IMPALA-4619: Allow NULL as default value in Kudu tables This commit fixes an issue where an error is thrown if the default value for a Kudu column is set to NULL.
Change-Id: Ida27ce56f1dd7603485a69c680db3bcea6702aff Reviewed-on: http://gerrit.cloudera.org:8080/5405 Reviewed-by: Dimitris Tsirogiannis <[email protected]> Tested-by: Internal 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/5ea17986 Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/5ea17986 Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/5ea17986 Branch: refs/heads/master Commit: 5ea179866114f7b7bd5922362dec62024d3ab5b8 Parents: 29971ac Author: Dimitris Tsirogiannis <[email protected]> Authored: Wed Dec 7 14:34:43 2016 -0800 Committer: Internal Jenkins <[email protected]> Committed: Thu Dec 8 04:53:38 2016 +0000 ---------------------------------------------------------------------- .../java/org/apache/impala/util/KuduUtil.java | 2 ++ .../apache/impala/analysis/AnalyzeDDLTest.java | 9 +++++++++ .../queries/QueryTest/kudu_create.test | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/5ea17986/fe/src/main/java/org/apache/impala/util/KuduUtil.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/org/apache/impala/util/KuduUtil.java b/fe/src/main/java/org/apache/impala/util/KuduUtil.java index edd331b..75b11b6 100644 --- a/fe/src/main/java/org/apache/impala/util/KuduUtil.java +++ b/fe/src/main/java/org/apache/impala/util/KuduUtil.java @@ -33,6 +33,7 @@ import org.apache.impala.thrift.TColumn; import org.apache.impala.thrift.TColumnEncoding; import org.apache.impala.thrift.TExpr; import org.apache.impala.thrift.TExprNode; +import org.apache.impala.thrift.TExprNodeType; import org.apache.impala.thrift.THdfsCompression; import org.apache.kudu.ColumnSchema; import org.apache.kudu.ColumnSchema.CompressionAlgorithm; @@ -156,6 +157,7 @@ public class KuduUtil { org.apache.kudu.Type type, String colName) throws ImpalaRuntimeException { Preconditions.checkState(defaultValue.getNodes().size() == 1); TExprNode literal = defaultValue.getNodes().get(0); + if (literal.getNode_type() == TExprNodeType.NULL_LITERAL) return null; switch (type) { case INT8: checkCorrectType(literal.isSetInt_literal(), type, colName, literal); http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/5ea17986/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 d1b6a8d..e62f797 100644 --- a/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java +++ b/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java @@ -2133,6 +2133,15 @@ public class AnalyzeDDLTest extends FrontendTestBase { } } } + // Use NULL as default values + AnalyzesOk("create table tab (x int primary key, i1 tinyint default null, " + + "i2 smallint default null, i3 int default null, i4 bigint default null, " + + "vals string default null, valf float default null, vald double default null, " + + "valb boolean default null) partition by hash (x) partitions 3 stored as kudu"); + // Use NULL as a default value on a non-nullable column + AnalysisError("create table tab (x int primary key, y int not null default null) " + + "partition by hash (x) partitions 3 stored as kudu", "Default value of NULL " + + "not allowed on non-nullable column: 'y'"); // Primary key specified using the PRIMARY KEY clause AnalyzesOk("create table tab (x int not null encoding plain_encoding " + "compression snappy block_size 1, y int null encoding rle compression lz4 " + http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/5ea17986/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 938a6a4..bc84db2 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test +++ b/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test @@ -123,3 +123,23 @@ select ID, nAmE, VALF, VALI from ignore_column_case where NaMe = 'Martin'; ---- TYPES INT,STRING,FLOAT,BIGINT ==== +---- QUERY +# Using NULL as default values +create table tbl_with_null_defaults (x int primary key, i1 tinyint default null, + i2 smallint default null, i3 int default null, i4 bigint default null, + vals string default null, valf float default null, vald double default null, + valb boolean default null) partition by hash (x) partitions 3 stored as kudu +---- RESULTS +==== +---- QUERY +insert into tbl_with_null_defaults (x) values (1); +---- RUNTIME_PROFILE +NumModifiedRows: 1 +NumRowErrors: 0 +---- LABELS +X, I1, I2, I3, I4, VALS, VALF, VALD, VALB +---- DML_RESULTS: tbl_with_null_defaults +1,NULL,NULL,NULL,NULL,'NULL',NULL,NULL,NULL +---- TYPES +INT,TINYINT,SMALLINT,INT,BIGINT,STRING,FLOAT,DOUBLE,BOOLEAN +====
