IMPALA-6571: NullPointerException in SHOW CREATE TABLE for HBase tables This patch fixes the NullPointerException in SHOW CREATE TABLE for HBase tables.
Testing: - Moved the content of back hbase-show-create-table.test to show-create-table.test - Ran show-create-table end-to-end tests Change-Id: Ibe018313168fac5dcbd80be9a8f28b71a2c0389b Reviewed-on: http://gerrit.cloudera.org:8080/9884 Reviewed-by: Alex Behm <alex.b...@cloudera.com> Tested-by: Impala Public Jenkins Project: http://git-wip-us.apache.org/repos/asf/impala/repo Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/09b58f6c Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/09b58f6c Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/09b58f6c Branch: refs/heads/2.x Commit: 09b58f6c8b24ae6b4fddab72466d5fc61c7c7ca8 Parents: 0a8cac2 Author: Fredy Wijaya <fwij...@cloudera.com> Authored: Mon Apr 2 09:19:36 2018 -0700 Committer: Impala Public Jenkins <impala-public-jenk...@gerrit.cloudera.org> Committed: Wed Apr 11 22:55:59 2018 +0000 ---------------------------------------------------------------------- .../org/apache/impala/analysis/ToSqlUtils.java | 11 +++++---- .../QueryTest/hbase-show-create-table.test | 24 -------------------- .../queries/QueryTest/show-create-table.test | 24 ++++++++++++++++++++ tests/metadata/test_show_create_table.py | 3 ++- 4 files changed, 33 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/impala/blob/09b58f6c/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java b/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java index 1940cde..9a164f0 100644 --- a/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java +++ b/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java @@ -45,6 +45,7 @@ import org.apache.impala.catalog.Function; import org.apache.impala.catalog.HBaseTable; import org.apache.impala.catalog.HdfsCompression; import org.apache.impala.catalog.HdfsFileFormat; +import org.apache.impala.catalog.HdfsTable; import org.apache.impala.catalog.KuduColumn; import org.apache.impala.catalog.KuduTable; import org.apache.impala.catalog.RowFormat; @@ -231,10 +232,8 @@ public class ToSqlUtils { } } RowFormat rowFormat = RowFormat.fromStorageDescriptor(msTable.getSd()); - HdfsFileFormat format = HdfsFileFormat.fromHdfsInputFormatClass( - msTable.getSd().getInputFormat()); - HdfsCompression compression = HdfsCompression.fromHdfsInputFormatClass( - msTable.getSd().getInputFormat()); + HdfsFileFormat format = null; + HdfsCompression compression = null; String location = isHbaseTable ? null : msTable.getSd().getLocation(); Map<String, String> serdeParameters = msTable.getSd().getSerdeInfo().getParameters(); @@ -270,6 +269,10 @@ public class ToSqlUtils { // We shouldn't output the columns for external tables colsSql = null; } + } else if (table instanceof HdfsTable) { + String inputFormat = msTable.getSd().getInputFormat(); + format = HdfsFileFormat.fromHdfsInputFormatClass(inputFormat); + compression = HdfsCompression.fromHdfsInputFormatClass(inputFormat); } HdfsUri tableLocation = location == null ? null : new HdfsUri(location); return getCreateTableSql(table.getDb().getName(), table.getName(), comment, colsSql, http://git-wip-us.apache.org/repos/asf/impala/blob/09b58f6c/testdata/workloads/functional-query/queries/QueryTest/hbase-show-create-table.test ---------------------------------------------------------------------- diff --git a/testdata/workloads/functional-query/queries/QueryTest/hbase-show-create-table.test b/testdata/workloads/functional-query/queries/QueryTest/hbase-show-create-table.test deleted file mode 100644 index 8062216..0000000 --- a/testdata/workloads/functional-query/queries/QueryTest/hbase-show-create-table.test +++ /dev/null @@ -1,24 +0,0 @@ -==== ----- QUERY -SHOW CREATE TABLE alltypes ----- RESULTS -CREATE EXTERNAL TABLE alltypes ( - id INT COMMENT 'Add a comment', - bigint_col BIGINT, - bool_col BOOLEAN, - date_string_col STRING, - double_col DOUBLE, - float_col FLOAT, - int_col INT, - month INT, - smallint_col SMALLINT, - string_col STRING, - timestamp_col TIMESTAMP, - tinyint_col TINYINT, - year INT -) -STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' -WITH SERDEPROPERTIES ('hbase.columns.mapping'=':key,d:bool_col,d:tinyint_col,d:smallint_col,d:int_col,d:bigint_col,d:float_col,d:double_col,d:date_string_col,d:string_col,d:timestamp_col,d:year,d:month', - 'serialization.format'='1') -TBLPROPERTIES ('hbase.table.name'='functional_hbase.alltypes', - 'storage_handler'='org.apache.hadoop.hive.hbase.HBaseStorageHandler') http://git-wip-us.apache.org/repos/asf/impala/blob/09b58f6c/testdata/workloads/functional-query/queries/QueryTest/show-create-table.test ---------------------------------------------------------------------- diff --git a/testdata/workloads/functional-query/queries/QueryTest/show-create-table.test b/testdata/workloads/functional-query/queries/QueryTest/show-create-table.test index 81b619b..db38984 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/show-create-table.test +++ b/testdata/workloads/functional-query/queries/QueryTest/show-create-table.test @@ -372,3 +372,27 @@ SORT BY (id) STORED AS TEXTFILE LOCATION '$$location_uri$$' ==== +---- QUERY +SHOW CREATE TABLE functional_hbase.alltypes +---- RESULTS +CREATE EXTERNAL TABLE functional_hbase.alltypes ( + id INT COMMENT 'Add a comment', + bigint_col BIGINT, + bool_col BOOLEAN, + date_string_col STRING, + double_col DOUBLE, + float_col FLOAT, + int_col INT, + month INT, + smallint_col SMALLINT, + string_col STRING, + timestamp_col TIMESTAMP, + tinyint_col TINYINT, + year INT +) +STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' +WITH SERDEPROPERTIES ('hbase.columns.mapping'=':key,d:bool_col,d:tinyint_col,d:smallint_col,d:int_col,d:bigint_col,d:float_col,d:double_col,d:date_string_col,d:string_col,d:timestamp_col,d:year,d:month', + 'serialization.format'='1') +TBLPROPERTIES ('hbase.table.name'='functional_hbase.alltypes', + 'storage_handler'='org.apache.hadoop.hive.hbase.HBaseStorageHandler') +==== \ No newline at end of file http://git-wip-us.apache.org/repos/asf/impala/blob/09b58f6c/tests/metadata/test_show_create_table.py ---------------------------------------------------------------------- diff --git a/tests/metadata/test_show_create_table.py b/tests/metadata/test_show_create_table.py index d0ce87f..00b63ef 100644 --- a/tests/metadata/test_show_create_table.py +++ b/tests/metadata/test_show_create_table.py @@ -34,7 +34,8 @@ class TestShowCreateTable(ImpalaTestSuite): # Properties to filter before comparing results FILTER_TBL_PROPERTIES = ["transient_lastDdlTime", "numFiles", "numPartitions", "numRows", "rawDataSize", "totalSize", "COLUMN_STATS_ACCURATE", - "STATS_GENERATED_VIA_STATS_TASK"] + "STATS_GENERATED_VIA_STATS_TASK", "last_modified_by", + "last_modified_time"] @classmethod def get_workload(self):