hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vihan...@apache.org
Subject hive git commit: HIVE-17764 : alter view fails when hive.metastore.disallow.incompatible.col.type.changes set to true (Janaki Lahorani, reviewed by Andrew Sherman and Vihang Karajgaonkar)
Date Wed, 25 Oct 2017 01:42:06 GMT
Repository: hive
Updated Branches:
  refs/heads/master 70c7f1c6e -> 84950cfa6


HIVE-17764 : alter view fails when hive.metastore.disallow.incompatible.col.type.changes set
to true (Janaki Lahorani, reviewed by Andrew Sherman and Vihang Karajgaonkar)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/84950cfa
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/84950cfa
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/84950cfa

Branch: refs/heads/master
Commit: 84950cfa6d32aa6d1c04e7c4e5d84f4bc3c11c3d
Parents: 70c7f1c
Author: Vihang Karajgaonkar <vihang@cloudera.com>
Authored: Tue Oct 24 18:33:54 2017 -0700
Committer: Vihang Karajgaonkar <vihang@cloudera.com>
Committed: Tue Oct 24 18:34:00 2017 -0700

----------------------------------------------------------------------
 .../hadoop/hive/metastore/HiveAlterHandler.java |   6 +-
 .../clientpositive/alter_view_col_type.q        |  16 ++
 .../clientpositive/alter_view_col_type.q.out    | 167 +++++++++++++++++++
 3 files changed, 188 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/84950cfa/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
----------------------------------------------------------------------
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
index 65551ad..70d33ff 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
@@ -154,9 +154,13 @@ public class HiveAlterHandler implements AlterHandler {
         isPartitionedTable = true;
       }
 
