Skip to content

[SPARK-51539] Refactor SparkConnectClient to use analyze helper function #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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
21 changes: 12 additions & 9 deletions Sources/SparkConnect/SparkConnectClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ public actor SparkConnectClient {

self.sessionID = sessionID
let service = SparkConnectService.Client(wrapping: client)
let version = AnalyzePlanRequest.SparkVersion()
var request = AnalyzePlanRequest()
request.clientType = clientType
request.userContext = userContext
request.sessionID = self.sessionID!
request.analyze = .sparkVersion(version)
let request = analyze(self.sessionID!, {
return OneOf_Analyze.sparkVersion(AnalyzePlanRequest.SparkVersion())
})
let response = try await service.analyzePlan(request)
return response
}
Expand Down Expand Up @@ -243,13 +240,19 @@ public actor SparkConnectClient {
func getAnalyzePlanRequest(_ sessionID: String, _ plan: Plan) async
-> AnalyzePlanRequest
{
return analyze(sessionID, {
var schema = AnalyzePlanRequest.Schema()
schema.plan = plan
return OneOf_Analyze.schema(schema)
})
}

private func analyze(_ sessionID: String, _ f: () -> OneOf_Analyze) -> AnalyzePlanRequest {
var request = AnalyzePlanRequest()
request.clientType = clientType
request.userContext = userContext
request.sessionID = self.sessionID!
var schema = AnalyzePlanRequest.Schema()
schema.plan = plan
request.analyze = .schema(schema)
request.analyze = f()
return request
}

Expand Down
1 change: 1 addition & 0 deletions Sources/SparkConnect/TypeAliases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typealias Plan = Spark_Connect_Plan
typealias Project = Spark_Connect_Project
typealias KeyValue = Spark_Connect_KeyValue
typealias Limit = Spark_Connect_Limit
typealias OneOf_Analyze = AnalyzePlanRequest.OneOf_Analyze
typealias Range = Spark_Connect_Range
typealias Relation = Spark_Connect_Relation
typealias SparkConnectService = Spark_Connect_SparkConnectService
Expand Down
Loading