Skip to content

Commit f6f4a2d

Browse files
committed
[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 <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent c533d4c commit f6f4a2d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Sources/SparkConnect/SparkSession.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public actor SparkSession {
4646
/// The Spark version of Spark Connect Servier. This is supposed to be overwritten during establishing connections.
4747
public var version: String = ""
4848

49+
/// Start a new session with isolated SQL configurations, temporary tables, registered functions
50+
/// are isolated, but sharing the underlying `SparkContext` and cached data.
51+
/// - Returns: a new ``SparkSession`` instance.
52+
public func newSession() async throws -> SparkSession {
53+
return try await SparkSession.builder.create()
54+
}
55+
4956
func setVersion(_ version: String) {
5057
self.version = version
5158
}

Tests/SparkConnectTests/SparkSessionTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ struct SparkSessionTests {
4040
await spark.stop()
4141
}
4242

43+
@Test
44+
func newSession() async throws {
45+
let spark = try await SparkSession.builder.getOrCreate()
46+
await spark.stop()
47+
let newSpark = try await spark.newSession()
48+
#expect(newSpark != spark)
49+
#expect(try await newSpark.range(1).count() == 1)
50+
await newSpark.stop()
51+
}
52+
4353
@Test func userContext() async throws {
4454
let spark = try await SparkSession.builder.getOrCreate()
4555
#if os(macOS) || os(Linux)

0 commit comments

Comments
 (0)