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
29 changes: 29 additions & 0 deletions Sources/SparkConnect/SparkConnectClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,35 @@ public actor SparkConnectClient {
}
}

@discardableResult
func defineSqlGraphElements(
_ dataflowGraphID: String,
_ sqlFilePath: String,
_ sqlText: String
) async throws -> Bool {
try await withGPRC { client in
if UUID(uuidString: dataflowGraphID) == nil {
throw SparkConnectError.InvalidArgument
}

var elements = Spark_Connect_PipelineCommand.DefineSqlGraphElements()
elements.dataflowGraphID = dataflowGraphID
elements.sqlFilePath = sqlFilePath
elements.sqlText = sqlText

var pipelineCommand = Spark_Connect_PipelineCommand()
pipelineCommand.commandType = .defineSqlGraphElements(elements)

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 @@ -164,4 +164,22 @@ struct SparkConnectClientTests {
}
await client.stop()
}

@Test
func defineSqlGraphElements() 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.defineSqlGraphElements("not-a-uuid-format", "path", "sql")
}

if response.sparkVersion.version.starts(with: "4.1") {
let dataflowGraphID = try await client.createDataflowGraph()
let sqlText = "CREATE MATERIALIZED VIEW mv1 AS SELECT 1"
#expect(UUID(uuidString: dataflowGraphID) != nil)
#expect(try await client.defineSqlGraphElements(dataflowGraphID, "path", sqlText))
}
await client.stop()
}
}
Loading