hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject svn commit: r1438896 - in /hive/trunk/ql/src: java/org/apache/hadoop/hive/ql/exec/ java/org/apache/hadoop/hive/ql/parse/ java/org/apache/hadoop/hive/ql/plan/ test/queries/clientpositive/ test/results/clientpositive/
Date Sat, 26 Jan 2013 14:00:28 GMT
Author: namit
Date: Sat Jan 26 14:00:28 2013
New Revision: 1438896

URL: http://svn.apache.org/viewvc?rev=1438896&view=rev
Log:
HIVE-3527 Allow CREATE TABLE LIKE command to take TBLPROPERTIES
(Kevin Wilfong via namit)


Added:
    hive/trunk/ql/src/test/queries/clientpositive/create_like_tbl_props.q
    hive/trunk/ql/src/test/results/clientpositive/create_like_tbl_props.q.out
Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/CreateTableLikeDesc.java

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java?rev=1438896&r1=1438895&r2=1438896&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java Sat Jan 26 14:00:28
2013
@@ -3748,6 +3748,10 @@ public class DDLTask extends Task<DDLWor
       String targetTableName = crtTbl.getTableName();
       tbl=db.newTable(targetTableName);
 
+      if (crtTbl.getTblProps() != null) {
+        tbl.getTTable().getParameters().putAll(crtTbl.getTblProps());
+      }
+
       tbl.setTableType(TableType.MANAGED_TABLE);
 
       if (crtTbl.isExternal()) {
@@ -3809,6 +3813,10 @@ public class DDLTask extends Task<DDLWor
         params.clear();
       }
 
+      if (crtTbl.getTblProps() != null) {
+        params.putAll(crtTbl.getTblProps());
+      }
+
       if (crtTbl.isExternal()) {
         tbl.setProperty("EXTERNAL", "TRUE");
         tbl.setTableType(TableType.EXTERNAL_TABLE);

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g?rev=1438896&r1=1438895&r2=1438896&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g Sat Jan 26 14:00:28 2013
@@ -485,6 +485,7 @@ createTableStatement
     : KW_CREATE (ext=KW_EXTERNAL)? KW_TABLE ifNotExists? name=tableName
       (  like=KW_LIKE likeName=tableName
          tableLocation?
+         tablePropertiesPrefixed?
        | (LPAREN columnNameTypeList RPAREN)?
          tableComment?
          tablePartition?

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java?rev=1438896&r1=1438895&r2=1438896&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java Sat Jan 26
14:00:28 2013
@@ -9101,9 +9101,11 @@ public class SemanticAnalyzer extends Ba
       break;
 
     case CTLT: // create table like <tbl_name>
+      tblProps = addDefaultProperties(tblProps);
+
       CreateTableLikeDesc crtTblLikeDesc = new CreateTableLikeDesc(tableName, isExt,
           storageFormat.inputFormat, storageFormat.outputFormat, location,
-          shared.serde, shared.serdeProps, ifNotExists, likeTableName);
+          shared.serde, shared.serdeProps, tblProps, ifNotExists, likeTableName);
       SessionState.get().setCommandType(HiveOperation.CREATETABLE);
       rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(),
           crtTblLikeDesc), conf));

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/CreateTableLikeDesc.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/CreateTableLikeDesc.java?rev=1438896&r1=1438895&r2=1438896&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/CreateTableLikeDesc.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/CreateTableLikeDesc.java Sat Jan
26 14:00:28 2013
@@ -35,6 +35,7 @@ public class CreateTableLikeDesc extends
   String defaultSerName;
   Map<String, String> defaultSerdeProps;
   String location;
+  Map<String, String> tblProps;
   boolean ifNotExists;
   String likeTableName;
 
@@ -43,8 +44,8 @@ public class CreateTableLikeDesc extends
 
   public CreateTableLikeDesc(String tableName, boolean isExternal,
       String defaultInputFormat, String defaultOutputFormat, String location,
-      String defaultSerName, Map<String, String> defaultSerdeProps, boolean ifNotExists,
-      String likeTableName) {
+      String defaultSerName, Map<String, String> defaultSerdeProps, Map<String,
String> tblProps,
+      boolean ifNotExists, String likeTableName) {
     this.tableName = tableName;
     this.isExternal = isExternal;
     this.defaultInputFormat=defaultInputFormat;
@@ -52,6 +53,7 @@ public class CreateTableLikeDesc extends
     this.defaultSerName=defaultSerName;
     this.defaultSerdeProps=defaultSerdeProps;
     this.location = location;
+    this.tblProps = tblProps;
     this.ifNotExists = ifNotExists;
     this.likeTableName = likeTableName;
   }
@@ -151,4 +153,19 @@ public class CreateTableLikeDesc extends
     this.likeTableName = likeTableName;
   }
 
+  /**
+   * @return the table properties
+   */
+  @Explain(displayName = "table properties")
+  public Map<String, String> getTblProps() {
+    return tblProps;
+  }
+
+  /**
+   * @param tblProps
+   *          the table properties to set
+   */
+  public void setTblProps(Map<String, String> tblProps) {
+    this.tblProps = tblProps;
+  }
 }

