beyond1920 commented on code in PR #20252: URL: https://github.com/apache/flink/pull/20252#discussion_r929887645
########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTableLike.java: ########## @@ -0,0 +1,135 @@ +/* + * 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. + */ + +package org.apache.flink.sql.parser.ddl; + +import org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint; +import org.apache.flink.sql.parser.error.SqlValidateException; + +import org.apache.calcite.sql.SqlCharStringLiteral; +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.SqlSpecialOperator; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.List; + +import static java.util.Objects.requireNonNull; + +/** + * {@link SqlNode} to describe the CREATE TABLE LIKE syntax. CREATE TABLE LIKE syntax is the same as + * CREATE TABLE syntax, both are just metadata operations. Review Comment: CREATE TABLE LIKE syntax is similar as CREATE TABLE syntax, besides it has LIKE sub clause to inherits property of an existed table. ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTableLike.java: ########## @@ -0,0 +1,135 @@ +/* + * 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. + */ + +package org.apache.flink.sql.parser.ddl; + +import org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint; +import org.apache.flink.sql.parser.error.SqlValidateException; + +import org.apache.calcite.sql.SqlCharStringLiteral; +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.SqlSpecialOperator; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.List; + +import static java.util.Objects.requireNonNull; + +/** + * {@link SqlNode} to describe the CREATE TABLE LIKE syntax. CREATE TABLE LIKE syntax is the same as + * CREATE TABLE syntax, both are just metadata operations. + * + * <p>Example: A DDL like the one below for creating a `derived_table` Review Comment: Example: ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTable.java: ########## @@ -85,7 +83,6 @@ public SqlCreateTable( SqlNodeList partitionKeyList, @Nullable SqlWatermark watermark, @Nullable SqlCharStringLiteral comment, - @Nullable SqlTableLike tableLike, boolean isTemporary, boolean ifNotExists) { super(OPERATOR, pos, false, ifNotExists); Review Comment: how about call the other constructor to create a new instance? ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTableAs.java: ########## @@ -0,0 +1,163 @@ +/* + * 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. + */ + +package org.apache.flink.sql.parser.ddl; + +import org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint; +import org.apache.flink.sql.parser.error.SqlValidateException; + +import org.apache.calcite.sql.SqlCharStringLiteral; +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.SqlSpecialOperator; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.List; + +import static java.util.Objects.requireNonNull; + +/** + * {@link SqlNode} to describe the CREATE TABLE AS syntax. The CTAS syntax is different from CREATE + * TABLE syntax, which also create the pipeline to sync the data from the source to the derived + * table. + * + * <p>Example: A DDL like the one below for creating a `derived_table` + * + * <pre>{@code + * CREATE TABLE base_table ( + * id BIGINT, + * name STRING, + * tstmp TIMESTAMP, + * PRIMARY KEY(id) + * ) WITH ( + * ‘connector’ = ‘kafka’, + * ‘connector.starting-offset’: ‘12345’, + * ‘format’ = ‘json’ + * ) + * + * CREATE TABLE derived_table + * WITH ( + * 'connector' = 'jdbc', + * 'url' = 'http://localhost:10000', + * 'table-name' = 'syncedTable' + * ) + * AS SELECT * FROM base_table; + * }</pre> + */ +public class SqlCreateTableAs extends SqlCreateTable { + + public static final SqlSpecialOperator OPERATOR = + new SqlSpecialOperator("CREATE TABLE AS", SqlKind.CREATE_TABLE); + + private final SqlNode asQuery; + + public SqlCreateTableAs( + SqlParserPos pos, + SqlIdentifier tableName, + SqlNodeList columnList, + List<SqlTableConstraint> tableConstraints, + SqlNodeList propertyList, + SqlNodeList partitionKeyList, + @Nullable SqlWatermark watermark, + @Nullable SqlCharStringLiteral comment, + SqlNode asQuery, + boolean isTemporary, + boolean ifNotExists) { + super( + OPERATOR, + pos, + tableName, + columnList, + tableConstraints, + propertyList, + partitionKeyList, + watermark, + comment, + isTemporary, + ifNotExists); + this.asQuery = requireNonNull(asQuery, "asQuery should not be null"); Review Comment: ```suggestion this.asQuery = requireNonNull(asQuery, "As clause is required for CREATE TABLE AS SELECT DDL"); ``` ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTableLike.java: ########## @@ -0,0 +1,135 @@ +/* + * 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. + */ + +package org.apache.flink.sql.parser.ddl; + +import org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint; +import org.apache.flink.sql.parser.error.SqlValidateException; + +import org.apache.calcite.sql.SqlCharStringLiteral; +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.SqlSpecialOperator; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.List; + +import static java.util.Objects.requireNonNull; + +/** + * {@link SqlNode} to describe the CREATE TABLE LIKE syntax. CREATE TABLE LIKE syntax is the same as + * CREATE TABLE syntax, both are just metadata operations. + * + * <p>Example: A DDL like the one below for creating a `derived_table` + * + * <pre>{@code + * CREATE TABLE base_table ( + * id BIGINT, + * name STRING, + * tstmp TIMESTAMP, + * PRIMARY KEY(id) + * ) WITH ( + * ‘connector’ = ‘kafka’, + * ‘connector.starting-offset’: ‘12345’, + * ‘format’ = ‘json’ + * ) + * + * CREATE TABLE derived_table ( + * a int + * ) + * WITH ( + * 'connector' = 'jdbc', + * 'url' = 'http://localhost:10000', + * 'table-name' = 'derivedTable' + * ) + * LIKE base_table; + * }</pre> + */ +public class SqlCreateTableLike extends SqlCreateTable { + + public static final SqlSpecialOperator OPERATOR = + new SqlSpecialOperator("CREATE TABLE LIKE", SqlKind.CREATE_TABLE); + + private final SqlTableLike tableLike; + + public SqlCreateTableLike( + SqlParserPos pos, + SqlIdentifier tableName, + SqlNodeList columnList, + List<SqlTableConstraint> tableConstraints, + SqlNodeList propertyList, + SqlNodeList partitionKeyList, + @Nullable SqlWatermark watermark, + @Nullable SqlCharStringLiteral comment, + SqlTableLike tableLike, + boolean isTemporary, + boolean ifNotExists) { + super( + OPERATOR, + pos, + tableName, + columnList, + tableConstraints, + propertyList, + partitionKeyList, + watermark, + comment, + isTemporary, + ifNotExists); + this.tableLike = requireNonNull(tableLike, "tableLike should not be null"); Review Comment: ```suggestion this.tableLike = requireNonNull(tableLike, "LIKE clause is required for CREATE TABLE LIKE DDL"); ``` ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTableAs.java: ########## @@ -0,0 +1,163 @@ +/* + * 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. + */ + +package org.apache.flink.sql.parser.ddl; + +import org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint; +import org.apache.flink.sql.parser.error.SqlValidateException; + +import org.apache.calcite.sql.SqlCharStringLiteral; +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.SqlSpecialOperator; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.List; + +import static java.util.Objects.requireNonNull; + +/** + * {@link SqlNode} to describe the CREATE TABLE AS syntax. The CTAS syntax is different from CREATE + * TABLE syntax, which also create the pipeline to sync the data from the source to the derived + * table. + * + * <p>Example: A DDL like the one below for creating a `derived_table` Review Comment: ```suggestion * <p>Example: ``` ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTableAs.java: ########## @@ -0,0 +1,163 @@ +/* + * 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. + */ + +package org.apache.flink.sql.parser.ddl; + +import org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint; +import org.apache.flink.sql.parser.error.SqlValidateException; + +import org.apache.calcite.sql.SqlCharStringLiteral; +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.SqlSpecialOperator; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.List; + +import static java.util.Objects.requireNonNull; + +/** + * {@link SqlNode} to describe the CREATE TABLE AS syntax. The CTAS syntax is different from CREATE + * TABLE syntax, which also create the pipeline to sync the data from the source to the derived + * table. Review Comment: ```suggestion * . The CTAS would create a pipeline to compute the result of the given query and insert data into the derived table. ``` -- 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]
