From 8cd530e3a2adcd036b390b46ce69f2d747a520b9 Mon Sep 17 00:00:00 2001 From: Xiaobing Zhou Date: Tue, 23 Sep 2014 18:10:39 -0700 Subject: [PATCH] HIVE-8169: Windows: alter table ..set location from hcatalog failed with NullPointerException --- .../cli/SemanticAnalysis/HCatSemanticAnalyzer.java | 3 +- .../queries/clientpositive/alter_table_location.q | 5 ++ .../clientpositive/alter_table_location.q.out | 55 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 ql/src/test/queries/clientpositive/alter_table_location.q create mode 100644 ql/src/test/results/clientpositive/alter_table_location.q.out diff --git a/hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/SemanticAnalysis/HCatSemanticAnalyzer.java b/hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/SemanticAnalysis/HCatSemanticAnalyzer.java index 6c54c05..de2b87c 100644 --- a/hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/SemanticAnalysis/HCatSemanticAnalyzer.java +++ b/hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/SemanticAnalysis/HCatSemanticAnalyzer.java @@ -23,6 +23,7 @@ import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.ql.exec.Task; +import org.apache.hadoop.hive.ql.exec.Utilities; import org.apache.hadoop.hive.ql.metadata.Hive; import org.apache.hadoop.hive.ql.metadata.HiveException; import org.apache.hadoop.hive.ql.metadata.Partition; @@ -359,7 +360,7 @@ protected void authorizeDDLWork(HiveSemanticAnalyzerHookContext cntxt, Hive hive AlterTableDesc alterTable = work.getAlterTblDesc(); if (alterTable != null) { Table table = hive.getTable(SessionState.get().getCurrentDatabase(), - alterTable.getOldName(), false); + Utilities.getDbTableName(alterTable.getOldName())[1], false); Partition part = null; if (alterTable.getPartSpec() != null) { diff --git a/ql/src/test/queries/clientpositive/alter_table_location.q b/ql/src/test/queries/clientpositive/alter_table_location.q new file mode 100644 index 0000000..94c3948 --- /dev/null +++ b/ql/src/test/queries/clientpositive/alter_table_location.q @@ -0,0 +1,5 @@ +drop table if exists hcat_altertable_16; +create table hcat_altertable_16(a int, b string) stored as textfile; +show table extended like hcat_altertable_16; +alter table hcat_altertable_16 set location 'file:${system:test.tmp.dir}/hcat_altertable_16'; +show table extended like hcat_altertable_16; diff --git a/ql/src/test/results/clientpositive/alter_table_location.q.out b/ql/src/test/results/clientpositive/alter_table_location.q.out new file mode 100644 index 0000000..167a936 --- /dev/null +++ b/ql/src/test/results/clientpositive/alter_table_location.q.out @@ -0,0 +1,55 @@ +PREHOOK: query: drop table if exists hcat_altertable_16 +PREHOOK: type: DROPTABLE +POSTHOOK: query: drop table if exists hcat_altertable_16 +POSTHOOK: type: DROPTABLE +PREHOOK: query: create table hcat_altertable_16(a int, b string) stored as textfile +PREHOOK: type: CREATETABLE +PREHOOK: Output: database:default +PREHOOK: Output: default@hcat_altertable_16 +POSTHOOK: query: create table hcat_altertable_16(a int, b string) stored as textfile +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: database:default +POSTHOOK: Output: default@hcat_altertable_16 +PREHOOK: query: show table extended like hcat_altertable_16 +PREHOOK: type: SHOW_TABLESTATUS +POSTHOOK: query: show table extended like hcat_altertable_16 +POSTHOOK: type: SHOW_TABLESTATUS +tableName:hcat_altertable_16 +#### A masked pattern was here #### +inputformat:org.apache.hadoop.mapred.TextInputFormat +outputformat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat +columns:struct columns { i32 a, string b} +partitioned:false +partitionColumns: +totalNumberFiles:0 +totalFileSize:0 +maxFileSize:0 +minFileSize:0 +#### A masked pattern was here #### + +#### A masked pattern was here #### +PREHOOK: type: ALTERTABLE_LOCATION +PREHOOK: Input: default@hcat_altertable_16 +PREHOOK: Output: default@hcat_altertable_16 +#### A masked pattern was here #### +POSTHOOK: type: ALTERTABLE_LOCATION +POSTHOOK: Input: default@hcat_altertable_16 +POSTHOOK: Output: default@hcat_altertable_16 +#### A masked pattern was here #### +PREHOOK: query: show table extended like hcat_altertable_16 +PREHOOK: type: SHOW_TABLESTATUS +POSTHOOK: query: show table extended like hcat_altertable_16 +POSTHOOK: type: SHOW_TABLESTATUS +tableName:hcat_altertable_16 +#### A masked pattern was here #### +inputformat:org.apache.hadoop.mapred.TextInputFormat +outputformat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat +columns:struct columns { i32 a, string b} +partitioned:false +partitionColumns: +totalNumberFiles:unknown +totalFileSize:unknown +maxFileSize:unknown +minFileSize:unknown +#### A masked pattern was here #### + -- 1.8.5.2 (Apple Git-48)