This is an automated email from the ASF dual-hosted git repository. michaelsmith pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/impala.git
commit 296224a6fb5c461a22920eac4f06815b8dd26068 Author: wzhou-code <[email protected]> AuthorDate: Sun Apr 30 14:23:43 2023 -0700 IMPALA-12110: Create Kudu table in CTAS without specifying primary key IMPALA-11809 adds support non unique primary key for Kudu table. It allows to create Kudu table without specifying primary key since partition columns could be promoted as non unique primary key. But when creating Kudu table in CTAS without specifying primary key, Impala returns parsing error. This patch fixed the parsing issue for creating Kudu table in CTAS without specifying primary key. Testing: - Added new test cases in parsing unit-test and end-to-end unit-test. - Passed core tests. Change-Id: Ia7bb0cf1954e0a4c3d864a800e929a88de272dd5 Reviewed-on: http://gerrit.cloudera.org:8080/19825 Reviewed-by: Abhishek Chennaka <[email protected]> Reviewed-by: Riza Suminto <[email protected]> Tested-by: Impala Public Jenkins <[email protected]> --- fe/src/main/cup/sql-parser.cup | 12 +++++++++++ .../org/apache/impala/analysis/ParserTest.java | 11 ++++++++++- .../queries/QueryTest/kudu_create.test | 23 +++++++++++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/fe/src/main/cup/sql-parser.cup b/fe/src/main/cup/sql-parser.cup index 9a2de413c..b5d83645b 100755 --- a/fe/src/main/cup/sql-parser.cup +++ b/fe/src/main/cup/sql-parser.cup @@ -1430,6 +1430,18 @@ create_tbl_as_select_params ::= RESULT = new CreateTableAsSelectStmt.CtasParams(new CreateTableStmt(tbl_def), select_stmt, null); :} + | tbl_def_without_col_defs:tbl_def + // Create Kudu table without specifying primary key. The partition columns could be + // promoted as non unique primary key. + partition_param_list:partition_params + tbl_options:options + KW_AS query_stmt:select_stmt + {: + tbl_def.getKuduPartitionParams().addAll(partition_params); + tbl_def.setOptions(options); + RESULT = new CreateTableAsSelectStmt.CtasParams(new CreateTableStmt(tbl_def), + select_stmt, null); + :} | tbl_def_without_col_defs:tbl_def iceberg_partition_spec_list:iceberg_specs tbl_options:options diff --git a/fe/src/test/java/org/apache/impala/analysis/ParserTest.java b/fe/src/test/java/org/apache/impala/analysis/ParserTest.java index 3da74e15b..a38405e02 100755 --- a/fe/src/test/java/org/apache/impala/analysis/ParserTest.java +++ b/fe/src/test/java/org/apache/impala/analysis/ParserTest.java @@ -3306,12 +3306,21 @@ public class ParserTest extends FrontendTestBase { // Flexible partitioning ParsesOk("CREATE TABLE Foo PRIMARY KEY (i) PARTITION BY HASH(i) PARTITIONS 4 AS " + "SELECT 1"); - ParserError("CREATE TABLE Foo PARTITION BY HASH(i) PARTITIONS 4 AS SELECT 1"); + ParsesOk("CREATE TABLE Foo PARTITION BY HASH(i) PARTITIONS 4 AS SELECT 1"); ParsesOk("CREATE TABLE Foo PRIMARY KEY (a) PARTITION BY HASH(a) PARTITIONS 4 " + "TBLPROPERTIES ('a'='b', 'c'='d') AS SELECT * from bar"); ParsesOk("CREATE TABLE Foo PRIMARY KEY (a) PARTITION BY RANGE(a) " + "(PARTITION 1 < VALUES < 10, PARTITION 10 <= VALUES < 20, PARTITION VALUE = 30) " + "STORED AS KUDU AS SELECT * FROM Bar"); + ParsesOk("CREATE TABLE Foo NON UNIQUE PRIMARY KEY (a) " + + "PARTITION BY HASH (a) PARTITIONS 2 " + + "STORED AS KUDU AS SELECT * FROM Bar"); + ParsesOk("CREATE TABLE Foo PARTITION BY RANGE(a) " + + "(PARTITION 1 < VALUES < 10, PARTITION 10 <= VALUES < 20, " + + " PARTITION VALUE = 30) " + + "STORED AS KUDU AS SELECT * FROM Bar"); + ParsesOk("CREATE TABLE Foo PARTITION BY HASH (a) PARTITIONS 2 " + + "STORED AS KUDU AS SELECT * FROM Bar"); } @Test diff --git a/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test b/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test index add08cf85..3d168312c 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test +++ b/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test @@ -643,4 +643,25 @@ create table non_unique_key_create_tbl14 (id int primary key, auto_incrementing_ partition by hash(id) partitions 3 stored as kudu ---- CATCH IllegalArgumentException: Column name auto_incrementing_id is reserved by Kudu engine -==== \ No newline at end of file +==== +---- QUERY +# Create Kudu table in CTAS statement without specifying primary key. +# Partition column 'id' is promoted as non unique primary key. +create table non_unique_key_create_tbl15 +partition by range (id) (partition values <= 1, partition 1 < values <= 3, + partition 3 < values <= 5, partition 5 < values) +stored as kudu +as select id, int_col from functional.alltypestiny order by id asc limit 100; +select id, int_col, auto_incrementing_id from non_unique_key_create_tbl15 order by id asc; +---- RESULTS +0,0,1 +1,1,2 +2,0,1 +3,1,2 +4,0,1 +5,1,2 +6,0,1 +7,1,2 +---- TYPES +INT,INT,BIGINT +====
