-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-41834][CONNECT] Implement SparkSession.conf #40150
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
Show all changes
14 commits
Select commit
Hold shift + click to select a range
eec67b2
init
zhengruifeng 70b54df
Implement SparkSession.conf.
ueshin 9d19983
Fix.
ueshin adbcc57
warnings
ueshin 33b61e0
Fix.
ueshin f7b6ac0
Fix.
ueshin 4d8ff36
Fix.
ueshin d832e2b
Fix.
ueshin 1b80142
Fix.
ueshin 88fb676
Fix.
ueshin 34b18b2
Fix.
ueshin d7dff30
Fix.
ueshin 6f4743a
Fix.
ueshin 61034d2
Fix.
ueshin 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
181 changes: 181 additions & 0 deletions
181
...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,181 @@ | ||
| /* | ||
| * 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.RuntimeConfig | ||
| 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 = request.getOperation.getOpTypeCase match { | ||
| case proto.ConfigRequest.Operation.OpTypeCase.SET => | ||
| handleSet(request.getOperation.getSet, session.conf) | ||
| case proto.ConfigRequest.Operation.OpTypeCase.GET => | ||
| handleGet(request.getOperation.getGet, session.conf) | ||
| case proto.ConfigRequest.Operation.OpTypeCase.GET_WITH_DEFAULT => | ||
| handleGetWithDefault(request.getOperation.getGetWithDefault, session.conf) | ||
| case proto.ConfigRequest.Operation.OpTypeCase.GET_OPTION => | ||
| handleGetOption(request.getOperation.getGetOption, session.conf) | ||
| case proto.ConfigRequest.Operation.OpTypeCase.GET_ALL => | ||
| handleGetAll(request.getOperation.getGetAll, session.conf) | ||
| case proto.ConfigRequest.Operation.OpTypeCase.UNSET => | ||
| handleUnset(request.getOperation.getUnset, session.conf) | ||
| case proto.ConfigRequest.Operation.OpTypeCase.IS_MODIFIABLE => | ||
| handleIsModifiable(request.getOperation.getIsModifiable, session.conf) | ||
| case _ => throw new UnsupportedOperationException(s"${request.getOperation} not supported.") | ||
| } | ||
|
|
||
| builder.setClientId(request.getClientId) | ||
| responseObserver.onNext(builder.build()) | ||
| responseObserver.onCompleted() | ||
| } | ||
|
|
||
| private def handleSet( | ||
| operation: proto.ConfigRequest.Set, | ||
| conf: RuntimeConfig): proto.ConfigResponse.Builder = { | ||
| val builder = proto.ConfigResponse.newBuilder() | ||
| operation.getPairsList.asScala.iterator.foreach { pair => | ||
| val (key, value) = SparkConnectConfigHandler.toKeyValue(pair) | ||
| conf.set(key, value.orNull) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
| builder | ||
| } | ||
|
|
||
| private def handleGet( | ||
| operation: proto.ConfigRequest.Get, | ||
| conf: RuntimeConfig): proto.ConfigResponse.Builder = { | ||
| val builder = proto.ConfigResponse.newBuilder() | ||
| operation.getKeysList.asScala.iterator.foreach { key => | ||
| val value = conf.get(key) | ||
| builder.addPairs(SparkConnectConfigHandler.toProtoKeyValue(key, Option(value))) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
| builder | ||
| } | ||
|
|
||
| private def handleGetWithDefault( | ||
| operation: proto.ConfigRequest.GetWithDefault, | ||
| conf: RuntimeConfig): proto.ConfigResponse.Builder = { | ||
| val builder = proto.ConfigResponse.newBuilder() | ||
| operation.getPairsList.asScala.iterator.foreach { pair => | ||
| val (key, default) = SparkConnectConfigHandler.toKeyValue(pair) | ||
| val value = conf.get(key, default.orNull) | ||
| builder.addPairs(SparkConnectConfigHandler.toProtoKeyValue(key, Option(value))) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
| builder | ||
| } | ||
|
|
||
| private def handleGetOption( | ||
| operation: proto.ConfigRequest.GetOption, | ||
| conf: RuntimeConfig): proto.ConfigResponse.Builder = { | ||
| val builder = proto.ConfigResponse.newBuilder() | ||
| operation.getKeysList.asScala.iterator.foreach { key => | ||
| val value = conf.getOption(key) | ||
| builder.addPairs(SparkConnectConfigHandler.toProtoKeyValue(key, value)) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
| builder | ||
| } | ||
|
|
||
| private def handleGetAll( | ||
| operation: proto.ConfigRequest.GetAll, | ||
| conf: RuntimeConfig): proto.ConfigResponse.Builder = { | ||
| val builder = proto.ConfigResponse.newBuilder() | ||
| val results = if (operation.hasPrefix) { | ||
| val prefix = operation.getPrefix | ||
| conf.getAll.iterator | ||
| .filter { case (key, _) => key.startsWith(prefix) } | ||
| .map { case (key, value) => (key.substring(prefix.length), value) } | ||
| } else { | ||
| conf.getAll.iterator | ||
| } | ||
| results.foreach { case (key, value) => | ||
| builder.addPairs(SparkConnectConfigHandler.toProtoKeyValue(key, Option(value))) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
| builder | ||
| } | ||
|
|
||
| private def handleUnset( | ||
| operation: proto.ConfigRequest.Unset, | ||
| conf: RuntimeConfig): proto.ConfigResponse.Builder = { | ||
| val builder = proto.ConfigResponse.newBuilder() | ||
| operation.getKeysList.asScala.iterator.foreach { key => | ||
| conf.unset(key) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
| builder | ||
| } | ||
|
|
||
| private def handleIsModifiable( | ||
| operation: proto.ConfigRequest.IsModifiable, | ||
| conf: RuntimeConfig): proto.ConfigResponse.Builder = { | ||
| val builder = proto.ConfigResponse.newBuilder() | ||
| operation.getKeysList.asScala.iterator.foreach { key => | ||
| val value = conf.isModifiable(key) | ||
| builder.addPairs(SparkConnectConfigHandler.toProtoKeyValue(key, Option(value.toString))) | ||
| getWarning(key).foreach(builder.addWarnings) | ||
| } | ||
| 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") | ||
|
|
||
| def toKeyValue(pair: proto.KeyValue): (String, Option[String]) = { | ||
| val key = pair.getKey | ||
| val value = if (pair.hasValue) { | ||
| Some(pair.getValue) | ||
| } else { | ||
| None | ||
| } | ||
| (key, value) | ||
| } | ||
|
|
||
| def toProtoKeyValue(key: String, value: Option[String]): proto.KeyValue = { | ||
| val builder = proto.KeyValue.newBuilder() | ||
| builder.setKey(key) | ||
| value.foreach(builder.setValue) | ||
| builder.build() | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.