You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/07/15 09:20:59 UTC

[GitHub] [flink] godfreyhe commented on a diff in pull request #20242: [FLINK-28489][sql-parser] Introduce `ANALYZE TABLE` syntax in sql parser

godfreyhe commented on code in PR #20242:
URL: https://github.com/apache/flink/pull/20242#discussion_r921982228


##########
flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl:
##########
@@ -2203,3 +2203,81 @@ SqlNode TryCastFunctionCall() :
         return operator.createCall(s.end(this), args);
     }
 }
+
+/**
+* Parses a partition key/value,
+* e.g. p or p = '10'.
+*/
+SqlPair PartitionKeyValuePair():
+{
+    SqlIdentifier key;
+    SqlNode value = null;
+    SqlParserPos pos;
+}
+{
+    key = SimpleIdentifier() { pos = getPos(); }
+    [
+        LOOKAHEAD(1)
+        <EQ> value = Literal()
+    ]
+    {
+           return new SqlPair(key, value, pos);
+    }
+}
+
+/**
+* Parses a partition specifications statement,
+* e.g. ANALYZE TABLE tbl1 partition(col1='val1', col2='val2') xxx
+* or
+* ANALYZE TABLE tbl1 partition(col1, col2) xxx.
+*/
+void ExtendedPartitionSpecCommaList(SqlNodeList list) :
+{
+    SqlPair keyValuePair;
+}
+{
+    <LPAREN>
+    keyValuePair = PartitionKeyValuePair()
+    {
+       list.add(keyValuePair);
+    }
+    (
+        <COMMA> keyValuePair = PartitionKeyValuePair()
+        {
+            list.add(keyValuePair);
+        }
+    )*
+    <RPAREN>
+}
+
+/** Parses an ANALYZE TABLE statement. */
+SqlNode SqlAnalyzeTable():
+{
+       Span s;
+       SqlIdentifier tableName;
+       SqlNodeList partitionSpec = null;
+       SqlNodeList columns = null;
+       boolean allColumns = false;
+}
+{
+    <ANALYZE> <TABLE> { s = span(); }
+    tableName = CompoundIdentifier()
+    [
+        <PARTITION> {
+            partitionSpec = new SqlNodeList(getPos());
+            ExtendedPartitionSpecCommaList(partitionSpec);
+        }
+    ]
+
+    <COMPUTE> <STATISTICS> [
+        (

Review Comment:
   The parser can't chose the correct branch if `LOOKAHEAD` is missing



-- 
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: issues-unsubscribe@flink.apache.org

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