You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by st...@apache.org on 2020/03/04 23:24:10 UTC

[impala] 01/02: IMPALA-7686: Allow RANGE() clause before HASH() clause for PARTITION BY

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

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

commit 158f0b45752de52037a682d5766669c287f2fb72
Author: Adam Tamas <ta...@cloudera.com>
AuthorDate: Mon Mar 2 11:42:13 2020 +0100

    IMPALA-7686: Allow RANGE() clause before HASH() clause for PARTITION BY
    
    Modified the sql_parser.cup to accept the reversed syntax.
    
    Testing:
    -Added extra analyzer tests to cover the case when RANGE() is before HASH()
    for Kudu tables.
    
    Change-Id: I914e340e9acfb0f49c7d4f78705dbd9bde0aec8c
    Reviewed-on: http://gerrit.cloudera.org:8080/15332
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 fe/src/main/cup/sql-parser.cup                                 |  9 +++++++--
 .../java/org/apache/impala/analysis/AnalyzeKuduDDLTest.java    | 10 ++++++++++
 fe/src/test/java/org/apache/impala/analysis/ParserTest.java    |  4 ++--
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/fe/src/main/cup/sql-parser.cup b/fe/src/main/cup/sql-parser.cup
index ee07f4f..bc2613d 100644
--- a/fe/src/main/cup/sql-parser.cup
+++ b/fe/src/main/cup/sql-parser.cup
@@ -1598,8 +1598,8 @@ partition_column_defs ::=
   {: RESULT = col_defs; :}
   ;
 
-// The PARTITION BY clause contains any number of HASH() clauses followed by exactly zero
-// or one RANGE clauses
+// The PARTITION BY clause contains any number of HASH() clauses followed by or following
+// exactly zero or one RANGE clauses
 partition_param_list ::=
   KW_PARTITION KW_BY hash_partition_param_list:list
   {: RESULT = list; :}
@@ -1610,6 +1610,11 @@ partition_param_list ::=
     list.add(rng);
     RESULT = list;
   :}
+  | KW_PARTITION KW_BY range_partition_param:rng COMMA hash_partition_param_list:list
+  {:
+    list.add(rng);
+    RESULT = list;
+  :}
   ;
 
 // A list of HASH partitioning clauses used for flexible partitioning
diff --git a/fe/src/test/java/org/apache/impala/analysis/AnalyzeKuduDDLTest.java b/fe/src/test/java/org/apache/impala/analysis/AnalyzeKuduDDLTest.java
index 288bce3..3bde618 100644
--- a/fe/src/test/java/org/apache/impala/analysis/AnalyzeKuduDDLTest.java
+++ b/fe/src/test/java/org/apache/impala/analysis/AnalyzeKuduDDLTest.java
@@ -120,6 +120,16 @@ public class AnalyzeKuduDDLTest extends FrontendTestBase {
         "(partition values < 'aa', partition 'aa' <= values < 'bb', " +
         "partition 'bb' <= values < 'cc', partition 'cc' <= values) " +
         "stored as kudu", isExternalPurgeTbl);
+    // Swapped RANGE and HASH
+    AnalyzesOk("create table tab (x int, y string, primary key(x, y)) " +
+        "partition by range(y) (partition values < 'aa', partition 'aa' " +
+        "<= values < 'bb', partition 'bb' <= values < 'cc', partition 'cc' <= values), " +
+        "hash(x) partitions 3 stored as kudu", isExternalPurgeTbl);
+    // RANGE followed by multiple HASH
+    AnalyzesOk("create table tab (x int, y string, primary key(x, y)) " +
+        "partition by range(y) (partition values < 'aa', partition 'aa' " +
+        "<= values < 'bb', partition 'bb' <= values < 'cc', partition 'cc' <= values), " +
+        "hash(x) partitions 3, hash(y) partitions 2 stored as kudu", isExternalPurgeTbl);
     // Key column in upper case
     AnalyzesOk("create table tab (x int, y int, primary key (X)) " +
         "partition by hash (x) partitions 8 stored as kudu", isExternalPurgeTbl);
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 b3c22a5..431a5dd 100644
--- a/fe/src/test/java/org/apache/impala/analysis/ParserTest.java
+++ b/fe/src/test/java/org/apache/impala/analysis/ParserTest.java
@@ -2876,6 +2876,8 @@ public class ParserTest extends FrontendTestBase {
         "HASH (a) PARTITIONS 3, RANGE (a, b) (PARTITION VALUE = (1, 'abc'), " +
         "PARTITION VALUE = (2, 'def'))");
     ParsesOk("CREATE TABLE Foo (a int) PARTITION BY RANGE (a) " +
+        "(PARTITION VALUE = 10), HASH (a) PARTITIONS 3");
+    ParsesOk("CREATE TABLE Foo (a int) PARTITION BY RANGE (a) " +
         "(PARTITION VALUE = 1 + 1) STORED AS KUDU");
     ParsesOk("CREATE TABLE Foo (a int) PARTITION BY RANGE (a) " +
         "(PARTITION 1 + 1 < VALUES) STORED AS KUDU");
@@ -2889,8 +2891,6 @@ public class ParserTest extends FrontendTestBase {
     ParserError("CREATE TABLE Foo (a int) PARTITION BY HASH (a) PARTITIONS 4, " +
         "RANGE (a) (PARTITION VALUE = 10), RANGE (a) (PARTITION VALUES < 10)");
     ParserError("CREATE TABLE Foo (a int) PARTITION BY RANGE (a) " +
-        "(PARTITION VALUE = 10), HASH (a) PARTITIONS 3");
-    ParserError("CREATE TABLE Foo (a int) PARTITION BY RANGE (a) " +
         "(PARTITION VALUES = 10) STORED AS KUDU");
     ParserError("CREATE TABLE Foo (a int) PARTITION BY RANGE (a) " +
         "(PARTITION 10 < VALUE < 20) STORED AS KUDU");