You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2019/04/07 19:45:22 UTC
[impala] 01/04: IMPALA-7640: RENAME on managed Kudu table should
rename Kudu table
This is an automated email from the ASF dual-hosted git repository.
tarmstrong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
commit 4057331fb8cb976ea11364c374183bab01d795da
Author: stakiar <ta...@gmail.com>
AuthorDate: Fri Jan 4 13:22:47 2019 -0600
IMPALA-7640: RENAME on managed Kudu table should rename Kudu table
`ALTER TABLE managed_kudu_tbl RENAME TO new_managed_kudu_tbl` will now
rename the underlying Kudu table from `managed_kudu_tbl` to
`new_managed_kudu_tbl`. This is only triggered for managed tables, for
external tables renames do not modify the underlying Kudu table.
Testing:
* Ran core tests
* Updated kudu_alter.test
Change-Id: I77e7583ce93cba8f6e743c4bedd9900ae1fae081
Reviewed-on: http://gerrit.cloudera.org:8080/12179
Reviewed-by: Thomas Marshall <tm...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
.../apache/impala/service/CatalogOpExecutor.java | 27 ++++++++++++++++++++++
.../queries/QueryTest/kudu_alter.test | 26 ++++++++++++++++++++-
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java b/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
index e0c5fe9..0f27510 100644
--- a/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
+++ b/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
@@ -165,6 +165,7 @@ import org.apache.impala.thrift.TUpdateCatalogResponse;
import org.apache.impala.util.CompressionUtil;
import org.apache.impala.util.FunctionUtils;
import org.apache.impala.util.HdfsCachingUtil;
+import org.apache.impala.util.KuduUtil;
import org.apache.impala.util.MetaStoreUtil;
import org.slf4j.Logger;
import org.apache.thrift.TException;
@@ -2526,6 +2527,13 @@ public class CatalogOpExecutor {
oldTbl.getMetaStoreTable().deepCopy();
msTbl.setDbName(newTableName.getDb());
msTbl.setTableName(newTableName.getTbl());
+
+ // If oldTbl is a managed Kudu table, rename the underlying Kudu table
+ if (oldTbl instanceof KuduTable && !Table.isExternalTable(msTbl)) {
+ Preconditions.checkState(KuduTable.isKuduTable(msTbl));
+ renameKuduTable((KuduTable) oldTbl, msTbl, newTableName);
+ }
+
try (MetaStoreClient msClient = catalog_.getMetaStoreClient()) {
msClient.getHiveClient().alter_table(tableName.getDb(), tableName.getTbl(), msTbl);
} catch (TException e) {
@@ -2554,6 +2562,25 @@ public class CatalogOpExecutor {
}
/**
+ * Renames the underlying Kudu table for the given Impala table. If the new Kudu
+ * table name is the same as the old Kudu table name, this method does nothing.
+ */
+ private void renameKuduTable(KuduTable oldTbl,
+ org.apache.hadoop.hive.metastore.api.Table oldMsTbl, TableName newTableName)
+ throws ImpalaRuntimeException {
+ String newKuduTableName = KuduUtil.getDefaultCreateKuduTableName(
+ newTableName.getDb(), newTableName.getTbl());
+
+ // If the name of the Kudu table has not changed, do nothing
+ if (oldTbl.getKuduTableName().equals(newKuduTableName)) return;
+
+ KuduCatalogOpExecutor.renameTable(oldTbl, newKuduTableName);
+
+ // Add the name of the new Kudu table to the HMS table parameters
+ oldMsTbl.getParameters().put(KuduTable.KEY_TABLE_NAME, newKuduTableName);
+ }
+
+ /**
* Changes the file format for the given table or partitions. This is a metadata only
* operation, existing table data will not be converted to the new format. Returns
* true if the file metadata to be reloaded.
diff --git a/testdata/workloads/functional-query/queries/QueryTest/kudu_alter.test b/testdata/workloads/functional-query/queries/QueryTest/kudu_alter.test
index 0bed123..801bad8 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/kudu_alter.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/kudu_alter.test
@@ -381,8 +381,10 @@ BIGINT
====
---- QUERY
# Create an external Kudu table pointing to an existing Kudu table
+# The Kudu table kudu_tbl_to_alter is used in order to validate that renaming
+# the managed Impala-Kudu table tbl_to_alter renames the underlying Kudu table
create external table external_tbl stored as kudu
- tblproperties('kudu.table_name'='impala::$DATABASE.tbl_to_alter');
+ tblproperties('kudu.table_name'='impala::$DATABASE.kudu_tbl_to_alter');
select count(*) from external_tbl
---- RESULTS
5
@@ -390,6 +392,14 @@ select count(*) from external_tbl
BIGINT
====
---- QUERY
+# Ensure that after renaming the Impala table that the old Kudu table no longer
+# exists
+create external table external_tbl_on_nonexistent_kudu_tbl stored as kudu
+ tblproperties('kudu.table_name'='impala::$DATABASE.tbl_to_alter');
+---- CATCH
+ImpalaRuntimeException: Table does not exist in Kudu: 'impala::$DATABASE.tbl_to_alter'
+====
+---- QUERY
# Insert an item into the table pointed by the external Kudu table
insert into kudu_tbl_to_alter (id, name, new_col1, new_col2)
values (7, 'test', 4, 400)
@@ -610,3 +620,17 @@ alter table multi_range_partition_cols add range partition ('b', 2) <= values <
---- CATCH
NonRecoverableException: New range partition conflicts with existing range partition: ("b", 2) <= VALUES < ("c", 1)
====
+---- QUERY
+# Check that renaming an external Impala-Kudu table does not rename the underlying Kudu
+# table; this test consists of this QUERY block as well as the next one
+alter table external_tbl rename to external_tbl_new;
+---- RESULTS
+'Renaming was successful.'
+====
+---- QUERY
+describe formatted external_tbl_new;
+---- RESULTS: VERIFY_IS_SUBSET
+'','kudu.table_name ','impala::$DATABASE.temp_kudu_table'
+---- TYPES
+STRING,STRING,STRING
+----