cloud-fan commented on code in PR #49445:
URL: https://github.com/apache/spark/pull/49445#discussion_r1931446944
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/command/v2/SetVariableExec.scala:
##########
@@ -47,21 +50,46 @@ case class SetVariableExec(variables:
Seq[VariableReference], query: SparkPlan)
val row = values(0)
variables.zipWithIndex.foreach { case (v, index) =>
val value = row.get(index, v.dataType)
- createVariable(variableManager, v, value)
+ setVariable(v, value, sessionVariablesOnly)
}
}
Seq.empty
}
- private def createVariable(
- variableManager: TempVariableManager,
+ private def setVariable(
variable: VariableReference,
- value: Any): Unit = {
- variableManager.create(
- variable.identifier.name,
+ value: Any,
+ sessionVariablesOnly: Boolean): Unit = {
+ val namePartsCaseAdjusted = if
(session.sessionState.conf.caseSensitiveAnalysis) {
+ variable.originalNameParts
+ } else {
+ variable.originalNameParts.map(_.toLowerCase(Locale.ROOT))
+ }
+
+ val tempVariableManager =
session.sessionState.catalogManager.tempVariableManager
+ val scriptingVariableManager = SqlScriptingLocalVariableManager.get()
+
+ val variableManager = scriptingVariableManager
+ .filterNot(_ => sessionVariablesOnly)
+ // If a local variable with nameParts exists, set it using
scriptingVariableManager.
+ .filter(_.get(namePartsCaseAdjusted).isDefined)
+ // If a local variable with nameParts doesn't exist, check if a session
variable exists
+ // with those nameParts and set it using tempVariableManager.
+ .orElse(
+ Option.when(tempVariableManager.get(namePartsCaseAdjusted).isDefined) {
+ tempVariableManager
+ }
+ // If neither local or session variable exists, throw error. This
shouldn't happen as
+ // existence of this variable is already checked in ResolveSetVariable.
+ ).getOrElse(
+ throw unresolvedVariableError(namePartsCaseAdjusted, Seq("SYSTEM",
"SESSION"))
+ )
+
+ variableManager.set(
Review Comment:
This is different from `create` with `overrideIfExists = true`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]