Added: hive/trunk/ql/src/test/queries/clientpositive/create_like_tbl_props.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/create_like_tbl_props.q?rev=1438896&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/create_like_tbl_props.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/create_like_tbl_props.q Sat Jan 26 14:00:28
2013
@@ -0,0 +1,35 @@
+-- Test that CREATE TABLE LIKE commands can take explicit table properties
+
+CREATE TABLE test_table LIKE src TBLPROPERTIES('key'='value');
+
+DESC FORMATTED test_table;
+
+set hive.table.parameters.default=key1=value1;
+
+--Test that CREATE TABLE LIKE commands can take default table properties
+
+CREATE TABLE test_table1 LIKE src;
+
+DESC FORMATTED test_table1;
+
+-- Test that CREATE TABLE LIKE commands can take default and explicit table properties
+
+CREATE TABLE test_table2 LIKE src TBLPROPERTIES('key2' = 'value2');
+
+DESC FORMATTED test_table2;
+
+set hive.ddl.createtablelike.properties.whitelist=key2;
+
+-- Test that properties inherited are overwritten by explicitly set ones
+
+CREATE TABLE test_table3 LIKE test_table2 TBLPROPERTIES('key2' = 'value3');
+
+DESC FORMATTED test_table3;
+
+--Test that CREATE TALBE LIKE on a view can take explicit table properties
+
+CREATE VIEW test_view (key, value) AS SELECT * FROM src;
+
+CREATE TABLE test_table4 LIKE test_view TBLPROPERTIES('key'='value');
+
+DESC FORMATTED test_table4;

