cloud-fan commented on code in PR #49445:
URL: https://github.com/apache/spark/pull/49445#discussion_r1946863023
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/command/v2/CreateVariableExec.scala:
##########
@@ -19,29 +19,47 @@ package org.apache.spark.sql.execution.command.v2
import java.util.Locale
-import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.{InternalRow,
SqlScriptingLocalVariableManager}
+import org.apache.spark.sql.catalyst.analysis.{FakeLocalCatalog,
ResolvedIdentifier}
import org.apache.spark.sql.catalyst.expressions.{Attribute,
ExpressionsEvaluator, Literal}
import org.apache.spark.sql.catalyst.plans.logical.DefaultValueExpression
+import org.apache.spark.sql.connector.catalog.Identifier
import org.apache.spark.sql.execution.datasources.v2.LeafV2CommandExec
/**
* Physical plan node for creating a variable.
*/
-case class CreateVariableExec(name: String, defaultExpr:
DefaultValueExpression, replace: Boolean)
- extends LeafV2CommandExec with ExpressionsEvaluator {
+case class CreateVariableExec(
+ resolvedIdentifier: ResolvedIdentifier,
+ defaultExpr: DefaultValueExpression,
+ replace: Boolean) extends LeafV2CommandExec with ExpressionsEvaluator {
override protected def run(): Seq[InternalRow] = {
- val variableManager =
session.sessionState.catalogManager.tempVariableManager
+ val scriptingVariableManager = SqlScriptingLocalVariableManager.get()
+ val tempVariableManager =
session.sessionState.catalogManager.tempVariableManager
+
val exprs = prepareExpressions(Seq(defaultExpr.child),
subExprEliminationEnabled = false)
initializeExprs(exprs, 0)
val initValue = Literal(exprs.head.eval(), defaultExpr.dataType)
- val normalizedName = if (session.sessionState.conf.caseSensitiveAnalysis) {
- name
+
+ val normalizedIdentifier = if
(session.sessionState.conf.caseSensitiveAnalysis) {
+ resolvedIdentifier.identifier
} else {
- name.toLowerCase(Locale.ROOT)
+ Identifier.of(
+
resolvedIdentifier.identifier.namespace().map(_.toLowerCase(Locale.ROOT)),
+ resolvedIdentifier.identifier.name().toLowerCase(Locale.ROOT))
}
- variableManager.create(
- normalizedName, defaultExpr.originalSQL, initValue, replace)
+
+ // create local variable if we are in a script, otherwise create session
variable
+ scriptingVariableManager
+ .filter(_ => resolvedIdentifier.catalog == FakeLocalCatalog)
Review Comment:
let's add a comment to say that it's a safeguard and should never happen. If
the resolved identifier uses `FakeLocalCatalog` it must mean that we are in the
scripting environment and `scriptingVariableManager` must be present.
--
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]