dusantism-db commented on code in PR #49445:
URL: https://github.com/apache/spark/pull/49445#discussion_r1963389892


##########
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:
   @cloud-fan Addressed, refactored this part into a clearer match statement 
which throws errors on every unexpected case.



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to