Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Sources/SparkConnect/SparkConnectClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,37 @@ public actor SparkConnectClient {
}
}

@discardableResult
func defineFlow(
_ dataflowGraphID: String,
_ flowName: String,
_ targetDatasetName: String,
_ relation: Relation
) async throws -> Bool {
try await withGPRC { client in
if UUID(uuidString: dataflowGraphID) == nil {
throw SparkConnectError.InvalidArgument
}

var defineFlow = Spark_Connect_PipelineCommand.DefineFlow()
defineFlow.dataflowGraphID = dataflowGraphID
defineFlow.flowName = flowName
defineFlow.targetDatasetName = targetDatasetName
defineFlow.plan = relation

var pipelineCommand = Spark_Connect_PipelineCommand()
pipelineCommand.commandType = .defineFlow(defineFlow)

var command = Spark_Connect_Command()
command.commandType = .pipelineCommand(pipelineCommand)

let responses = try await execute(self.sessionID!, command)
return responses.contains {
$0.responseType == .pipelineCommandResult(Spark_Connect_PipelineCommandResult())
}
}
}

private enum URIParams {
static let PARAM_GRPC_MAX_MESSAGE_SIZE = "grpc_max_message_size"
static let PARAM_SESSION_ID = "session_id"
Expand Down
18 changes: 18 additions & 0 deletions Tests/SparkConnectTests/SparkConnectClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,22 @@ struct SparkConnectClientTests {
}
await client.stop()
}

@Test
func defineFlow() async throws {
let client = SparkConnectClient(remote: TEST_REMOTE)
let response = try await client.connect(UUID().uuidString)

try await #require(throws: SparkConnectError.InvalidArgument) {
try await client.defineFlow("not-a-uuid-format", "f1", "ds1", Relation())
}

if response.sparkVersion.version.starts(with: "4.1") {
let dataflowGraphID = try await client.createDataflowGraph()
#expect(UUID(uuidString: dataflowGraphID) != nil)
let relation = await client.getLocalRelation().root
#expect(try await client.defineFlow(dataflowGraphID, "f1", "ds1", relation))
}
await client.stop()
}
}
Loading