cloud-fan commented on code in PR #53158:
URL: https://github.com/apache/spark/pull/53158#discussion_r2609910517


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala:
##########
@@ -724,6 +724,65 @@ class SparkSqlAstBuilder extends AstBuilder {
     }
   }
 
+  override def visitCodeLiteral(ctx: CodeLiteralContext): String = {
+    assert(ctx != null)
+    dollarQuotedString(ctx.DOLLAR_QUOTED_STRING_BODY())
+  }
+
+  override def visitCreateMetricView(ctx: CreateMetricViewContext): 
LogicalPlan = withOrigin(ctx) {
+    checkDuplicateClauses(ctx.commentSpec(), "COMMENT", ctx)
+    checkDuplicateClauses(ctx.TBLPROPERTIES, "TBLPROPERTIES", ctx)
+    checkDuplicateClauses(ctx.routineLanguage(), "LANGUAGE", ctx)
+    checkDuplicateClauses(ctx.METRICS(), "WITH METRICS", ctx)
+    val userSpecifiedColumns = Option(ctx.identifierCommentList).toSeq.flatMap 
{ icl =>
+      icl.identifierComment.asScala.map { ic =>
+        ic.identifier.getText -> Option(ic.commentSpec()).map(visitCommentSpec)
+      }
+    }
+
+    if (ctx.EXISTS != null && ctx.REPLACE != null) {
+      throw 
QueryParsingErrors.createViewWithBothIfNotExistsAndReplaceError(ctx)
+    }
+
+    if (ctx.METRICS(0) == null) {
+      throw QueryParsingErrors.missingClausesForOperation(
+        ctx, "WITH METRICS", "CREATE METRIC VIEW")
+    }
+
+    if (ctx.routineLanguage(0) == null) {
+      throw QueryParsingErrors.missingClausesForOperation(
+        ctx, "LANGUAGE", "CREATE METRIC VIEW")
+    }
+
+    val languageCtx = ctx.routineLanguage(0)
+    withOrigin(languageCtx) {
+      if (languageCtx.SQL() != null) {
+        operationNotAllowed("Unsupported language for metric view: SQL", ctx)
+      }
+      val name: String = languageCtx.IDENTIFIER().getText
+      if (!name.equalsIgnoreCase("YAML")) {
+        operationNotAllowed(s"Unsupported language for metric view: $name", 
ctx)
+      }
+    }
+
+    val properties = ctx.propertyList.asScala.headOption
+      .map(visitPropertyKeyValues)
+      .getOrElse(Map.empty)
+    val codeLiteral = visitCodeLiteral(ctx.codeLiteral())
+
+    withIdentClause(ctx.identifierReference(), ident => {

Review Comment:
   I think it's simpler to do
   ```
         CreateMetricViewCommand(
           withIdentClause(...),
           userSpecifiedColumns,
           visitCommentSpecList(ctx.commentSpec()),
           properties,
           codeLiteral,
           allowExisting = ctx.EXISTS != null,
           replace = ctx.REPLACE != null
         )
   ```



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