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

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

commit 841b8c32c8bd38b739077835d85dfe5b5bad14a7
Author: Daniel Vanko <[email protected]>
AuthorDate: Tue Feb 25 16:23:48 2025 +0100

    IMPALA-12107: Throw AnalysisException for unsupported Kudu range-partioning 
types
    
    Change Precondition check to throwing AnalysisException for illegal key
    types in the PARTITION BY RANGE clause.
    
    Testing:
     * add fe tests
     * add e2e tests
    
    Change-Id: I3e3037318065b0f4437045a7e8dbb76639404167
    Reviewed-on: http://gerrit.cloudera.org:8080/22542
    Tested-by: Impala Public Jenkins <[email protected]>
    Reviewed-by: Zoltan Borok-Nagy <[email protected]>
---
 .../org/apache/impala/analysis/RangePartition.java |  8 ++++++--
 .../apache/impala/analysis/AnalyzeKuduDDLTest.java | 22 ++++++++++++++++++--
 .../queries/QueryTest/kudu_create.test             | 24 ++++++++++++++++++++++
 3 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/fe/src/main/java/org/apache/impala/analysis/RangePartition.java 
b/fe/src/main/java/org/apache/impala/analysis/RangePartition.java
index f8b98f773..4bd4c780a 100644
--- a/fe/src/main/java/org/apache/impala/analysis/RangePartition.java
+++ b/fe/src/main/java/org/apache/impala/analysis/RangePartition.java
@@ -174,6 +174,12 @@ public class RangePartition extends StmtNode {
 
   private LiteralExpr analyzeBoundaryValue(Expr value, ColumnDef pkColumn,
       Analyzer analyzer) throws AnalysisException {
+    Type colType = pkColumn.getType();
+    if (!KuduUtil.isSupportedKeyType(colType)) {
+      throw new AnalysisException(String.format("%s type is not allowed to be 
part of " +
+          "a PRIMARY KEY therefore not allowed for range-partitioning.",
+          colType.toSql()));
+    }
     try {
       value.analyze(analyzer);
     } catch (AnalysisException e) {
@@ -194,8 +200,6 @@ public class RangePartition extends StmtNode {
       throw new AnalysisException(String.format("Range partition values cannot 
be " +
           "NULL. Range partition: '%s'", toSql()));
     }
-    org.apache.impala.catalog.Type colType = pkColumn.getType();
-    Preconditions.checkState(KuduUtil.isSupportedKeyType(colType));
 
     // Special case string literals in timestamp columns for convenience.
     if (literal.getType().isStringType() && colType.isTimestamp()) {
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 5a7b96774..bf8802726 100644
--- a/fe/src/test/java/org/apache/impala/analysis/AnalyzeKuduDDLTest.java
+++ b/fe/src/test/java/org/apache/impala/analysis/AnalyzeKuduDDLTest.java
@@ -109,7 +109,6 @@ public class AnalyzeKuduDDLTest extends FrontendTestBase {
         "stored as kudu", "Specify primary key or non unique primary key for 
the Kudu " +
         "table, or create partitions with the beginning columns of the table.",
         isExternalPurgeTbl);
-
     AnalyzesOk("create table tab (x int, y string, primary key (x)) partition 
by " +
         "hash (x) partitions 3, range (x) (partition values < 1, partition " +
         "1 <= values < 10, partition 10 <= values < 20, partition value = 30) 
" +
@@ -117,6 +116,12 @@ public class AnalyzeKuduDDLTest extends FrontendTestBase {
     AnalyzesOk("create table tab (x int, y int, primary key (x, y)) partition 
by " +
         "range (x, y) (partition value = (2001, 1), partition value = (2002, 
1), " +
         "partition value = (2003, 2)) stored as kudu", isExternalPurgeTbl);
+    // Promote all partition columns as non unique primary key columns if 
primary keys
+    // are not declared, but partition columns must be supported type.
+    AnalysisError("create table tab (x float) partition by range(x) " +
+        "(partition values < cast(0 as float), partition cast(1.5 as float) <= 
values) " +
+        "stored as kudu", "FLOAT type is not allowed to be part of a " +
+        "PRIMARY KEY therefore not allowed for range-partitioning.", 
isExternalPurgeTbl);
     // Non-literal boundary values in range partitions
     AnalyzesOk("create table tab (x int, y int, primary key (x)) partition by 
" +
         "range (x) (partition values < 1 + 1, partition (1+3) + 2 < values < 
10, " +
@@ -283,7 +288,7 @@ public class AnalyzeKuduDDLTest extends FrontendTestBase {
         "partition by range (b) (partition value = 'abc') stored as kudu",
         "Column 'b' in 'RANGE (b) (PARTITION VALUE = 'abc')' is not a key 
column. " +
         "Only key columns can be used in PARTITION BY.", isExternalPurgeTbl);
-    // No float range partition values
+    // No incompatible range partition values
     AnalysisError("create table tab (a int, b int, c int, d int, primary key 
(a, b, c))" +
         "partition by hash (a, b, c) partitions 8, " +
         "range (a) (partition value = 1.2, partition value = 2) stored as 
kudu",
@@ -294,6 +299,19 @@ public class AnalyzeKuduDDLTest extends FrontendTestBase {
         "partition by hash (a, b) partitions 8, " +
         "range (a) (partition 0 < values < 1.23, partition 1.23 <= values)" +
         "stored as kudu", isExternalPurgeTbl);
+    // Unsuppported types for range partition
+    AnalysisError("create table tab (a float) partition by range(a) " +
+        "(partition values < 0, partition 1.5 <= values) " +
+        "stored as kudu", "FLOAT type is not allowed to be part of a " +
+        "PRIMARY KEY therefore not allowed for range-partitioning.", 
isExternalPurgeTbl);
+    AnalysisError("create table tab (a double) partition by range(a) " +
+        "(partition values < 0, partition 1.5 <= values) stored as kudu",
+        "DOUBLE type is not allowed to be part of a PRIMARY KEY therefore not 
allowed " +
+        "for range-partitioning.", isExternalPurgeTbl);
+    AnalysisError("create table tab (a boolean) partition by range(a) " +
+        "(partition value = true) stored as kudu",
+        "BOOLEAN type is not allowed to be part of a PRIMARY KEY therefore not 
allowed " +
+        "for range-partitioning.", isExternalPurgeTbl);
     // Non-existing column used in PARTITION BY
     AnalysisError("create table tab (a int, b int, primary key (a, b)) " +
         "partition by range(unknown_column) (partition value = 'abc') stored 
as kudu",
diff --git 
a/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test 
b/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test
index 37f8fda42..1fe5e3d0a 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test
@@ -709,3 +709,27 @@ select c1, c2, c3 from decimal_partitioned_tbl order by c1 
asc
 ---- TYPES
 DECIMAL,DECIMAL,DECIMAL
 ====
+---- QUERY
+# Cannot create a Kudu table with float range partition
+create table create_tbl_float_part (x float) partition by range (x)
+  (partition values < 0)
+stored as kudu
+---- CATCH
+AnalysisException: FLOAT type is not allowed to be part of a PRIMARY KEY 
therefore not allowed for range-partitioning.
+====
+---- QUERY
+# Cannot create a Kudu table with double range partition
+create table create_tbl_double_part (x double) partition by range (x)
+  (partition values < 0)
+stored as kudu
+---- CATCH
+AnalysisException: DOUBLE type is not allowed to be part of a PRIMARY KEY 
therefore not allowed for range-partitioning.
+====
+---- QUERY
+# Cannot create a Kudu table with boolean range partition
+create table create_tbl_float_part (x boolean) partition by range (x)
+  (partition value = true)
+stored as kudu
+---- CATCH
+AnalysisException: BOOLEAN type is not allowed to be part of a PRIMARY KEY 
therefore not allowed for range-partitioning.
+====

Reply via email to