Skip to content

Commit 7fe4882

Browse files
committed
[SPARK-51858] Support SPARK_REMOTE
### What changes were proposed in this pull request? This PR aims to support `SPARK_REMOTE` environment variable. ### Why are the changes needed? For feature parity. ### Does this PR introduce _any_ user-facing change? No behavior change. This is an additional way to set Spark connect remote string. ### How was this patch tested? Pass the CIs with the revised test pipeline. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #79 from dongjoon-hyun/SPARK-51858. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 023f450 commit 7fe4882

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

.github/workflows/build_and_test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ jobs:
6767
6868
integration-test-linux:
6969
runs-on: ubuntu-latest
70+
env:
71+
SPARK_REMOTE: "sc://localhost:15003"
7072
services:
7173
spark:
7274
image: apache/spark:4.0.0-preview2
7375
env:
7476
SPARK_NO_DAEMONIZE: 1
7577
ports:
76-
- 15002:15002
78+
- 15003:15002
7779
options: --entrypoint /opt/spark/sbin/start-connect-server.sh
7880
steps:
7981
- uses: actions/checkout@v4

Sources/SparkConnect/SparkSession.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ public actor SparkSession {
221221
/// Create a new ``SparkSession``. If `spark.remote` is not given, `sc://localhost:15002` is used.
222222
/// - Returns: A newly created `SparkSession`.
223223
func create() async throws -> SparkSession {
224-
let session = SparkSession(sparkConf["spark.remote"] ?? "sc://localhost:15002")
224+
let remote = ProcessInfo.processInfo.environment["SPARK_REMOTE"] ?? "sc://localhost:15002"
225+
let session = SparkSession(sparkConf["spark.remote"] ?? remote)
225226
let response = try await session.client.connect(session.sessionID)
226227
await session.setVersion(response.sparkVersion.version)
227228
let isSuccess = try await session.client.setConf(map: sparkConf)

Tests/SparkConnectTests/BuilderTests.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@
1717
// under the License.
1818
//
1919

20+
import Foundation
2021
import Testing
2122

2223
@testable import SparkConnect
2324

2425
/// A test suite for `SparkSession.Builder`
2526
@Suite(.serialized)
2627
struct BuilderTests {
28+
let TEST_REMOTE = ProcessInfo.processInfo.environment["SPARK_REMOTE"] ?? "sc://localhost:15002"
29+
2730
@Test
2831
func builderDefault() async throws {
32+
let url = URL(string: self.TEST_REMOTE)!
2933
let spark = try await SparkSession.builder.getOrCreate()
3034
#expect(await spark.client.clientType == "swift")
31-
#expect(await spark.client.url.host() == "localhost")
32-
#expect(await spark.client.url.port == 15002)
35+
#expect(await spark.client.url.host() == url.host())
36+
#expect(await spark.client.url.port == url.port)
3337
await spark.stop()
3438
}
3539

Tests/SparkConnectTests/RuntimeConfTests.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ import Testing
2525
/// A test suite for `RuntimeConf`
2626
@Suite(.serialized)
2727
struct RuntimeConfTests {
28+
let TEST_REMOTE = ProcessInfo.processInfo.environment["SPARK_REMOTE"] ?? "sc://localhost"
29+
2830
@Test
2931
func get() async throws {
30-
let client = SparkConnectClient(remote: "sc://localhost")
32+
let client = SparkConnectClient(remote: TEST_REMOTE)
3133
_ = try await client.connect(UUID().uuidString)
3234
let conf = RuntimeConf(client)
3335

@@ -42,7 +44,7 @@ struct RuntimeConfTests {
4244

4345
@Test
4446
func set() async throws {
45-
let client = SparkConnectClient(remote: "sc://localhost")
47+
let client = SparkConnectClient(remote: TEST_REMOTE)
4648
_ = try await client.connect(UUID().uuidString)
4749
let conf = RuntimeConf(client)
4850
try await conf.set("spark.test.key1", "value1")
@@ -52,7 +54,7 @@ struct RuntimeConfTests {
5254

5355
@Test
5456
func reset() async throws {
55-
let client = SparkConnectClient(remote: "sc://localhost")
57+
let client = SparkConnectClient(remote: TEST_REMOTE)
5658
_ = try await client.connect(UUID().uuidString)
5759
let conf = RuntimeConf(client)
5860

@@ -73,7 +75,7 @@ struct RuntimeConfTests {
7375

7476
@Test
7577
func getAll() async throws {
76-
let client = SparkConnectClient(remote: "sc://localhost")
78+
let client = SparkConnectClient(remote: TEST_REMOTE)
7779
_ = try await client.connect(UUID().uuidString)
7880
let conf = RuntimeConf(client)
7981
let map = try await conf.getAll()

Tests/SparkConnectTests/SparkConnectClientTests.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ import Testing
2525
/// A test suite for `SparkConnectClient`
2626
@Suite(.serialized)
2727
struct SparkConnectClientTests {
28+
let TEST_REMOTE = ProcessInfo.processInfo.environment["SPARK_REMOTE"] ?? "sc://localhost"
29+
2830
@Test
2931
func createAndStop() async throws {
30-
let client = SparkConnectClient(remote: "sc://localhost")
32+
let client = SparkConnectClient(remote: TEST_REMOTE)
3133
await client.stop()
3234
}
3335

@@ -44,7 +46,7 @@ struct SparkConnectClientTests {
4446

4547
@Test
4648
func connectWithInvalidUUID() async throws {
47-
let client = SparkConnectClient(remote: "sc://localhost")
49+
let client = SparkConnectClient(remote: TEST_REMOTE)
4850
try await #require(throws: SparkConnectError.InvalidSessionIDException) {
4951
let _ = try await client.connect("not-a-uuid-format")
5052
}
@@ -53,14 +55,14 @@ struct SparkConnectClientTests {
5355

5456
@Test
5557
func connect() async throws {
56-
let client = SparkConnectClient(remote: "sc://localhost")
58+
let client = SparkConnectClient(remote: TEST_REMOTE)
5759
let _ = try await client.connect(UUID().uuidString)
5860
await client.stop()
5961
}
6062

6163
@Test
6264
func tags() async throws {
63-
let client = SparkConnectClient(remote: "sc://localhost")
65+
let client = SparkConnectClient(remote: TEST_REMOTE)
6466
let _ = try await client.connect(UUID().uuidString)
6567
let plan = await client.getPlanRange(0, 1, 1)
6668

@@ -76,7 +78,7 @@ struct SparkConnectClientTests {
7678

7779
@Test
7880
func ddlParse() async throws {
79-
let client = SparkConnectClient(remote: "sc://localhost")
81+
let client = SparkConnectClient(remote: TEST_REMOTE)
8082
let _ = try await client.connect(UUID().uuidString)
8183
#expect(try await client.ddlParse("a int").simpleString == "struct<a:int>")
8284
await client.stop()
@@ -85,7 +87,7 @@ struct SparkConnectClientTests {
8587
#if !os(Linux) // TODO: Enable this with the offical Spark 4 docker image
8688
@Test
8789
func jsonToDdl() async throws {
88-
let client = SparkConnectClient(remote: "sc://localhost")
90+
let client = SparkConnectClient(remote: TEST_REMOTE)
8991
let _ = try await client.connect(UUID().uuidString)
9092
let json =
9193
#"{"type":"struct","fields":[{"name":"id","type":"long","nullable":false,"metadata":{}}]}"#

0 commit comments

Comments
 (0)