This is an automated email from the ASF dual-hosted git repository. dongjoon pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/spark-connect-swift.git
The following commit(s) were added to refs/heads/main by this push: new f6f4a2d [SPARK-52063] Support `newSession` in `SparkSession` f6f4a2d is described below commit f6f4a2dccd39112748b9b612efdd3fdc1e7aadd4 Author: Dongjoon Hyun <dongj...@apache.org> AuthorDate: Fri May 9 18:11:09 2025 -0700 [SPARK-52063] Support `newSession` in `SparkSession` ### What changes were proposed in this pull request? This PR aims to support `newSession` API in `SparkSession`. ### Why are the changes needed? For feature parity. ### Does this PR introduce _any_ user-facing change? No. This is an addition API. ### How was this patch tested? Pass the CIs with the newly added test case. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #121 from dongjoon-hyun/SPARK-52063. Authored-by: Dongjoon Hyun <dongj...@apache.org> Signed-off-by: Dongjoon Hyun <dongj...@apache.org> --- Sources/SparkConnect/SparkSession.swift | 7 +++++++ Tests/SparkConnectTests/SparkSessionTests.swift | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/Sources/SparkConnect/SparkSession.swift b/Sources/SparkConnect/SparkSession.swift index a3fcff9..e588ace 100644 --- a/Sources/SparkConnect/SparkSession.swift +++ b/Sources/SparkConnect/SparkSession.swift @@ -46,6 +46,13 @@ public actor SparkSession { /// The Spark version of Spark Connect Servier. This is supposed to be overwritten during establishing connections. public var version: String = "" + /// Start a new session with isolated SQL configurations, temporary tables, registered functions + /// are isolated, but sharing the underlying `SparkContext` and cached data. + /// - Returns: a new ``SparkSession`` instance. + public func newSession() async throws -> SparkSession { + return try await SparkSession.builder.create() + } + func setVersion(_ version: String) { self.version = version } diff --git a/Tests/SparkConnectTests/SparkSessionTests.swift b/Tests/SparkConnectTests/SparkSessionTests.swift index 9097e99..c2b5aa2 100644 --- a/Tests/SparkConnectTests/SparkSessionTests.swift +++ b/Tests/SparkConnectTests/SparkSessionTests.swift @@ -40,6 +40,16 @@ struct SparkSessionTests { await spark.stop() } + @Test + func newSession() async throws { + let spark = try await SparkSession.builder.getOrCreate() + await spark.stop() + let newSpark = try await spark.newSession() + #expect(newSpark != spark) + #expect(try await newSpark.range(1).count() == 1) + await newSpark.stop() + } + @Test func userContext() async throws { let spark = try await SparkSession.builder.getOrCreate() #if os(macOS) || os(Linux) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org