File tree Expand file tree Collapse file tree 4 files changed +20
-1
lines changed Expand file tree Collapse file tree 4 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,12 @@ public actor DataFrame: Sendable {
6262 self . batches. append ( contentsOf: batches)
6363 }
6464
65+ /// Return the `SparkSession` of this `DataFrame`.
66+ /// - Returns: A `SparkSession`
67+ public func sparkSession( ) -> SparkSession {
68+ return self . spark
69+ }
70+
6571 /// A method to access the underlying Spark's `RDD`.
6672 /// In `Spark Connect`, this feature is not allowed by design.
6773 public func rdd( ) throws {
Original file line number Diff line number Diff line change @@ -77,3 +77,9 @@ extension Data {
7777 /// Get an `Int32` value from unsafe 4 bytes.
7878 var int32 : Int32 { withUnsafeBytes ( { $0. load ( as: Int32 . self) } ) }
7979}
80+
81+ extension SparkSession : Equatable {
82+ public static func == ( lhs: SparkSession , rhs: SparkSession ) -> Bool {
83+ return lhs. sessionID == rhs. sessionID
84+ }
85+ }
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ public actor SparkSession {
6262 }
6363
6464 /// A unique session ID for this session from client.
65- var sessionID : String = UUID ( ) . uuidString
65+ nonisolated let sessionID : String = UUID ( ) . uuidString
6666
6767 /// Get the current session ID
6868 /// - Returns: the current session ID
Original file line number Diff line number Diff line change @@ -23,6 +23,13 @@ import Testing
2323
2424/// A test suite for `DataFrame`
2525struct DataFrameTests {
26+ @Test
27+ func sparkSession( ) async throws {
28+ let spark = try await SparkSession . builder. getOrCreate ( )
29+ #expect( try await spark. range ( 1 ) . sparkSession ( ) == spark)
30+ await spark. stop ( )
31+ }
32+
2633 @Test
2734 func rdd( ) async throws {
2835 let spark = try await SparkSession . builder. getOrCreate ( )
You can’t perform that action at this time.
0 commit comments