-
Notifications
You must be signed in to change notification settings - Fork 29k
[WIP][CONNECT] Initial runtime SQL configuration implementation #39995
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,6 +183,85 @@ message ExecutePlanResponse { | |
| } | ||
| } | ||
|
|
||
| // Request to update or fetch the configurations. | ||
| message ConfigRequest { | ||
| // (Required) | ||
| // | ||
| // The client_id is set by the client to be able to collate streaming responses from | ||
| // different queries. | ||
| string client_id = 1; | ||
|
|
||
| // (Required) User context | ||
| UserContext user_context = 2; | ||
|
|
||
| Operation operation = 3; | ||
|
|
||
| // (Optional) | ||
| // | ||
| // Identify which keys will be updated or fetched. | ||
| // Required when the 'operation' is 'SET', 'GET', 'GET_OPTION', 'UNSET', | ||
| // 'CONTAINS', 'IS_MODIFIABLE'. | ||
| repeated string keys = 4; | ||
|
|
||
| // (Optional) | ||
| // | ||
| // Corresponding values to the keys. | ||
| // Required when the 'operation' is 'SET'. | ||
| // Optional when the 'operation' is 'GET', the values here will be used | ||
| // as the default values. | ||
| repeated string values = 5; | ||
|
Comment on lines
+199
to
+212
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not make this something like this
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find the reuse in case of GET/SET hard to reason about |
||
|
|
||
| // (Optional) | ||
| // | ||
| // Only used when the 'operation' is 'GET_ALL'. | ||
| // If prefix is given, only parameters that start with the prefix will be returned. | ||
| optional string prefix = 6; | ||
|
|
||
| enum Operation { | ||
| OPERATION_UNSPECIFIED = 0; | ||
| OPERATION_SET = 1; | ||
| OPERATION_GET = 2; | ||
| OPERATION_GET_OPTION = 3; | ||
| OPERATION_GET_ALL = 4; | ||
| OPERATION_UNSET = 5; | ||
| OPERATION_CONTAINS = 6; | ||
| OPERATION_IS_MODIFIABLE = 7; | ||
| } | ||
| } | ||
|
|
||
| message ConfigResponse { | ||
| string client_id = 1; | ||
|
|
||
| // (Optional) | ||
| // | ||
| // Available when the operation is 'GET_ALL'. | ||
| repeated string keys = 2; | ||
|
|
||
| // (Optional) | ||
| // | ||
| // Available when the operation is 'GET', 'GET_ALL'. | ||
| repeated string values = 3; | ||
|
|
||
| // (Optional) | ||
| // | ||
| // Available when the operation is 'GET_OPTION'. | ||
| repeated OptionalValue optional_values = 4; | ||
|
|
||
| // (Optional) | ||
| // | ||
| // Available when the operation is 'CONTAINS', 'IS_MODIFIABLE'. | ||
| repeated bool bools = 5; | ||
|
|
||
| // (Optional) | ||
| // | ||
| // Warning messages for deprecated or unsupported configurations. | ||
| repeated string warnings = 6; | ||
|
|
||
| message OptionalValue { | ||
| optional string value = 1; | ||
| } | ||
| } | ||
|
|
||
| // Main interface for the SparkConnect service. | ||
| service SparkConnectService { | ||
|
|
||
|
|
@@ -193,5 +272,8 @@ service SparkConnectService { | |
|
|
||
| // Analyzes a query and returns a [[AnalyzeResponse]] containing metadata about the query. | ||
| rpc AnalyzePlan(AnalyzePlanRequest) returns (AnalyzePlanResponse) {} | ||
|
|
||
| // Update or fetch the configurations and returns a [[ConfigResponse]] containing the result. | ||
| rpc Config(ConfigRequest) returns (ConfigResponse) {} | ||
| } | ||
|
|
||
142 changes: 142 additions & 0 deletions
142
...erver/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectConfigHandler.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connect.service | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
||
| import io.grpc.stub.StreamObserver | ||
|
|
||
| import org.apache.spark.connect.proto | ||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.sql.SparkSession | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
||
| class SparkConnectConfigHandler(responseObserver: StreamObserver[proto.ConfigResponse]) | ||
| extends Logging { | ||
|
|
||
| def handle(request: proto.ConfigRequest): Unit = { | ||
| val session = | ||
| SparkConnectService | ||
| .getOrCreateIsolatedSession(request.getUserContext.getUserId, request.getClientId) | ||
| .session | ||
|
|
||
| val builder = handleSQLConf(request, session) | ||
| builder.setClientId(request.getClientId) | ||
| responseObserver.onNext(builder.build()) | ||
| responseObserver.onCompleted() | ||
| } | ||
|
|
||
| private def handleSQLConf(request: proto.ConfigRequest, session: SparkSession) = { | ||
| val conf = session.conf | ||
| val builder = proto.ConfigResponse.newBuilder() | ||
|
|
||
| request.getOperation match { | ||
| case proto.ConfigRequest.Operation.OPERATION_SET => | ||
| if (request.getKeysCount != request.getValuesCount) { | ||
| throw new UnsupportedOperationException("Keys and values should have the same length!") | ||
| } | ||
| request.getKeysList.asScala.iterator | ||
| .zip(request.getValuesList.asScala.iterator) | ||
| .foreach { case (key, value) => | ||
| conf.set(key, value) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
|
|
||
| case proto.ConfigRequest.Operation.OPERATION_GET => | ||
| if (request.getValuesCount == 0) { | ||
| request.getKeysList.asScala.iterator.foreach { key => | ||
| builder.addValues(conf.get(key)) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
| } else { | ||
| if (request.getKeysCount != request.getValuesCount) { | ||
| throw new UnsupportedOperationException( | ||
| "Keys and values should have the same length!") | ||
| } | ||
| request.getKeysList.asScala.iterator | ||
| .zip(request.getValuesList.asScala.iterator) | ||
| .foreach { case (key, value) => | ||
| builder.addValues(conf.get(key, value)) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
| } | ||
|
|
||
| case proto.ConfigRequest.Operation.OPERATION_GET_OPTION => | ||
| request.getKeysList.asScala.iterator.foreach { key => | ||
| conf.getOption(key) match { | ||
| case Some(value) => | ||
| builder.addOptionalValues( | ||
| proto.ConfigResponse.OptionalValue.newBuilder().setValue(value).build()) | ||
| case _ => | ||
| builder.addOptionalValues(proto.ConfigResponse.OptionalValue.newBuilder().build()) | ||
| } | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
|
|
||
| case proto.ConfigRequest.Operation.OPERATION_GET_ALL => | ||
| val results = if (request.hasPrefix) { | ||
| val prefix = request.getPrefix | ||
| conf.getAll.iterator | ||
| .filter { case (key, value) => key.startsWith(prefix) } | ||
| .map { case (key, value) => (key.substring(prefix.length), value) } | ||
| } else { | ||
| conf.getAll.iterator | ||
| } | ||
| results.foreach { case (key, value) => | ||
| builder.addKeys(key).addValues(value) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
|
|
||
| case proto.ConfigRequest.Operation.OPERATION_UNSET => | ||
| request.getKeysList.asScala.iterator.foreach { key => | ||
| conf.unset(key) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
|
|
||
| case proto.ConfigRequest.Operation.OPERATION_CONTAINS => | ||
| request.getKeysList.asScala.iterator.foreach { key => | ||
| builder.addBools(conf.contains(key)) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
|
|
||
| case proto.ConfigRequest.Operation.OPERATION_IS_MODIFIABLE => | ||
| request.getKeysList.asScala.iterator.foreach { key => | ||
| builder.addBools(conf.isModifiable(key)) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
|
|
||
| case other => | ||
| throw new UnsupportedOperationException(s"Unsupported operation $other in SQLConf.") | ||
| } | ||
|
|
||
| builder | ||
| } | ||
|
|
||
| private def getWarning(key: String): Option[String] = { | ||
| if (SparkConnectConfigHandler.unsupportedConfigurations.contains(key)) { | ||
| Some(s"The SQL config '$key' is NOT supported in Spark Connect") | ||
| } else { | ||
| SQLConf.deprecatedSQLConfigs.get(key).map(_.toDeprecationString) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| object SparkConnectConfigHandler { | ||
|
|
||
| private[connect] val unsupportedConfigurations = Set("spark.sql.execution.arrow.enabled") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe more like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be good to have explicit messages rather than the combination of the enum plus the message attributes.