Repository: incubator-impala
Updated Branches:
  refs/heads/master 75980d891 -> 68f32e52b


IMPALA-5154: Handle 'unpartitioned' Kudu tables

The catalogd was hanging trying to load an unpartitioned
Kudu table created outside of Impala. This fixes an
assumption made in KuduTable.java that the list of
'partition by' expressions is not empty. Regardless, the
list on the thrift structure must be created because the
field is marked required.

Change-Id: I40926bf6ea46cfca518bba6d4ca13fb5b0de358d
Reviewed-on: http://gerrit.cloudera.org:8080/6560
Reviewed-by: Alex Behm <[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/58286bda
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/58286bda
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/58286bda

Branch: refs/heads/master
Commit: 58286bda7a62251f3841fa431013bdb009c6bfaf
Parents: 75980d8
Author: Matthew Jacobs <[email protected]>
Authored: Tue Apr 4 10:00:55 2017 -0700
Committer: Impala Public Jenkins <[email protected]>
Committed: Thu Apr 6 01:36:27 2017 +0000

----------------------------------------------------------------------
 .../org/apache/impala/catalog/KuduTable.java    |  3 ++
 tests/query_test/test_kudu.py                   | 32 ++++++++++++++++++++
 2 files changed, 35 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/58286bda/fe/src/main/java/org/apache/impala/catalog/KuduTable.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/catalog/KuduTable.java 
b/fe/src/main/java/org/apache/impala/catalog/KuduTable.java
index c58c665..5cf5fd1 100644
--- a/fe/src/main/java/org/apache/impala/catalog/KuduTable.java
+++ b/fe/src/main/java/org/apache/impala/catalog/KuduTable.java
@@ -356,6 +356,9 @@ public class KuduTable extends Table {
     tbl.setMaster_addresses(Lists.newArrayList(kuduMasters_.split(",")));
     tbl.setTable_name(kuduTableName_);
     Preconditions.checkNotNull(partitionBy_);
+    // IMPALA-5154: partitionBy_ may be empty if Kudu table created outside 
Impala,
+    // partition_by must be explicitly created because the field is required.
+    tbl.partition_by = Lists.newArrayList();
     for (KuduPartitionParam partitionParam: partitionBy_) {
       tbl.addToPartition_by(partitionParam.toThrift());
     }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/58286bda/tests/query_test/test_kudu.py
----------------------------------------------------------------------
diff --git a/tests/query_test/test_kudu.py b/tests/query_test/test_kudu.py
index 35152b8..8a210a8 100644
--- a/tests/query_test/test_kudu.py
+++ b/tests/query_test/test_kudu.py
@@ -477,6 +477,38 @@ class TestCreateExternalTable(KuduTestSuite):
       except Exception as e:
         assert "Table does not exist in Kudu: '%s'" % table_name in str(e)
 
+  def test_table_without_partitioning(self, cursor, kudu_client, 
unique_database):
+    """Test a Kudu table created without partitioning (i.e. equivalent to a 
single
+       unbounded partition). It is not possible to create such a table in 
Impala, but
+       it can be created directly in Kudu and then loaded as an external table.
+       Regression test for IMPALA-5154."""
+    schema_builder = SchemaBuilder()
+    column_spec = schema_builder.add_column("id", INT64)
+    column_spec.nullable(False)
+    schema_builder.set_primary_keys(["id"])
+    schema = schema_builder.build()
+    partitioning = Partitioning().set_range_partition_columns([])
+    name = "%s.one_big_unbounded_partition" % unique_database
+
+    try:
+      kudu_client.create_table(name, schema, partitioning=partitioning)
+      kudu_table = kudu_client.table(name)
+
+      props = "TBLPROPERTIES('kudu.table_name'='%s')" % name
+      cursor.execute("CREATE EXTERNAL TABLE %s STORED AS KUDU %s" % (name, 
props))
+      with self.drop_impala_table_after_context(cursor, name):
+        cursor.execute("INSERT INTO %s VALUES (1), (2), (3)" % name)
+        cursor.execute("SELECT COUNT(*) FROM %s" % name)
+        assert cursor.fetchall() == [(3, )]
+        try:
+          cursor.execute("SHOW RANGE PARTITIONS %s" % name)
+          assert False
+        except Exception as e:
+          assert "AnalysisException: SHOW RANGE PARTITIONS requested but table 
does "\
+              "not have range partitions" in str(e)
+    finally:
+      if kudu_client.table_exists(name):
+        kudu_client.delete_table(name)
 
 class TestShowCreateTable(KuduTestSuite):
 

Reply via email to