Skip to content

Commit caa986b

Browse files
committed
[SPARK-51481] Add RuntimeConf actor
1 parent c405943 commit caa986b

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
/// User-facing configuration API, accessible through `SparkSession.conf`.
21+
public actor RuntimeConf {
22+
private let client: SparkConnectClient
23+
24+
/// Create a `RuntimeConf` instance with the given client.
25+
/// - Parameter client: A client to talk to the Spark Connect server.
26+
init(_ client: SparkConnectClient) {
27+
self.client = client
28+
}
29+
30+
/// Set a new configuration.
31+
/// - Parameters:
32+
/// - key: A string for the configuration key.
33+
/// - value: A string for the configuration value.
34+
public func set(_ key: String, _ value: String) async throws {
35+
_ = try await client.setConf(map: [key: value])
36+
}
37+
38+
/// Get a configuration.
39+
/// - Parameter key: A string for the configuration look-up.
40+
/// - Returns: A string for the configuration.
41+
public func get(_ key: String) async throws -> String {
42+
return try await client.getConf(key)
43+
}
44+
45+
/// Get all configurations.
46+
/// - Returns: A map of configuration key-values.
47+
public func getAll() async throws -> [String: String] {
48+
return try await client.getConfAll()
49+
}
50+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
import Foundation
21+
import Testing
22+
23+
@testable import SparkConnect
24+
25+
/// A test suite for `RuntimeConf`
26+
@Suite(.serialized)
27+
struct RuntimeConfTests {
28+
@Test
29+
func get() async throws {
30+
let client = SparkConnectClient(remote: "sc://localhost", user: "test")
31+
_ = try await client.connect(UUID().uuidString)
32+
let conf = RuntimeConf(client)
33+
#expect(try await conf.get("spark.app.name") == "Spark Connect server")
34+
}
35+
36+
@Test
37+
func set() async throws {
38+
let client = SparkConnectClient(remote: "sc://localhost", user: "test")
39+
_ = try await client.connect(UUID().uuidString)
40+
let conf = RuntimeConf(client)
41+
try await conf.set("spark.test.key1", "value1")
42+
#expect(try await conf.get("spark.test.key1") == "value1")
43+
}
44+
45+
@Test
46+
func getAll() async throws {
47+
let client = SparkConnectClient(remote: "sc://localhost", user: "test")
48+
_ = try await client.connect(UUID().uuidString)
49+
let conf = RuntimeConf(client)
50+
let map = try await conf.getAll()
51+
print(map)
52+
#expect(map.count > 0)
53+
#expect(map["spark.app.id"] != nil)
54+
#expect(map["spark.app.startTime"] != nil)
55+
#expect(map["spark.executor.id"] == "driver")
56+
#expect(map["spark.master"] != nil)
57+
}
58+
}

0 commit comments

Comments
 (0)