flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [flink] danny0405 commented on a change in pull request #8548: [FLINK-6962] [table] Add a create table SQL DDL
Date Wed, 29 May 2019 09:18:19 GMT
danny0405 commented on a change in pull request #8548: [FLINK-6962] [table] Add a create table
SQL DDL
URL: https://github.com/apache/flink/pull/8548#discussion_r288470641
 
 

 ##########
 File path: flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl
 ##########
 @@ -0,0 +1,347 @@
+<#--
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to you under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+-->
+
+void TableColumn(TableCreationContext context) :
+{
+}
+{
+    (
+        TableColumn2(context.columnList)
+    |
+        context.watermark = Watermark()
+    |
+        context.primaryKeyList = PrimaryKey()
+    |
+        UniqueKey(context.uniqueKeysList)
+    |
+        ComputedColumn(context)
+    )
+}
+
+void ComputedColumn(TableCreationContext context) :
+{
+    SqlNode identifier;
+    SqlNode expr;
+    boolean hidden = false;
+    SqlParserPos pos;
+}
+{
+    identifier = SimpleIdentifier() {pos = getPos();}
+    <AS>
+    expr = Expression(ExprContext.ACCEPT_SUB_QUERY) {
+        expr = SqlStdOperatorTable.AS.createCall(Span.of(identifier, expr).pos(), expr, identifier);
+        context.columnList.add(expr);
+    }
+}
+
+void TableColumn2(List<SqlNode> list) :
+{
+    SqlParserPos pos;
+    SqlIdentifier name;
+    SqlDataTypeSpec type;
+    SqlCharStringLiteral comment = null;
+    boolean isHeader = false;
+}
+{
+    name = SimpleIdentifier()
+    type = DataType()
+    (
+        <NULL> { type = type.withNullable(true); }
+    |
+        <NOT> <NULL> { type = type.withNullable(false); }
+    |
+        { type = type.withNullable(true); }
+    )
+    [ <HEADER> { isHeader = true; } ]
+    [ <COMMENT> <QUOTED_STRING> {
+        String p = SqlParserUtil.parseString(token.image);
+        comment = SqlLiteral.createCharString(p, getPos());
+    }]
+    {
+        SqlTableColumn tableColumn = new SqlTableColumn(name, type, comment, getPos());
+        tableColumn.setHeader(isHeader);
+        list.add(tableColumn);
+    }
+}
+
+SqlNodeList PrimaryKey() :
+{
+    List<SqlNode> pkList = new ArrayList<SqlNode>();
+
+    SqlParserPos pos;
+    SqlIdentifier columnName;
+}
+{
+    <PRIMARY> { pos = getPos(); } <KEY> <LPAREN>
+        columnName = SimpleIdentifier() { pkList.add(columnName); }
+        (<COMMA> columnName = SimpleIdentifier() { pkList.add(columnName); })*
+    <RPAREN>
+    {
+        return new SqlNodeList(pkList, pos.plus(getPos()));
+    }
+}
+
+void UniqueKey(List<SqlNodeList> list) :
+{
+    List<SqlNode> ukList = new ArrayList<SqlNode>();
+    SqlParserPos pos;
+    SqlIdentifier columnName;
+}
+{
+    <UNIQUE> { pos = getPos(); } <LPAREN>
+        columnName = SimpleIdentifier() { ukList.add(columnName); }
+        (<COMMA> columnName = SimpleIdentifier() { ukList.add(columnName); })*
+    <RPAREN>
+    {
+        SqlNodeList uk = new SqlNodeList(ukList, pos.plus(getPos()));
+        list.add(uk);
+    }
+}
+
+SqlWatermark Watermark() :
+{
+    SqlIdentifier watermarkName = null;
+    SqlIdentifier columnName;
+    SqlWatermarkStrategy strategy;
+    int delayDef = -1;
+    SqlTimeUnit timeUnit = null;
+}
+{
+    <WATERMARK>
+    [watermarkName = SimpleIdentifier()]
+    <FOR>
+    columnName = SimpleIdentifier()
+    <AS>
+    (
+        <BOUNDED> <WITH> <DELAY>
+            {
+                strategy = SqlWatermarkStrategy.BOUNDED_WITH_DELAY;
+                delayDef = UnsignedIntLiteral();
 
 Review comment:
   There is no necessity to quoting the literal.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message