diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java index ba8cdd344ddb246f4b0819bb76298d4732ad240f..f0e776e2670f70a1243317a2e7addbffa64b0a29 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java @@ -2723,7 +2723,6 @@ private void analyzeAlterTablePartColType(String[] qualified, ASTNode ast) // Alter table ... partition column ( column newtype) only takes one column at a time. // It must have a column name followed with type. ASTNode colAst = (ASTNode) ast.getChild(0); - assert(colAst.getChildCount() == 2); FieldSchema newCol = new FieldSchema(); @@ -2735,6 +2734,10 @@ private void analyzeAlterTablePartColType(String[] qualified, ASTNode ast) ASTNode typeChild = (ASTNode) (colAst.getChild(1)); newCol.setType(getTypeStringFromAST(typeChild)); + if (colAst.getChildCount() == 3) { + newCol.setComment(unescapeSQLString(colAst.getChild(2).getText())); + } + // check if column is defined or not boolean fFoundColumn = false; for( FieldSchema col : tab.getTTable().getPartitionKeys()) { diff --git a/ql/src/test/queries/clientpositive/alter_partition_change_col.q b/ql/src/test/queries/clientpositive/alter_partition_change_col.q index 4451ef3f993c17a1ab1b1b7a6abd025be2abfc4f..6861ca2bbf681267412c03f2f7f76a422cab3d72 100644 --- a/ql/src/test/queries/clientpositive/alter_partition_change_col.q +++ b/ql/src/test/queries/clientpositive/alter_partition_change_col.q @@ -6,7 +6,7 @@ SET hive.exec.dynamic.partition.mode = nonstrict; create table alter_partition_change_col0 (c1 string, c2 string); load data local inpath '../../data/files/dec.txt' overwrite into table alter_partition_change_col0; -create table alter_partition_change_col1 (c1 string, c2 string) partitioned by (p1 string, p2 string); +create table alter_partition_change_col1 (c1 string, c2 string) partitioned by (p1 string comment 'Column p1', p2 string comment 'Column p2'); insert overwrite table alter_partition_change_col1 partition (p1, p2) select c1, c2, 'abc', '123' from alter_partition_change_col0 @@ -31,6 +31,10 @@ describe alter_partition_change_col1 partition (p1='abc', p2='123'); select * from alter_partition_change_col1 where p1='abc'; select * from alter_partition_change_col1 where p1='__HIVE_DEFAULT_PARTITION__'; +-- change the comment on a partition column without changing type or renaming it +alter table alter_partition_change_col1 partition column (p1 string comment 'Changed comment for p1'); +describe alter_partition_change_col1; + -- now change the column type of the existing partition alter table alter_partition_change_col1 partition (p1='abc', p2='123') change c2 c2 decimal(14,4); describe alter_partition_change_col1 partition (p1='abc', p2='123'); diff --git a/ql/src/test/results/clientpositive/alter_partition_change_col.q.out b/ql/src/test/results/clientpositive/alter_partition_change_col.q.out index 50520aa2935250b5f4c9d5e5a2dd81f6a6ac3179..5eb5932d62a8b04e34daf1ad00a56edd35bb8fb1 100644 --- a/ql/src/test/results/clientpositive/alter_partition_change_col.q.out +++ b/ql/src/test/results/clientpositive/alter_partition_change_col.q.out @@ -18,11 +18,11 @@ POSTHOOK: query: load data local inpath '../../data/files/dec.txt' overwrite int POSTHOOK: type: LOAD #### A masked pattern was here #### POSTHOOK: Output: default@alter_partition_change_col0 -PREHOOK: query: create table alter_partition_change_col1 (c1 string, c2 string) partitioned by (p1 string, p2 string) +PREHOOK: query: create table alter_partition_change_col1 (c1 string, c2 string) partitioned by (p1 string comment 'Column p1', p2 string comment 'Column p2') PREHOOK: type: CREATETABLE PREHOOK: Output: database:default PREHOOK: Output: default@alter_partition_change_col1 -POSTHOOK: query: create table alter_partition_change_col1 (c1 string, c2 string) partitioned by (p1 string, p2 string) +POSTHOOK: query: create table alter_partition_change_col1 (c1 string, c2 string) partitioned by (p1 string comment 'Column p1', p2 string comment 'Column p2') POSTHOOK: type: CREATETABLE POSTHOOK: Output: database:default POSTHOOK: Output: default@alter_partition_change_col1 @@ -179,14 +179,14 @@ POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@alter_partition_change_col1 c1 string c2 decimal(14,4) -p1 string -p2 string +p1 string Column p1 +p2 string Column p2 # Partition Information # col_name data_type comment -p1 string -p2 string +p1 string Column p1 +p2 string Column p2 PREHOOK: query: describe alter_partition_change_col1 partition (p1='abc', p2='123') PREHOOK: type: DESCTABLE PREHOOK: Input: default@alter_partition_change_col1 @@ -195,14 +195,14 @@ POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@alter_partition_change_col1 c1 string c2 decimal(10,0) -p1 string -p2 string +p1 string Column p1 +p2 string Column p2 # Partition Information # col_name data_type comment -p1 string -p2 string +p1 string Column p1 +p2 string Column p2 PREHOOK: query: select * from alter_partition_change_col1 where p1='abc' PREHOOK: type: QUERY PREHOOK: Input: default@alter_partition_change_col1 @@ -243,6 +243,31 @@ Snow 56 __HIVE_DEFAULT_PARTITION__ 123 Tom -12 __HIVE_DEFAULT_PARTITION__ 123 Tom 19 __HIVE_DEFAULT_PARTITION__ 123 Tom 235 __HIVE_DEFAULT_PARTITION__ 123 +PREHOOK: query: -- change the comment on a partition column without changing type or renaming it +alter table alter_partition_change_col1 partition column (p1 string comment 'Changed comment for p1') +PREHOOK: type: ALTERTABLE_PARTCOLTYPE +PREHOOK: Input: default@alter_partition_change_col1 +POSTHOOK: query: -- change the comment on a partition column without changing type or renaming it +alter table alter_partition_change_col1 partition column (p1 string comment 'Changed comment for p1') +POSTHOOK: type: ALTERTABLE_PARTCOLTYPE +POSTHOOK: Input: default@alter_partition_change_col1 +POSTHOOK: Output: default@alter_partition_change_col1 +PREHOOK: query: describe alter_partition_change_col1 +PREHOOK: type: DESCTABLE +PREHOOK: Input: default@alter_partition_change_col1 +POSTHOOK: query: describe alter_partition_change_col1 +POSTHOOK: type: DESCTABLE +POSTHOOK: Input: default@alter_partition_change_col1 +c1 string +c2 decimal(14,4) +p1 string Changed comment for p1 +p2 string Column p2 + +# Partition Information +# col_name data_type comment + +p1 string Changed comment for p1 +p2 string Column p2 PREHOOK: query: -- now change the column type of the existing partition alter table alter_partition_change_col1 partition (p1='abc', p2='123') change c2 c2 decimal(14,4) PREHOOK: type: ALTERTABLE_RENAMECOL @@ -262,14 +287,14 @@ POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@alter_partition_change_col1 c1 string c2 decimal(14,4) -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 # Partition Information # col_name data_type comment -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 PREHOOK: query: select * from alter_partition_change_col1 where p1='abc' PREHOOK: type: QUERY PREHOOK: Input: default@alter_partition_change_col1 @@ -329,14 +354,14 @@ POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@alter_partition_change_col1 c1 string c2 decimal(14,4) -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 # Partition Information # col_name data_type comment -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 PREHOOK: query: select * from alter_partition_change_col1 where p1='abc' PREHOOK: type: QUERY PREHOOK: Input: default@alter_partition_change_col1 @@ -396,14 +421,14 @@ POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@alter_partition_change_col1 c1 string c2 decimal(14,4) -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 # Partition Information # col_name data_type comment -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 PREHOOK: query: describe alter_partition_change_col1 partition (p1='abc', p2='123') PREHOOK: type: DESCTABLE PREHOOK: Input: default@alter_partition_change_col1 @@ -411,14 +436,14 @@ POSTHOOK: query: describe alter_partition_change_col1 partition (p1='abc', p2='1 POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@alter_partition_change_col1 c1 string -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 # Partition Information # col_name data_type comment -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 PREHOOK: query: select * from alter_partition_change_col1 where p1='abc' PREHOOK: type: QUERY PREHOOK: Input: default@alter_partition_change_col1 @@ -474,14 +499,14 @@ POSTHOOK: query: describe alter_partition_change_col1 POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@alter_partition_change_col1 c1 string -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 # Partition Information # col_name data_type comment -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 PREHOOK: query: select * from alter_partition_change_col1 where p1='abc' PREHOOK: type: QUERY PREHOOK: Input: default@alter_partition_change_col1 @@ -540,14 +565,14 @@ POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@alter_partition_change_col1 c1 string c2 decimal(14,4) -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 # Partition Information # col_name data_type comment -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 PREHOOK: query: describe alter_partition_change_col1 partition (p1='abc', p2='123') PREHOOK: type: DESCTABLE PREHOOK: Input: default@alter_partition_change_col1 @@ -555,14 +580,14 @@ POSTHOOK: query: describe alter_partition_change_col1 partition (p1='abc', p2='1 POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@alter_partition_change_col1 c1 string -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 # Partition Information # col_name data_type comment -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 PREHOOK: query: select * from alter_partition_change_col1 where p1='abc' PREHOOK: type: QUERY PREHOOK: Input: default@alter_partition_change_col1 @@ -620,14 +645,14 @@ POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@alter_partition_change_col1 c1 string c2 decimal(14,4) -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 # Partition Information # col_name data_type comment -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 PREHOOK: query: select * from alter_partition_change_col1 where p1='abc' PREHOOK: type: QUERY PREHOOK: Input: default@alter_partition_change_col1 @@ -690,14 +715,14 @@ POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@alter_partition_change_col1 c1 string c2 decimal(10,0) -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 # Partition Information # col_name data_type comment -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 PREHOOK: query: describe alter_partition_change_col1 partition (p1='__HIVE_DEFAULT_PARTITION__', p2='123') PREHOOK: type: DESCTABLE PREHOOK: Input: default@alter_partition_change_col1 @@ -706,14 +731,14 @@ POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@alter_partition_change_col1 c1 string c2 decimal(10,0) -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 # Partition Information # col_name data_type comment -p1 string -p2 string +p1 string Changed comment for p1 +p2 string Column p2 PREHOOK: query: select * from alter_partition_change_col1 where p1='abc' PREHOOK: type: QUERY PREHOOK: Input: default@alter_partition_change_col1