Repository: incubator-impala
Updated Branches:
  refs/heads/master e24333c1f -> 878fcf5a7


IMPALA-5111: Fix check when creating NOT NULL PK col in Kudu

The fix for IMPALA-4616 broke the ability to create a PK key
col in a Kudu table as explicitly 'NOT NULL'. While this is
the default, it should be possible to specify.

The precondition that was failing was fixed, and some tests
were added/modified.

Change-Id: I557eea7cd994d6a2ed38893d283d08107e78f789
Reviewed-on: http://gerrit.cloudera.org:8080/6465
Reviewed-by: Matthew Jacobs <[email protected]>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/878fcf5a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/878fcf5a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/878fcf5a

Branch: refs/heads/master
Commit: 878fcf5a746153bcaf38dab2ecd6fa6a462ceb13
Parents: e24333c
Author: Matthew Jacobs <[email protected]>
Authored: Thu Mar 23 13:16:42 2017 -0700
Committer: Impala Public Jenkins <[email protected]>
Committed: Fri Mar 24 21:22:50 2017 +0000

----------------------------------------------------------------------
 .../org/apache/impala/service/KuduCatalogOpExecutor.java |  4 +++-
 .../java/org/apache/impala/analysis/AnalyzeDDLTest.java  | 11 +++++++++++
 .../functional-query/queries/QueryTest/kudu_create.test  |  3 ++-
 3 files changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/878fcf5a/fe/src/main/java/org/apache/impala/service/KuduCatalogOpExecutor.java
----------------------------------------------------------------------
diff --git 
a/fe/src/main/java/org/apache/impala/service/KuduCatalogOpExecutor.java 
b/fe/src/main/java/org/apache/impala/service/KuduCatalogOpExecutor.java
index f1a9135..ed3b5af 100644
--- a/fe/src/main/java/org/apache/impala/service/KuduCatalogOpExecutor.java
+++ b/fe/src/main/java/org/apache/impala/service/KuduCatalogOpExecutor.java
@@ -100,7 +100,9 @@ public class KuduCatalogOpExecutor {
     ColumnSchemaBuilder csb = new ColumnSchemaBuilder(column.getColumnName(), 
kuduType);
     csb.key(isKey);
     if (column.isSetIs_nullable()) {
-      Preconditions.checkArgument(!isKey);
+      // If nullability is explicitly set and the column is a key, it must 
have been
+      // set as NOT NULL. This is the default, but it is also valid to specify 
it.
+      Preconditions.checkArgument(!isKey || !column.isIs_nullable());
       csb.nullable(column.isIs_nullable());
     } else {
       // Non-key columns are by default nullable unless the user explicitly 
sets its

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/878fcf5a/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
----------------------------------------------------------------------
diff --git a/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java 
b/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
index 757b857..1278372 100644
--- a/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
+++ b/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
@@ -2155,11 +2155,22 @@ public class AnalyzeDDLTest extends FrontendTestBase {
         for (String nul: nullability) {
           for (String def: defaultVal) {
             for (String block: blockSize) {
+              // Test analysis for a non-key column
               AnalyzesOk(String.format("create table tab (x int primary key " +
                   "not null encoding %s compression %s %s %s, y int encoding 
%s " +
                   "compression %s %s %s %s) partition by hash (x) " +
                   "partitions 3 stored as kudu", enc, comp, def, block, enc,
                   comp, def, nul, block));
+
+              // For a key column
+              String createTblStr = String.format("create table tab (x int 
primary key " +
+                  "%s encoding %s compression %s %s %s) partition by hash (x) 
" +
+                  "partitions 3 stored as kudu", nul, enc, comp, def, block);
+              if (nul.equals("null")) {
+                AnalysisError(createTblStr, "Primary key columns cannot be 
nullable");
+              } else {
+                AnalyzesOk(createTblStr);
+              }
             }
           }
         }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/878fcf5a/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test
----------------------------------------------------------------------
diff --git 
a/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test 
b/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test
index bc84db2..b7db12f 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test
@@ -80,7 +80,8 @@ INT,INT
 ====
 ---- QUERY
 # Test implicit casting/folding of partition values.
-create table tab (a int primary key) partition by range (a) (partition value = 
false)
+create table tab (a int not null primary key)
+partition by range (a) (partition value = false)
 stored as kudu
 ---- RESULTS
 ====

Reply via email to