Added: hive/trunk/ql/src/test/results/clientpositive/create_like_tbl_props.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/create_like_tbl_props.q.out?rev=1438896&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/create_like_tbl_props.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/create_like_tbl_props.q.out Sat Jan 26 14:00:28
2013
@@ -0,0 +1,205 @@
+PREHOOK: query: -- Test that CREATE TABLE LIKE commands can take explicit table properties
+
+CREATE TABLE test_table LIKE src TBLPROPERTIES('key'='value')
+PREHOOK: type: CREATETABLE
+POSTHOOK: query: -- Test that CREATE TABLE LIKE commands can take explicit table properties
+
+CREATE TABLE test_table LIKE src TBLPROPERTIES('key'='value')
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: default@test_table
+PREHOOK: query: DESC FORMATTED test_table
+PREHOOK: type: DESCTABLE
+POSTHOOK: query: DESC FORMATTED test_table
+POSTHOOK: type: DESCTABLE
+# col_name            	data_type           	comment             
+	 	 
+key                 	string              	default             
+value               	string              	default             
+	 	 
+# Detailed Table Information	 	 
+Database:           	default             	 
+#### A masked pattern was here ####
+Protect Mode:       	None                	 
+Retention:          	0                   	 
+#### A masked pattern was here ####
+Table Type:         	MANAGED_TABLE       	 
+Table Parameters:	 	 
+	key                 	value               
+#### A masked pattern was here ####
+	 	 
+# Storage Information	 	 
+SerDe Library:      	org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe	 
+InputFormat:        	org.apache.hadoop.mapred.TextInputFormat	 
+OutputFormat:       	org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat	 
+Compressed:         	No                  	 
+Num Buckets:        	-1                  	 
+Bucket Columns:     	[]                  	 
+Sort Columns:       	[]                  	 
+Storage Desc Params:	 	 
+	serialization.format	1                   
+PREHOOK: query: --Test that CREATE TABLE LIKE commands can take default table properties
+
+CREATE TABLE test_table1 LIKE src
+PREHOOK: type: CREATETABLE
+POSTHOOK: query: --Test that CREATE TABLE LIKE commands can take default table properties
+
+CREATE TABLE test_table1 LIKE src
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: default@test_table1
+PREHOOK: query: DESC FORMATTED test_table1
+PREHOOK: type: DESCTABLE
+POSTHOOK: query: DESC FORMATTED test_table1
+POSTHOOK: type: DESCTABLE
+# col_name            	data_type           	comment             
+	 	 
+key                 	string              	default             
+value               	string              	default             
+	 	 
+# Detailed Table Information	 	 
+Database:           	default             	 
+#### A masked pattern was here ####
+Protect Mode:       	None                	 
+Retention:          	0                   	 
+#### A masked pattern was here ####
+Table Type:         	MANAGED_TABLE       	 
+Table Parameters:	 	 
+	key1                	value1              
+#### A masked pattern was here ####
+	 	 
+# Storage Information	 	 
+SerDe Library:      	org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe	 
+InputFormat:        	org.apache.hadoop.mapred.TextInputFormat	 
+OutputFormat:       	org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat	 
+Compressed:         	No                  	 
+Num Buckets:        	-1                  	 
+Bucket Columns:     	[]                  	 
+Sort Columns:       	[]                  	 
+Storage Desc Params:	 	 
+	serialization.format	1                   
+PREHOOK: query: -- Test that CREATE TABLE LIKE commands can take default and explicit table
properties
+
+CREATE TABLE test_table2 LIKE src TBLPROPERTIES('key2' = 'value2')
+PREHOOK: type: CREATETABLE
+POSTHOOK: query: -- Test that CREATE TABLE LIKE commands can take default and explicit table
properties
+
+CREATE TABLE test_table2 LIKE src TBLPROPERTIES('key2' = 'value2')
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: default@test_table2
+PREHOOK: query: DESC FORMATTED test_table2
+PREHOOK: type: DESCTABLE
+POSTHOOK: query: DESC FORMATTED test_table2
+POSTHOOK: type: DESCTABLE
+# col_name            	data_type           	comment             
+	 	 
+key                 	string              	default             
+value               	string              	default             
+	 	 
+# Detailed Table Information	 	 
+Database:           	default             	 
+#### A masked pattern was here ####
+Protect Mode:       	None                	 
+Retention:          	0                   	 
+#### A masked pattern was here ####
+Table Type:         	MANAGED_TABLE       	 
+Table Parameters:	 	 
+	key1                	value1              
+	key2                	value2              
+#### A masked pattern was here ####
+	 	 
+# Storage Information	 	 
+SerDe Library:      	org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe	 
+InputFormat:        	org.apache.hadoop.mapred.TextInputFormat	 
+OutputFormat:       	org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat	 
+Compressed:         	No                  	 
+Num Buckets:        	-1                  	 
+Bucket Columns:     	[]                  	 
+Sort Columns:       	[]                  	 
+Storage Desc Params:	 	 
+	serialization.format	1                   
+PREHOOK: query: -- Test that properties inherited are overwritten by explicitly set ones
+
+CREATE TABLE test_table3 LIKE test_table2 TBLPROPERTIES('key2' = 'value3')
+PREHOOK: type: CREATETABLE
+POSTHOOK: query: -- Test that properties inherited are overwritten by explicitly set ones
+
+CREATE TABLE test_table3 LIKE test_table2 TBLPROPERTIES('key2' = 'value3')
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: default@test_table3
+PREHOOK: query: DESC FORMATTED test_table3
+PREHOOK: type: DESCTABLE
+POSTHOOK: query: DESC FORMATTED test_table3
+POSTHOOK: type: DESCTABLE
+# col_name            	data_type           	comment             
+	 	 
+key                 	string              	default             
+value               	string              	default             
+	 	 
+# Detailed Table Information	 	 
+Database:           	default             	 
+#### A masked pattern was here ####
+Protect Mode:       	None                	 
+Retention:          	0                   	 
+#### A masked pattern was here ####
+Table Type:         	MANAGED_TABLE       	 
+Table Parameters:	 	 
+	key1                	value1              
+	key2                	value3              
+#### A masked pattern was here ####
+	 	 
+# Storage Information	 	 
+SerDe Library:      	org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe	 
+InputFormat:        	org.apache.hadoop.mapred.TextInputFormat	 
+OutputFormat:       	org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat	 
+Compressed:         	No                  	 
+Num Buckets:        	-1                  	 
+Bucket Columns:     	[]                  	 
+Sort Columns:       	[]                  	 
+Storage Desc Params:	 	 
+	serialization.format	1                   
+PREHOOK: query: --Test that CREATE TALBE LIKE on a view can take explicit table properties
+
+CREATE VIEW test_view (key, value) AS SELECT * FROM src
+PREHOOK: type: CREATEVIEW
+#### A masked pattern was here ####
+POSTHOOK: query: --Test that CREATE TALBE LIKE on a view can take explicit table properties
+
+CREATE VIEW test_view (key, value) AS SELECT * FROM src
+POSTHOOK: type: CREATEVIEW
+POSTHOOK: Output: default@test_view
+#### A masked pattern was here ####
+PREHOOK: query: CREATE TABLE test_table4 LIKE test_view TBLPROPERTIES('key'='value')
+PREHOOK: type: CREATETABLE
+POSTHOOK: query: CREATE TABLE test_table4 LIKE test_view TBLPROPERTIES('key'='value')
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: default@test_table4
+PREHOOK: query: DESC FORMATTED test_table4
+PREHOOK: type: DESCTABLE
+POSTHOOK: query: DESC FORMATTED test_table4
+POSTHOOK: type: DESCTABLE
+# col_name            	data_type           	comment             
+	 	 
+key                 	string              	None                
+value               	string              	None                
+	 	 
+# Detailed Table Information	 	 
+Database:           	default             	 
+#### A masked pattern was here ####
+Protect Mode:       	None                	 
+Retention:          	0                   	 
+#### A masked pattern was here ####
+Table Type:         	MANAGED_TABLE       	 
+Table Parameters:	 	 
+	key                 	value               
+	key1                	value1              
+#### A masked pattern was here ####
+	 	 
+# Storage Information	 	 
+SerDe Library:      	org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe	 
+InputFormat:        	org.apache.hadoop.mapred.TextInputFormat	 
+OutputFormat:       	org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat	 
+Compressed:         	No                  	 
+Num Buckets:        	-1                  	 
+Bucket Columns:     	[]                  	 
+Sort Columns:       	[]                  	 
+Storage Desc Params:	 	 
+	serialization.format	1                   



Mime
View raw message