This is an automated email from the ASF dual-hosted git repository.

libenchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/master by this push:
     new dd768443424 [FLINK-29990][sql-parser] Fix unparsed sql for 
SqlTableLike with no options
dd768443424 is described below

commit dd76844342489a252f8b76417090f137028af0bc
Author: chengshuo.cs <chengshuo...@bytedance.com>
AuthorDate: Fri Nov 11 15:21:24 2022 +0800

    [FLINK-29990][sql-parser] Fix unparsed sql for SqlTableLike with no options
---
 .../org/apache/flink/sql/parser/ddl/SqlTableLike.java |  3 +++
 .../flink/sql/parser/FlinkSqlParserImplTest.java      | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git 
a/flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlTableLike.java
 
b/flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlTableLike.java
index 634eb1b0b55..eb1651cc2e0 100644
--- 
a/flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlTableLike.java
+++ 
b/flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlTableLike.java
@@ -223,6 +223,9 @@ public class SqlTableLike extends SqlCall implements 
ExtendedSqlNode {
     public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
         writer.keyword("LIKE");
         sourceTable.unparse(writer, leftPrec, rightPrec);
+        if (options == null || options.isEmpty()) {
+            return;
+        }
         SqlWriter.Frame frame = writer.startList("(", ")");
         for (SqlTableLikeOption option : options) {
             writer.newlineAndIndent();
diff --git 
a/flink-table/flink-sql-parser/src/test/java/org/apache/flink/sql/parser/FlinkSqlParserImplTest.java
 
b/flink-table/flink-sql-parser/src/test/java/org/apache/flink/sql/parser/FlinkSqlParserImplTest.java
index 741afa6d010..2dd968993f0 100644
--- 
a/flink-table/flink-sql-parser/src/test/java/org/apache/flink/sql/parser/FlinkSqlParserImplTest.java
+++ 
b/flink-table/flink-sql-parser/src/test/java/org/apache/flink/sql/parser/FlinkSqlParserImplTest.java
@@ -1078,6 +1078,25 @@ class FlinkSqlParserImplTest extends SqlParserTest {
         sql(sql).fails("(?s).*Encountered \"a\" at line 6, column 3.\n.*");
     }
 
+    @Test
+    void testCreateTableLikeWithoutOption() {
+        final String sql =
+                "create table source_table(\n"
+                        + "  a int,\n"
+                        + "  b bigint,\n"
+                        + "  c string\n"
+                        + ")\n"
+                        + "LIKE parent_table";
+        final String expected =
+                "CREATE TABLE `SOURCE_TABLE` (\n"
+                        + "  `A` INTEGER,\n"
+                        + "  `B` BIGINT,\n"
+                        + "  `C` STRING\n"
+                        + ")\n"
+                        + "LIKE `PARENT_TABLE`";
+        sql(sql).ok(expected);
+    }
+
     @Test
     void testCreateTableWithLikeClause() {
         final String sql =

Reply via email to