Repository: hive Updated Branches: refs/heads/master 4d5d80609 -> 8e7c3b340
HIVE-21124: HPL/SQL does not support the CREATE TABLE LIKE statement (Baoning He, reviewed by Daniel Dai) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/8e7c3b34 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/8e7c3b34 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/8e7c3b34 Branch: refs/heads/master Commit: 8e7c3b340f36a3b76453338b04b8cda360eeaa70 Parents: 4d5d806 Author: Daniel Dai <dai...@gmail.com> Authored: Wed Jan 16 22:21:57 2019 -0800 Committer: Daniel Dai <dai...@gmail.com> Committed: Wed Jan 16 22:21:57 2019 -0800 ---------------------------------------------------------------------- hplsql/src/main/antlr4/org/apache/hive/hplsql/Hplsql.g4 | 2 +- hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java | 3 +++ .../src/test/java/org/apache/hive/hplsql/TestHplsqlOffline.java | 5 +++++ hplsql/src/test/queries/offline/create_table.sql | 1 + hplsql/src/test/results/offline/create_table.out.txt | 2 ++ 5 files changed, 12 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/8e7c3b34/hplsql/src/main/antlr4/org/apache/hive/hplsql/Hplsql.g4 ---------------------------------------------------------------------- diff --git a/hplsql/src/main/antlr4/org/apache/hive/hplsql/Hplsql.g4 b/hplsql/src/main/antlr4/org/apache/hive/hplsql/Hplsql.g4 index 186b617..77c2e2c 100644 --- a/hplsql/src/main/antlr4/org/apache/hive/hplsql/Hplsql.g4 +++ b/hplsql/src/main/antlr4/org/apache/hive/hplsql/Hplsql.g4 @@ -227,7 +227,7 @@ create_local_temp_table_stmt : ; create_table_definition : - (T_AS? T_OPEN_P select_stmt T_CLOSE_P | T_AS? select_stmt | T_OPEN_P create_table_columns T_CLOSE_P) create_table_options? + (T_AS? T_OPEN_P select_stmt T_CLOSE_P | T_AS? select_stmt | T_OPEN_P create_table_columns T_CLOSE_P | T_LIKE table_name) create_table_options? ; create_table_columns : http://git-wip-us.apache.org/repos/asf/hive/blob/8e7c3b34/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java ---------------------------------------------------------------------- diff --git a/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java b/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java index 0094e82..eabb9fa 100644 --- a/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java +++ b/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java @@ -172,6 +172,9 @@ public class Stmt { } exec.append(sql, ctx.T_CLOSE_P().getText(), last, ctx.T_CLOSE_P().getSymbol()); } + else if (ctx.T_LIKE() != null) { + sql.append(" ").append(ctx.T_LIKE().getText()).append(" ").append(evalPop(ctx.table_name())); + } // CREATE TABLE AS SELECT statement else { exec.append(sql, evalPop(ctx.select_stmt()).toString(), last, ctx.select_stmt().getStart()); http://git-wip-us.apache.org/repos/asf/hive/blob/8e7c3b34/hplsql/src/test/java/org/apache/hive/hplsql/TestHplsqlOffline.java ---------------------------------------------------------------------- diff --git a/hplsql/src/test/java/org/apache/hive/hplsql/TestHplsqlOffline.java b/hplsql/src/test/java/org/apache/hive/hplsql/TestHplsqlOffline.java index c908191..b48c8c5 100644 --- a/hplsql/src/test/java/org/apache/hive/hplsql/TestHplsqlOffline.java +++ b/hplsql/src/test/java/org/apache/hive/hplsql/TestHplsqlOffline.java @@ -34,6 +34,11 @@ public class TestHplsqlOffline { private final ByteArrayOutputStream out = new ByteArrayOutputStream(); @Test + public void testCreateTable() throws Exception { + run("create_table"); + } + + @Test public void testCreateTableDb2() throws Exception { run("create_table_db2"); } http://git-wip-us.apache.org/repos/asf/hive/blob/8e7c3b34/hplsql/src/test/queries/offline/create_table.sql ---------------------------------------------------------------------- diff --git a/hplsql/src/test/queries/offline/create_table.sql b/hplsql/src/test/queries/offline/create_table.sql new file mode 100644 index 0000000..9fde50f --- /dev/null +++ b/hplsql/src/test/queries/offline/create_table.sql @@ -0,0 +1 @@ +CREATE TABLE tbl LIKE tbl2; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hive/blob/8e7c3b34/hplsql/src/test/results/offline/create_table.out.txt ---------------------------------------------------------------------- diff --git a/hplsql/src/test/results/offline/create_table.out.txt b/hplsql/src/test/results/offline/create_table.out.txt new file mode 100644 index 0000000..fac30ed --- /dev/null +++ b/hplsql/src/test/results/offline/create_table.out.txt @@ -0,0 +1,2 @@ +Ln:1 CREATE TABLE +Ln:1 CREATE TABLE tbl LIKE tbl2 \ No newline at end of file