Index: ql/src/test/results/clientpositive/alter_table_serde.q.out =================================================================== --- ql/src/test/results/clientpositive/alter_table_serde.q.out (revision 0) +++ ql/src/test/results/clientpositive/alter_table_serde.q.out (revision 0) @@ -0,0 +1,168 @@ +PREHOOK: query: -- test table +create table test_table (id int, query string, name string) +PREHOOK: type: CREATETABLE +POSTHOOK: query: -- test table +create table test_table (id int, query string, name string) +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: default@test_table +PREHOOK: query: describe extended test_table +PREHOOK: type: DESCTABLE +POSTHOOK: query: describe extended test_table +POSTHOOK: type: DESCTABLE +id int +query string +name string + +Detailed Table Information Table(tableName:test_table, dbName:default, owner:xiaol, createTime:1317799666, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:id, type:int, comment:null), FieldSchema(name:query, type:string, comment:null), FieldSchema(name:name, type:string, comment:null)], location:pfile:/Users/xiaol/Tools/hive-trunk/build/ql/test/data/warehouse/test_table, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{transient_lastDdlTime=1317799666}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE) +PREHOOK: query: alter table test_table set serde 'org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe' +PREHOOK: type: ALTERTABLE_SERIALIZER +PREHOOK: Input: default@test_table +PREHOOK: Output: default@test_table +POSTHOOK: query: alter table test_table set serde 'org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe' +POSTHOOK: type: ALTERTABLE_SERIALIZER +POSTHOOK: Input: default@test_table +POSTHOOK: Output: default@test_table +PREHOOK: query: describe extended test_table +PREHOOK: type: DESCTABLE +POSTHOOK: query: describe extended test_table +POSTHOOK: type: DESCTABLE +id int from deserializer +query string from deserializer +name string from deserializer + +Detailed Table Information Table(tableName:test_table, dbName:default, owner:xiaol, createTime:1317799666, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:id, type:int, comment:from deserializer), FieldSchema(name:query, type:string, comment:from deserializer), FieldSchema(name:name, type:string, comment:from deserializer)], location:pfile:/Users/xiaol/Tools/hive-trunk/build/ql/test/data/warehouse/test_table, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{last_modified_by=xiaol, last_modified_time=1317799666, transient_lastDdlTime=1317799666}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE) +PREHOOK: query: alter table test_table set serdeproperties ('field.delim' = ',') +PREHOOK: type: ALTERTABLE_SERDEPROPERTIES +PREHOOK: Input: default@test_table +PREHOOK: Output: default@test_table +POSTHOOK: query: alter table test_table set serdeproperties ('field.delim' = ',') +POSTHOOK: type: ALTERTABLE_SERDEPROPERTIES +POSTHOOK: Input: default@test_table +POSTHOOK: Output: default@test_table +PREHOOK: query: describe extended test_table +PREHOOK: type: DESCTABLE +POSTHOOK: query: describe extended test_table +POSTHOOK: type: DESCTABLE +id int from deserializer +query string from deserializer +name string from deserializer + +Detailed Table Information Table(tableName:test_table, dbName:default, owner:xiaol, createTime:1317799666, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:id, type:int, comment:from deserializer), FieldSchema(name:query, type:string, comment:from deserializer), FieldSchema(name:name, type:string, comment:from deserializer)], location:pfile:/Users/xiaol/Tools/hive-trunk/build/ql/test/data/warehouse/test_table, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe, parameters:{serialization.format=1, field.delim=,}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{last_modified_by=xiaol, last_modified_time=1317799666, transient_lastDdlTime=1317799666}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE) +PREHOOK: query: drop table test_table +PREHOOK: type: DROPTABLE +PREHOOK: Input: default@test_table +PREHOOK: Output: default@test_table +POSTHOOK: query: drop table test_table +POSTHOOK: type: DROPTABLE +POSTHOOK: Input: default@test_table +POSTHOOK: Output: default@test_table +PREHOOK: query: --- test partitioned table +create table test_table (id int, query string, name string) partitioned by (dt string) +PREHOOK: type: CREATETABLE +POSTHOOK: query: --- test partitioned table +create table test_table (id int, query string, name string) partitioned by (dt string) +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: default@test_table +PREHOOK: query: alter table test_table add partition (dt = '2011') +PREHOOK: type: ALTERTABLE_ADDPARTS +PREHOOK: Input: default@test_table +POSTHOOK: query: alter table test_table add partition (dt = '2011') +POSTHOOK: type: ALTERTABLE_ADDPARTS +POSTHOOK: Input: default@test_table +POSTHOOK: Output: default@test_table@dt=2011 +PREHOOK: query: describe extended test_table partition (dt='2011') +PREHOOK: type: DESCTABLE +POSTHOOK: query: describe extended test_table partition (dt='2011') +POSTHOOK: type: DESCTABLE +id int +query string +name string +dt string + +Detailed Partition Information Partition(values:[2011], dbName:default, tableName:test_table, createTime:1317799667, lastAccessTime:0, sd:StorageDescriptor(cols:[FieldSchema(name:id, type:int, comment:null), FieldSchema(name:query, type:string, comment:null), FieldSchema(name:name, type:string, comment:null)], location:pfile:/Users/xiaol/Tools/hive-trunk/build/ql/test/data/warehouse/test_table/dt=2011, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), parameters:{transient_lastDdlTime=1317799667}) +PREHOOK: query: alter table test_table set serde 'org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe' +PREHOOK: type: ALTERTABLE_SERIALIZER +PREHOOK: Input: default@test_table +PREHOOK: Output: default@test_table +POSTHOOK: query: alter table test_table set serde 'org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe' +POSTHOOK: type: ALTERTABLE_SERIALIZER +POSTHOOK: Input: default@test_table +POSTHOOK: Output: default@test_table +PREHOOK: query: describe extended test_table partition (dt='2011') +PREHOOK: type: DESCTABLE +POSTHOOK: query: describe extended test_table partition (dt='2011') +POSTHOOK: type: DESCTABLE +id int from deserializer +query string from deserializer +name string from deserializer +dt string + +Detailed Partition Information Partition(values:[2011], dbName:default, tableName:test_table, createTime:1317799667, lastAccessTime:0, sd:StorageDescriptor(cols:[FieldSchema(name:id, type:int, comment:null), FieldSchema(name:query, type:string, comment:null), FieldSchema(name:name, type:string, comment:null)], location:pfile:/Users/xiaol/Tools/hive-trunk/build/ql/test/data/warehouse/test_table/dt=2011, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), parameters:{transient_lastDdlTime=1317799667}) +PREHOOK: query: alter table test_table set serdeproperties ('field.delim' = ',') +PREHOOK: type: ALTERTABLE_SERDEPROPERTIES +PREHOOK: Input: default@test_table +PREHOOK: Output: default@test_table +POSTHOOK: query: alter table test_table set serdeproperties ('field.delim' = ',') +POSTHOOK: type: ALTERTABLE_SERDEPROPERTIES +POSTHOOK: Input: default@test_table +POSTHOOK: Output: default@test_table +PREHOOK: query: describe extended test_table partition (dt='2011') +PREHOOK: type: DESCTABLE +POSTHOOK: query: describe extended test_table partition (dt='2011') +POSTHOOK: type: DESCTABLE +id int from deserializer +query string from deserializer +name string from deserializer +dt string + +Detailed Partition Information Partition(values:[2011], dbName:default, tableName:test_table, createTime:1317799667, lastAccessTime:0, sd:StorageDescriptor(cols:[FieldSchema(name:id, type:int, comment:null), FieldSchema(name:query, type:string, comment:null), FieldSchema(name:name, type:string, comment:null)], location:pfile:/Users/xiaol/Tools/hive-trunk/build/ql/test/data/warehouse/test_table/dt=2011, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), parameters:{transient_lastDdlTime=1317799667}) +PREHOOK: query: -- test partitions + +alter table test_table partition(dt='2011') set serde 'org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe' +PREHOOK: type: ALTERPARTITION_SERIALIZER +PREHOOK: Input: default@test_table +PREHOOK: Output: default@test_table@dt=2011 +POSTHOOK: query: -- test partitions + +alter table test_table partition(dt='2011') set serde 'org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe' +POSTHOOK: type: ALTERPARTITION_SERIALIZER +POSTHOOK: Input: default@test_table +POSTHOOK: Input: default@test_table@dt=2011 +POSTHOOK: Output: default@test_table@dt=2011 +PREHOOK: query: describe extended test_table partition (dt='2011') +PREHOOK: type: DESCTABLE +POSTHOOK: query: describe extended test_table partition (dt='2011') +POSTHOOK: type: DESCTABLE +id int from deserializer +query string from deserializer +name string from deserializer +dt string + +Detailed Partition Information Partition(values:[2011], dbName:default, tableName:test_table, createTime:1317799667, lastAccessTime:0, sd:StorageDescriptor(cols:[FieldSchema(name:id, type:int, comment:null), FieldSchema(name:query, type:string, comment:null), FieldSchema(name:name, type:string, comment:null)], location:pfile:/Users/xiaol/Tools/hive-trunk/build/ql/test/data/warehouse/test_table/dt=2011, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), parameters:{last_modified_by=xiaol, last_modified_time=1317799667, transient_lastDdlTime=1317799667}) +PREHOOK: query: alter table test_table partition(dt='2011') set serdeproperties ('field.delim' = ',') +PREHOOK: type: ALTERPARTITION_SERDEPROPERTIES +PREHOOK: Input: default@test_table +PREHOOK: Output: default@test_table@dt=2011 +POSTHOOK: query: alter table test_table partition(dt='2011') set serdeproperties ('field.delim' = ',') +POSTHOOK: type: ALTERPARTITION_SERDEPROPERTIES +POSTHOOK: Input: default@test_table +POSTHOOK: Input: default@test_table@dt=2011 +POSTHOOK: Output: default@test_table@dt=2011 +PREHOOK: query: describe extended test_table partition (dt='2011') +PREHOOK: type: DESCTABLE +POSTHOOK: query: describe extended test_table partition (dt='2011') +POSTHOOK: type: DESCTABLE +id int from deserializer +query string from deserializer +name string from deserializer +dt string + +Detailed Partition Information Partition(values:[2011], dbName:default, tableName:test_table, createTime:1317799667, lastAccessTime:0, sd:StorageDescriptor(cols:[FieldSchema(name:id, type:int, comment:null), FieldSchema(name:query, type:string, comment:null), FieldSchema(name:name, type:string, comment:null)], location:pfile:/Users/xiaol/Tools/hive-trunk/build/ql/test/data/warehouse/test_table/dt=2011, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe, parameters:{serialization.format=1, field.delim=,}), bucketCols:[], sortCols:[], parameters:{}), parameters:{last_modified_by=xiaol, last_modified_time=1317799668, transient_lastDdlTime=1317799668}) +PREHOOK: query: drop table test_table +PREHOOK: type: DROPTABLE +PREHOOK: Input: default@test_table +PREHOOK: Output: default@test_table +POSTHOOK: query: drop table test_table +POSTHOOK: type: DROPTABLE +POSTHOOK: Input: default@test_table +POSTHOOK: Output: default@test_table Index: ql/src/test/queries/clientpositive/alter_table_serde.q =================================================================== --- ql/src/test/queries/clientpositive/alter_table_serde.q (revision 0) +++ ql/src/test/queries/clientpositive/alter_table_serde.q (revision 0) @@ -0,0 +1,33 @@ +-- test table +create table test_table (id int, query string, name string); +describe extended test_table; + +alter table test_table set serde 'org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe'; +describe extended test_table; + +alter table test_table set serdeproperties ('field.delim' = ','); +describe extended test_table; + +drop table test_table; + +--- test partitioned table +create table test_table (id int, query string, name string) partitioned by (dt string); + +alter table test_table add partition (dt = '2011'); +describe extended test_table partition (dt='2011'); + +alter table test_table set serde 'org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe'; +describe extended test_table partition (dt='2011'); + +alter table test_table set serdeproperties ('field.delim' = ','); +describe extended test_table partition (dt='2011'); + +-- test partitions + +alter table test_table partition(dt='2011') set serde 'org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe'; +describe extended test_table partition (dt='2011'); + +alter table test_table partition(dt='2011') set serdeproperties ('field.delim' = ','); +describe extended test_table partition (dt='2011'); + +drop table test_table Index: ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (revision 1178944) +++ ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (working copy) @@ -2801,16 +2801,31 @@ } else if (alterTbl.getOp() == AlterTableDesc.AlterTableTypes.ADDPROPS) { tbl.getTTable().getParameters().putAll(alterTbl.getProps()); } else if (alterTbl.getOp() == AlterTableDesc.AlterTableTypes.ADDSERDEPROPS) { - tbl.getTTable().getSd().getSerdeInfo().getParameters().putAll( - alterTbl.getProps()); - } else if (alterTbl.getOp() == AlterTableDesc.AlterTableTypes.ADDSERDE) { - tbl.setSerializationLib(alterTbl.getSerdeName()); - if ((alterTbl.getProps() != null) && (alterTbl.getProps().size() > 0)) { + if (part != null) { + part.getTPartition().getSd().getSerdeInfo().getParameters().putAll( + alterTbl.getProps()); + } else { tbl.getTTable().getSd().getSerdeInfo().getParameters().putAll( alterTbl.getProps()); } - tbl.setFields(Hive.getFieldsFromDeserializer(tbl.getTableName(), tbl - .getDeserializer())); + } else if (alterTbl.getOp() == AlterTableDesc.AlterTableTypes.ADDSERDE) { + String serdeName = alterTbl.getSerdeName(); + if (part != null) { + part.getTPartition().getSd().getSerdeInfo().setSerializationLib(serdeName); + if ((alterTbl.getProps() != null) && (alterTbl.getProps().size() > 0)) { + part.getTPartition().getSd().getSerdeInfo().getParameters().putAll( + alterTbl.getProps()); + } + part.getTPartition().getSd().setCols(part.getTPartition().getSd().getCols()); + } else { + tbl.setSerializationLib(alterTbl.getSerdeName()); + if ((alterTbl.getProps() != null) && (alterTbl.getProps().size() > 0)) { + tbl.getTTable().getSd().getSerdeInfo().getParameters().putAll( + alterTbl.getProps()); + } + tbl.setFields(Hive.getFieldsFromDeserializer(tbl.getTableName(), tbl. + getDeserializer())); + } } else if (alterTbl.getOp() == AlterTableDesc.AlterTableTypes.ADDFILEFORMAT) { if(part != null) { part.getTPartition().getSd().setInputFormat(alterTbl.getInputFormat()); Index: ql/src/java/org/apache/hadoop/hive/ql/plan/HiveOperation.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/plan/HiveOperation.java (revision 1178984) +++ ql/src/java/org/apache/hadoop/hive/ql/plan/HiveOperation.java (working copy) @@ -44,7 +44,9 @@ ALTERTABLE_UNARCHIVE("ALTERTABLE_UNARCHIVE", new Privilege[]{Privilege.ALTER_DATA}, null), ALTERTABLE_PROPERTIES("ALTERTABLE_PROPERTIES", new Privilege[]{Privilege.ALTER_METADATA}, null), ALTERTABLE_SERIALIZER("ALTERTABLE_SERIALIZER", new Privilege[]{Privilege.ALTER_METADATA}, null), + ALTERPARTITION_SERIALIZER("ALTERPARTITION_SERIALIZER", new Privilege[]{Privilege.ALTER_METADATA}, null), ALTERTABLE_SERDEPROPERTIES("ALTERTABLE_SERDEPROPERTIES", new Privilege[]{Privilege.ALTER_METADATA}, null), + ALTERPARTITION_SERDEPROPERTIES("ALTERPARTITION_SERDEPROPERTIES", new Privilege[]{Privilege.ALTER_METADATA}, null), ALTERTABLE_CLUSTER_SORT("ALTERTABLE_CLUSTER_SORT", new Privilege[]{Privilege.ALTER_METADATA}, null), SHOWDATABASES("SHOWDATABASES", new Privilege[]{Privilege.SHOW_DATABASE}, null), SHOWTABLES("SHOWTABLES", null, null), Index: ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (revision 1178944) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (working copy) @@ -571,7 +571,6 @@ | alterStatementSuffixArchive | alterStatementSuffixUnArchive | alterStatementSuffixProperties - | alterStatementSuffixSerdeProperties | alterTblPartitionStatement | alterStatementSuffixClusterbySortby ; @@ -704,10 +703,10 @@ alterStatementSuffixSerdeProperties @init { msgs.push("alter serdes statement"); } @after { msgs.pop(); } - : name=Identifier KW_SET KW_SERDE serdeName=StringLiteral (KW_WITH KW_SERDEPROPERTIES tableProperties)? - -> ^(TOK_ALTERTABLE_SERIALIZER $name $serdeName tableProperties?) - | name=Identifier KW_SET KW_SERDEPROPERTIES tableProperties - -> ^(TOK_ALTERTABLE_SERDEPROPERTIES $name tableProperties) + : KW_SET KW_SERDE serdeName=StringLiteral (KW_WITH KW_SERDEPROPERTIES tableProperties)? + -> ^(TOK_ALTERTABLE_SERIALIZER $serdeName tableProperties?) + | KW_SET KW_SERDEPROPERTIES tableProperties + -> ^(TOK_ALTERTABLE_SERDEPROPERTIES tableProperties) ; tablePartitionPrefix @@ -731,6 +730,7 @@ | alterStatementSuffixLocation | alterStatementSuffixProtectMode | alterStatementSuffixMergeFiles + | alterStatementSuffixSerdeProperties ; alterStatementSuffixFileFormat Index: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java (revision 1178944) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java (working copy) @@ -56,8 +56,6 @@ commandType.put(HiveParser.TOK_ALTERTABLE_ARCHIVE, HiveOperation.ALTERTABLE_ARCHIVE); commandType.put(HiveParser.TOK_ALTERTABLE_UNARCHIVE, HiveOperation.ALTERTABLE_UNARCHIVE); commandType.put(HiveParser.TOK_ALTERTABLE_PROPERTIES, HiveOperation.ALTERTABLE_PROPERTIES); - commandType.put(HiveParser.TOK_ALTERTABLE_SERIALIZER, HiveOperation.ALTERTABLE_SERIALIZER); - commandType.put(HiveParser.TOK_ALTERTABLE_SERDEPROPERTIES, HiveOperation.ALTERTABLE_SERDEPROPERTIES); commandType.put(HiveParser.TOK_ALTERTABLE_CLUSTER_SORT, HiveOperation.ALTERTABLE_CLUSTER_SORT); commandType.put(HiveParser.TOK_SHOWDATABASES, HiveOperation.SHOWDATABASES); commandType.put(HiveParser.TOK_SHOWTABLES, HiveOperation.SHOWTABLES); @@ -104,8 +102,14 @@ new HiveOperation[] { HiveOperation.ALTERTABLE_LOCATION, HiveOperation.ALTERPARTITION_LOCATION }); tablePartitionCommandType.put(HiveParser.TOK_ALTERTABLE_ALTERPARTS_MERGEFILES, - new HiveOperation[] {HiveOperation.ALTERTABLE_MERGEFILES, + new HiveOperation[] {HiveOperation.ALTERTABLE_MERGEFILES, HiveOperation.ALTERPARTITION_MERGEFILES }); + tablePartitionCommandType.put(HiveParser.TOK_ALTERTABLE_SERIALIZER, + new HiveOperation[] {HiveOperation.ALTERTABLE_SERIALIZER, + HiveOperation.ALTERPARTITION_SERIALIZER }); + tablePartitionCommandType.put(HiveParser.TOK_ALTERTABLE_SERDEPROPERTIES, + new HiveOperation[] {HiveOperation.ALTERTABLE_SERDEPROPERTIES, + HiveOperation.ALTERPARTITION_SERDEPROPERTIES }); } public static BaseSemanticAnalyzer get(HiveConf conf, ASTNode tree) Index: ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java (revision 1178944) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java (working copy) @@ -196,6 +194,10 @@ analyzeAlterTableLocation(ast, tableName, partSpec); } else if (ast.getToken().getType() == HiveParser.TOK_ALTERTABLE_ALTERPARTS_MERGEFILES) { analyzeAlterTablePartMergeFiles(tablePart, ast, tableName, partSpec); + } else if (ast.getToken().getType() == HiveParser.TOK_ALTERTABLE_SERIALIZER) { + analyzeAlterTableSerde(ast, tableName, partSpec); + } else if (ast.getToken().getType() == HiveParser.TOK_ALTERTABLE_SERDEPROPERTIES) { + analyzeAlterTableSerdeProps(ast, tableName, partSpec); } break; } @@ -295,12 +297,6 @@ case HiveParser.TOK_ALTERTABLE_PROPERTIES: analyzeAlterTableProps(ast, false); break; - case HiveParser.TOK_ALTERTABLE_SERDEPROPERTIES: - analyzeAlterTableSerdeProps(ast); - break; - case HiveParser.TOK_ALTERTABLE_SERIALIZER: - analyzeAlterTableSerde(ast); - break; case HiveParser.TOK_ALTERTABLE_CLUSTER_SORT: analyzeAlterTableClusterSort(ast); break; @@ -946,52 +942,38 @@ alterTblDesc), conf)); } - private void analyzeAlterTableSerdeProps(ASTNode ast) + private void analyzeAlterTableSerdeProps(ASTNode ast, String tableName, + HashMap partSpec) throws SemanticException { - String tableName = getUnescapedName((ASTNode)ast.getChild(0)); - HashMap mapProp = getProps((ASTNode) (ast.getChild(1)) + HashMap mapProp = getProps((ASTNode) (ast.getChild(0)) .getChild(0)); AlterTableDesc alterTblDesc = new AlterTableDesc( AlterTableTypes.ADDSERDEPROPS); alterTblDesc.setProps(mapProp); alterTblDesc.setOldName(tableName); + alterTblDesc.setPartSpec(partSpec); - try { - Table tab = db.getTable(db.getCurrentDatabase(), tableName, false); - if (tab != null) { - inputs.add(new ReadEntity(tab)); - outputs.add(new WriteEntity(tab)); - } - } catch (HiveException e) { - throw new SemanticException(ErrorMsg.INVALID_TABLE.getMsg(tableName)); - } - + addInputsOutputsAlterTable(tableName, partSpec); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), alterTblDesc), conf)); } - private void analyzeAlterTableSerde(ASTNode ast) throws SemanticException { - String tableName = getUnescapedName((ASTNode)ast.getChild(0)); - String serdeName = unescapeSQLString(ast.getChild(1).getText()); + private void analyzeAlterTableSerde(ASTNode ast, String tableName, + HashMap partSpec) + throws SemanticException { + + String serdeName = unescapeSQLString(ast.getChild(0).getText()); AlterTableDesc alterTblDesc = new AlterTableDesc(AlterTableTypes.ADDSERDE); - if (ast.getChildCount() > 2) { - HashMap mapProp = getProps((ASTNode) (ast.getChild(2)) + if (ast.getChildCount() > 1) { + HashMap mapProp = getProps((ASTNode) (ast.getChild(1)) .getChild(0)); alterTblDesc.setProps(mapProp); } alterTblDesc.setOldName(tableName); alterTblDesc.setSerdeName(serdeName); + alterTblDesc.setPartSpec(partSpec); - try { - Table tab = db.getTable(db.getCurrentDatabase(), tableName, false); - if (tab != null) { - inputs.add(new ReadEntity(tab)); - outputs.add(new WriteEntity(tab)); - } - } catch (HiveException e) { - throw new SemanticException(ErrorMsg.INVALID_TABLE.getMsg(tableName)); - } - + addInputsOutputsAlterTable(tableName, partSpec); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), alterTblDesc), conf)); }