You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "melihsozdinler (via GitHub)" <gi...@apache.org> on 2023/08/07 13:53:10 UTC

[GitHub] [spark] melihsozdinler commented on a diff in pull request #40474: [SPARK-42849] [SQL] Session Variables

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

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


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