Index: ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (revision 1438781) +++ ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (working copy) @@ -3748,6 +3748,10 @@ 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 @@ params.clear(); } + if (crtTbl.getTblProps() != null) { + params.putAll(crtTbl.getTblProps()); + } + if (crtTbl.isExternal()) { tbl.setProperty("EXTERNAL", "TRUE"); tbl.setTableType(TableType.EXTERNAL_TABLE); Index: ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (revision 1438781) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (working copy) @@ -485,6 +485,7 @@ : KW_CREATE (ext=KW_EXTERNAL)? KW_TABLE ifNotExists? name=tableName ( like=KW_LIKE likeName=tableName tableLocation? + tablePropertiesPrefixed? | (LPAREN columnNameTypeList RPAREN)? tableComment? tablePartition? Index: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (revision 1438781) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (working copy) @@ -9101,9 +9101,11 @@ break; case CTLT: // create table like + 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)); Index: ql/src/java/org/apache/hadoop/hive/ql/plan/CreateTableLikeDesc.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/plan/CreateTableLikeDesc.java (revision 1438781) +++ ql/src/java/org/apache/hadoop/hive/ql/plan/CreateTableLikeDesc.java (working copy) @@ -35,6 +35,7 @@ String defaultSerName; Map defaultSerdeProps; String location; + Map tblProps; boolean ifNotExists; String likeTableName; @@ -43,8 +44,8 @@ public CreateTableLikeDesc(String tableName, boolean isExternal, String defaultInputFormat, String defaultOutputFormat, String location, - String defaultSerName, Map defaultSerdeProps, boolean ifNotExists, - String likeTableName) { + String defaultSerName, Map defaultSerdeProps, Map tblProps, + boolean ifNotExists, String likeTableName) { this.tableName = tableName; this.isExternal = isExternal; this.defaultInputFormat=defaultInputFormat; @@ -52,6 +53,7 @@ this.defaultSerName=defaultSerName; this.defaultSerdeProps=defaultSerdeProps; this.location = location; + this.tblProps = tblProps; this.ifNotExists = ifNotExists; this.likeTableName = likeTableName; } @@ -151,4 +153,19 @@ this.likeTableName = likeTableName; } + /** + * @return the table properties + */ + @Explain(displayName = "table properties") + public Map getTblProps() { + return tblProps; + } + + /** + * @param tblProps + * the table properties to set + */ + public void setTblProps(Map tblProps) { + this.tblProps = tblProps; + } } Index: ql/src/test/queries/clientpositive/create_like_tbl_props.q =================================================================== --- ql/src/test/queries/clientpositive/create_like_tbl_props.q (revision 0) +++ ql/src/test/queries/clientpositive/create_like_tbl_props.q (working copy) @@ -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; Index: ql/src/test/results/clientpositive/create_like_tbl_props.q.out =================================================================== --- ql/src/test/results/clientpositive/create_like_tbl_props.q.out (revision 0) +++ ql/src/test/results/clientpositive/create_like_tbl_props.q.out (working copy) @@ -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