melihsozdinler commented on code in PR #40474:
URL: https://github.com/apache/spark/pull/40474#discussion_r1285899298


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala:
##########
@@ -567,6 +568,135 @@ class SparkSqlAstBuilder extends AstBuilder {
     }
   }
 
+  /**
+   * Create a [[CreateVariableCommand]].
+   *
+   * For example:
+   * {{{
+   *   DECLARE [OR REPLACE] [VARIABLE] [db_name.]variable_name
+   *   [dataType] [defaultExpression];
+   * }}}
+   *
+   * We will ad CREATE VARIABLE for persisted variable definitions to this, 
hence the name...
+   */
+  override def visitCreateVariable(ctx: CreateVariableContext): LogicalPlan = 
withOrigin(ctx) {
+
+    def format(name: String): String = {
+      if (conf.caseSensitiveAnalysis) name else name.toLowerCase(Locale.ROOT)
+    }
+
+    val multipartIdentifier = visitMultipartIdentifier(ctx.multipartIdentifier)
+    val defaultExpression = if (ctx.variableDefaultExpression() == null) {
+      "null"
+    } else {
+      visitVariableDefaultExpression(ctx.variableDefaultExpression())
+    }
+    val dataTypeStr: Option[String] =
+      if (Option(ctx.dataType).nonEmpty) {
+        Option(source(Option(ctx.dataType).get))
+      } else {
+        Option(null)
+      }
+
+    if (multipartIdentifier.length > 3) {
+      throw QueryParsingErrors.unsupportedVariableNameError(
+        multipartIdentifier, ctx.multipartIdentifier)
+    }
+
+    val schemaQualifiedName = if (multipartIdentifier.length < 2) {
+      SESSION_DATABASE +: multipartIdentifier
+    } else {
+      multipartIdentifier
+    }
+
+    val catalogQualifiedName = if (schemaQualifiedName.length < 3) {

Review Comment:
   This "3" and VariableIdentifier apply method checks length 3 are connected? 
If connected there should be some comment to change also inside the apply 
function, or we can avoid such magic number issues by targetting named some 
meaningful variable with a value 



-- 
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]

Reply via email to