cloud-fan commented on code in PR #49445:
URL: https://github.com/apache/spark/pull/49445#discussion_r1946878523
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/command/v2/SetVariableExec.scala:
##########
@@ -47,21 +50,45 @@ 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)
}
}
Seq.empty
}
- private def createVariable(
- variableManager: TempVariableManager,
+ private def setVariable(
variable: VariableReference,
value: Any): Unit = {
- variableManager.create(
- variable.identifier.name,
+ 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
+ .filter(_ => variable.catalog == FakeLocalCatalog)
+ // 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
Review Comment:
shall we fail if this happens? The `ResolveSetVariable` rule has already
determined it's local variable and it's a bug if it disappears.
--
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]