lsyldliu commented on code in PR #20252:
URL: https://github.com/apache/flink/pull/20252#discussion_r927563895
##########
flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl:
##########
@@ -1151,9 +1152,13 @@ SqlCreate SqlCreateTable(Span s, boolean replace,
boolean isTemporary) :
[
<LIKE>
tableLike = SqlTableLike(getPos())
+ |
Review Comment:
```suggestion
{
return new SqlCreateTableLike(startPos.plus(getPos()),
tableName,
columnList,
constraints,
propertyList,
partitionColumns,
watermark,
comment,
tableLike,
isTemporary,
ifNotExists);
}
|
<AS>
asQuery = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY)
{
return new SqlCreateTableAs(startPos.plus(getPos()),
tableName,
columnList,
constraints,
propertyList,
partitionColumns,
watermark,
comment,
asQuery,
isTemporary,
ifNotExists);
}
]
{
return new SqlCreateTable(startPos.plus(getPos()),
tableName,
columnList,
constraints,
propertyList,
partitionColumns,
watermark,
comment,
isTemporary,
ifNotExists);
}
```
##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTableAs.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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;
+
+/**
+ * {@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_1;
+ * }</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 = asQuery;
+ }
+
+ @Override
+ public @Nonnull SqlOperator getOperator() {
+ return OPERATOR;
+ }
+
+ @Override
+ public @Nonnull List<SqlNode> getOperandList() {
+ return ImmutableNullableList.<SqlNode>builder()
+ .addAll(super.getOperandList())
+ .add(asQuery)
+ .build();
+ }
+
+ @Override
+ public void validate() throws SqlValidateException {
+ super.validate();
+ if (isTemporary()) {
+ throw new SqlValidateException(
+ getParserPosition(),
+ "CREATE TABLE AS SELECT syntax does not support to create
temporary table yet.");
+ }
+
+ if (getColumnList().size() > 0) {
+ throw new SqlValidateException(
+ getParserPosition(),
+ "CREATE TABLE AS SELECT syntax does not support explicitly
specifying columns yet.");
Review Comment:
```suggestion
"CREATE TABLE AS SELECT syntax does not support to
specify explicit columns yet.");
```
##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTableLike.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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;
+
+/** CREATE TABLE LIKE DDL sql call. */
Review Comment:
Referring to `SqlCreateTableAs`, give more description.
##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTableAs.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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;
+
+/**
+ * {@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_1;
Review Comment:
```suggestion
* AS SELECT * FROM base_table;
```
##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTableAs.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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;
+
+/**
+ * {@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_1;
+ * }</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 = asQuery;
+ }
+
+ @Override
+ public @Nonnull SqlOperator getOperator() {
+ return OPERATOR;
+ }
+
+ @Override
+ public @Nonnull List<SqlNode> getOperandList() {
+ return ImmutableNullableList.<SqlNode>builder()
+ .addAll(super.getOperandList())
+ .add(asQuery)
+ .build();
+ }
+
+ @Override
+ public void validate() throws SqlValidateException {
+ super.validate();
+ if (isTemporary()) {
+ throw new SqlValidateException(
+ getParserPosition(),
+ "CREATE TABLE AS SELECT syntax does not support to create
temporary table yet.");
+ }
+
+ if (getColumnList().size() > 0) {
+ throw new SqlValidateException(
+ getParserPosition(),
+ "CREATE TABLE AS SELECT syntax does not support explicitly
specifying columns yet.");
+ }
+
+ if (getWatermark().isPresent()) {
+ throw new SqlValidateException(
+ getParserPosition(),
+ "CREATE TABLE AS SELECT syntax does not support explicitly
specifying watermark yet.");
Review Comment:
```suggestion
"CREATE TABLE AS SELECT syntax does not support to
specify explicit watermark yet.");
```
##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTableAs.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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;
+
+/**
+ * {@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_1;
+ * }</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 = asQuery;
+ }
+
+ @Override
+ public @Nonnull SqlOperator getOperator() {
+ return OPERATOR;
+ }
+
+ @Override
+ public @Nonnull List<SqlNode> getOperandList() {
+ return ImmutableNullableList.<SqlNode>builder()
+ .addAll(super.getOperandList())
+ .add(asQuery)
+ .build();
+ }
+
+ @Override
+ public void validate() throws SqlValidateException {
+ super.validate();
+ if (isTemporary()) {
+ throw new SqlValidateException(
+ getParserPosition(),
+ "CREATE TABLE AS SELECT syntax does not support to create
temporary table yet.");
+ }
+
+ if (getColumnList().size() > 0) {
+ throw new SqlValidateException(
+ getParserPosition(),
+ "CREATE TABLE AS SELECT syntax does not support explicitly
specifying columns yet.");
+ }
+
+ if (getWatermark().isPresent()) {
+ throw new SqlValidateException(
+ getParserPosition(),
+ "CREATE TABLE AS SELECT syntax does not support explicitly
specifying watermark yet.");
+ }
+ // TODO flink dialect supports dynamic partition
+ if (getPartitionKeyList().size() > 0) {
+ throw new SqlValidateException(
+ getParserPosition(),
+ "CREATE TABLE AS SELECT syntax does not support creating
partitioned table yet.");
Review Comment:
```suggestion
"CREATE TABLE AS SELECT syntax does not support to
create partitioned table yet.");
```
--
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]