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/14 09:17:05 UTC

[GitHub] [flink] luoyuxia commented on a diff in pull request #20252: [FLINK-28463][flink-sql-parser] Flink dialect supports CREATE TABLE AS SELECT(CTAS) syntax

luoyuxia commented on code in PR #20252:
URL: https://github.com/apache/flink/pull/20252#discussion_r920919363


##########
flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl:
##########
@@ -1152,6 +1153,10 @@ SqlCreate SqlCreateTable(Span s, boolean replace, boolean isTemporary) :
         <LIKE>
         tableLike = SqlTableLike(getPos())
     ]
+    [

Review Comment:
   As `LIKE` and  `AS`  won't appear at same time in our sytax,  I think it should be somethink like `[ [LIKE] | [AS] ]`



##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTable.java:
##########
@@ -186,9 +195,24 @@ public void validate() throws SqlValidateException {
             }
         }
 
+        if (query != null && tableLike != null) {
+            throw new SqlValidateException(
+                    pos,
+                    "CREATE TABLE AS SELECT and CREATE TABLE LIKE syntax cannot be used together.");
+        }
+
         if (tableLike != null) {
             tableLike.validate();
         }
+
+        if (query != null
+                && (columnList.size() > 0
+                        || constraints.size() > 0
+                        || partitionKeyList.size() > 0)) {
+            throw new SqlValidateException(
+                    pos,
+                    "CREATE TABLE AS SELECT syntax does not yet support Column/Partition/Constraints settings.");

Review Comment:
   may be some more clear message like
   `CREATE TABLE AS SELECT syntax does not yet support to specific Column/Partition/Constraints`



##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateTable.java:
##########
@@ -302,6 +326,11 @@ public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
             writer.newlineAndIndent();
             this.tableLike.unparse(writer, leftPrec, rightPrec);
         }
+
+        if (this.query != null) {
+            writer.newlineAndIndent();
+            this.query.unparse(writer, 0, 0);

Review Comment:
   Why not follow the above code to pass `leftPrec` and `rightPrec` to the `unparse` method?



-- 
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