+      // Views derive the column type from the base table definition.  So the view definition
+      // can be altered to change the column types.  The column type compatibility checks
should
+      // be done only for non-views.
       if (HiveConf.getBoolVar(hiveConf,
             HiveConf.ConfVars.METASTORE_DISALLOW_INCOMPATIBLE_COL_TYPE_CHANGES,
-            false)) {
+            false) &&
+          !oldt.getTableType().equals(TableType.VIRTUAL_VIEW.toString())) {
         // Throws InvalidOperationException if the new column types are not
         // compatible with the current column types.
         checkColTypeChangeCompatible(oldt.getSd().getCols(), newt.getSd().getCols());

http://git-wip-us.apache.org/repos/asf/hive/blob/84950cfa/ql/src/test/queries/clientpositive/alter_view_col_type.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientpositive/alter_view_col_type.q b/ql/src/test/queries/clientpositive/alter_view_col_type.q
new file mode 100644
index 0000000..5f5f414
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/alter_view_col_type.q
@@ -0,0 +1,16 @@
+create table at1 (c1 int, c2 varchar(1), c3 varchar(10));
+
+insert into at1 values (1, 'a', 'one');
+insert into at1 values (2, 'b', 'two');
+insert into at1 values (3, 'c', 'three');
+insert into at1 values (4, 'd', 'four');
+insert into at1 values (5, 'e', 'five');
+
+create view av1 as select c1, c2 from at1;
+DESCRIBE FORMATTED av1;
+select * from av1;
+
+alter view av1 as select c2, c3 from at1;
+DESCRIBE FORMATTED av1;
+select * from av1;
+

http://git-wip-us.apache.org/repos/asf/hive/blob/84950cfa/ql/src/test/results/clientpositive/alter_view_col_type.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/alter_view_col_type.q.out b/ql/src/test/results/clientpositive/alter_view_col_type.q.out
new file mode 100644
index 0000000..8ac9437
--- /dev/null
+++ b/ql/src/test/results/clientpositive/alter_view_col_type.q.out
@@ -0,0 +1,167 @@
+PREHOOK: query: create table at1 (c1 int, c2 varchar(1), c3 varchar(10))
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@at1
+POSTHOOK: query: create table at1 (c1 int, c2 varchar(1), c3 varchar(10))
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@at1
+PREHOOK: query: insert into at1 values (1, 'a', 'one')
+PREHOOK: type: QUERY
+PREHOOK: Output: default@at1
+POSTHOOK: query: insert into at1 values (1, 'a', 'one')
+POSTHOOK: type: QUERY
+POSTHOOK: Output: default@at1
+POSTHOOK: Lineage: at1.c1 EXPRESSION [(values__tmp__table__1)values__tmp__table__1.FieldSchema(name:tmp_values_col1,
type:string, comment:), ]
+POSTHOOK: Lineage: at1.c2 EXPRESSION [(values__tmp__table__1)values__tmp__table__1.FieldSchema(name:tmp_values_col2,
type:string, comment:), ]
+POSTHOOK: Lineage: at1.c3 EXPRESSION [(values__tmp__table__1)values__tmp__table__1.FieldSchema(name:tmp_values_col3,
type:string, comment:), ]
+PREHOOK: query: insert into at1 values (2, 'b', 'two')
+PREHOOK: type: QUERY
+PREHOOK: Output: default@at1
+POSTHOOK: query: insert into at1 values (2, 'b', 'two')
+POSTHOOK: type: QUERY
+POSTHOOK: Output: default@at1
+POSTHOOK: Lineage: at1.c1 EXPRESSION [(values__tmp__table__2)values__tmp__table__2.FieldSchema(name:tmp_values_col1,
type:string, comment:), ]
+POSTHOOK: Lineage: at1.c2 EXPRESSION [(values__tmp__table__2)values__tmp__table__2.FieldSchema(name:tmp_values_col2,
type:string, comment:), ]
+POSTHOOK: Lineage: at1.c3 EXPRESSION [(values__tmp__table__2)values__tmp__table__2.FieldSchema(name:tmp_values_col3,
type:string, comment:), ]
+PREHOOK: query: insert into at1 values (3, 'c', 'three')
+PREHOOK: type: QUERY
+PREHOOK: Output: default@at1
+POSTHOOK: query: insert into at1 values (3, 'c', 'three')
+POSTHOOK: type: QUERY
+POSTHOOK: Output: default@at1
+POSTHOOK: Lineage: at1.c1 EXPRESSION [(values__tmp__table__3)values__tmp__table__3.FieldSchema(name:tmp_values_col1,
type:string, comment:), ]
+POSTHOOK: Lineage: at1.c2 EXPRESSION [(values__tmp__table__3)values__tmp__table__3.FieldSchema(name:tmp_values_col2,
type:string, comment:), ]
+POSTHOOK: Lineage: at1.c3 EXPRESSION [(values__tmp__table__3)values__tmp__table__3.FieldSchema(name:tmp_values_col3,
type:string, comment:), ]
+PREHOOK: query: insert into at1 values (4, 'd', 'four')
+PREHOOK: type: QUERY
+PREHOOK: Output: default@at1
+POSTHOOK: query: insert into at1 values (4, 'd', 'four')
+POSTHOOK: type: QUERY
+POSTHOOK: Output: default@at1
+POSTHOOK: Lineage: at1.c1 EXPRESSION [(values__tmp__table__4)values__tmp__table__4.FieldSchema(name:tmp_values_col1,
type:string, comment:), ]
+POSTHOOK: Lineage: at1.c2 EXPRESSION [(values__tmp__table__4)values__tmp__table__4.FieldSchema(name:tmp_values_col2,
type:string, comment:), ]
+POSTHOOK: Lineage: at1.c3 EXPRESSION [(values__tmp__table__4)values__tmp__table__4.FieldSchema(name:tmp_values_col3,
type:string, comment:), ]
+PREHOOK: query: insert into at1 values (5, 'e', 'five')
+PREHOOK: type: QUERY
+PREHOOK: Output: default@at1
+POSTHOOK: query: insert into at1 values (5, 'e', 'five')
+POSTHOOK: type: QUERY
+POSTHOOK: Output: default@at1
+POSTHOOK: Lineage: at1.c1 EXPRESSION [(values__tmp__table__5)values__tmp__table__5.FieldSchema(name:tmp_values_col1,
type:string, comment:), ]
+POSTHOOK: Lineage: at1.c2 EXPRESSION [(values__tmp__table__5)values__tmp__table__5.FieldSchema(name:tmp_values_col2,
type:string, comment:), ]
+POSTHOOK: Lineage: at1.c3 EXPRESSION [(values__tmp__table__5)values__tmp__table__5.FieldSchema(name:tmp_values_col3,
type:string, comment:), ]
+PREHOOK: query: create view av1 as select c1, c2 from at1
+PREHOOK: type: CREATEVIEW
+PREHOOK: Input: default@at1
+PREHOOK: Output: database:default
+PREHOOK: Output: default@av1
+POSTHOOK: query: create view av1 as select c1, c2 from at1
+POSTHOOK: type: CREATEVIEW
+POSTHOOK: Input: default@at1
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@av1
+POSTHOOK: Lineage: av1.c1 SIMPLE [(at1)at1.FieldSchema(name:c1, type:int, comment:null),
]
+POSTHOOK: Lineage: av1.c2 SIMPLE [(at1)at1.FieldSchema(name:c2, type:varchar(1), comment:null),
]
+PREHOOK: query: DESCRIBE FORMATTED av1
+PREHOOK: type: DESCTABLE
+PREHOOK: Input: default@av1
+POSTHOOK: query: DESCRIBE FORMATTED av1
+POSTHOOK: type: DESCTABLE
+POSTHOOK: Input: default@av1
+# col_name            	data_type           	comment             
+c1                  	int                 	                    
+c2                  	varchar(1)          	                    
+	 	 
+# Detailed Table Information	 	 
+Database:           	default             	 
+#### A masked pattern was here ####
+Retention:          	0                   	 
+Table Type:         	VIRTUAL_VIEW        	 
+Table Parameters:	 	 
+#### A masked pattern was here ####
+	 	 
+# Storage Information	 	 
+SerDe Library:      	null                	 
+InputFormat:        	org.apache.hadoop.mapred.TextInputFormat	 
+OutputFormat:       	org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat	 
+Compressed:         	No                  	 
+Num Buckets:        	-1                  	 
+Bucket Columns:     	[]                  	 
+Sort Columns:       	[]                  	 
+	 	 
+# View Information	 	 
+View Original Text: 	select c1, c2 from at1	 
+View Expanded Text: 	select `at1`.`c1`, `at1`.`c2` from `default`.`at1`	 
+View Rewrite Enabled:	No                  	 
+PREHOOK: query: select * from av1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@at1
+PREHOOK: Input: default@av1
+#### A masked pattern was here ####
+POSTHOOK: query: select * from av1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@at1
+POSTHOOK: Input: default@av1
+#### A masked pattern was here ####
+1	a
+2	b
+3	c
+4	d
+5	e
+PREHOOK: query: alter view av1 as select c2, c3 from at1
+PREHOOK: type: CREATEVIEW
+PREHOOK: Input: default@at1
+PREHOOK: Output: database:default
+PREHOOK: Output: default@av1
+POSTHOOK: query: alter view av1 as select c2, c3 from at1
+POSTHOOK: type: CREATEVIEW
+POSTHOOK: Input: default@at1
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@av1
+PREHOOK: query: DESCRIBE FORMATTED av1
+PREHOOK: type: DESCTABLE
+PREHOOK: Input: default@av1
+POSTHOOK: query: DESCRIBE FORMATTED av1
+POSTHOOK: type: DESCTABLE
+POSTHOOK: Input: default@av1
+# col_name            	data_type           	comment             
+c2                  	varchar(1)          	                    
+c3                  	varchar(10)         	                    
+	 	 
+# Detailed Table Information	 	 
+Database:           	default             	 
+#### A masked pattern was here ####
+Retention:          	0                   	 
+Table Type:         	VIRTUAL_VIEW        	 
+Table Parameters:	 	 
+#### A masked pattern was here ####
+	 	 
+# Storage Information	 	 
+SerDe Library:      	null                	 
+InputFormat:        	org.apache.hadoop.mapred.TextInputFormat	 
+OutputFormat:       	org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat	 
+Compressed:         	No                  	 
+Num Buckets:        	-1                  	 
+Bucket Columns:     	[]                  	 
+Sort Columns:       	[]                  	 
+	 	 
+# View Information	 	 
+View Original Text: 	select c2, c3 from at1	 
+View Expanded Text: 	select `at1`.`c2`, `at1`.`c3` from `default`.`at1`	 
+View Rewrite Enabled:	No                  	 
+PREHOOK: query: select * from av1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@at1
+PREHOOK: Input: default@av1
+#### A masked pattern was here ####
+POSTHOOK: query: select * from av1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@at1
+POSTHOOK: Input: default@av1
+#### A masked pattern was here ####
+a	one
+b	two
+c	three
+d	four
+e	five


Mime
View raw message