KurtYoung commented on a change in pull request #8548: [FLINK-6962] [table] Add create(drop) table SQL DDL URL: https://github.com/apache/flink/pull/8548#discussion_r289265024
########## File path: flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl ########## @@ -0,0 +1,295 @@ +<#-- +// 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.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; +} +{ + name = SimpleIdentifier() + type = DataType() + ( + <NULL> { type = type.withNullable(true); } + | + <NOT> <NULL> { type = type.withNullable(false); } + | + { type = type.withNullable(true); } + ) + [ <COMMENT> <QUOTED_STRING> { + String p = SqlParserUtil.parseString(token.image); + comment = SqlLiteral.createCharString(p, getPos()); + }] + { + SqlTableColumn tableColumn = new SqlTableColumn(name, type, comment, getPos()); + 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); + } +} + +SqlNode PropertyValue() : +{ + SqlIdentifier key; + SqlNode value; + SqlParserPos pos; +} +{ + key = CompoundIdentifier() + { pos = getPos(); } + <EQ> value = StringLiteral() + { + return new SqlProperty(key, value, getPos()); + } +} + +SqlNode SqlCreateTable() : +{ + final SqlParserPos startPos; + SqlIdentifier tableName; + SqlNodeList primaryKeyList = null; + List<SqlNodeList> uniqueKeysList = null; + SqlNodeList columnList = SqlNodeList.EMPTY; + SqlCharStringLiteral comment = null; Review comment: make it align? ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
