Index: ql/src/test/results/clientpositive/alter_partition_format_loc.q.out =================================================================== --- ql/src/test/results/clientpositive/alter_partition_format_loc.q.out (revision 0) +++ ql/src/test/results/clientpositive/alter_partition_format_loc.q.out (revision 0) @@ -0,0 +1,141 @@ +PREHOOK: query: create table alter_partition_format_test (key int, value string) +PREHOOK: type: CREATETABLE +POSTHOOK: query: create table alter_partition_format_test (key int, value string) +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: default@alter_partition_format_test +PREHOOK: query: desc extended alter_partition_format_test +PREHOOK: type: DESCTABLE +POSTHOOK: query: desc extended alter_partition_format_test +POSTHOOK: type: DESCTABLE +key int +value string + +Detailed Table Information Table(tableName:alter_partition_format_test, dbName:default, owner:heyongqiang, createTime:1281044582, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:key, type:int, comment:null), FieldSchema(name:value, type:string, comment:null)], location:pfile:/Users/heyongqiang/Documents/workspace/Hive-2/build/ql/test/data/warehouse/alter_partition_format_test, 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=1281044582}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE) +PREHOOK: query: alter table alter_partition_format_test set fileformat rcfile +PREHOOK: type: null +POSTHOOK: query: alter table alter_partition_format_test set fileformat rcfile +POSTHOOK: type: null +POSTHOOK: Input: default@alter_partition_format_test +POSTHOOK: Output: default@alter_partition_format_test +PREHOOK: query: desc extended alter_partition_format_test +PREHOOK: type: DESCTABLE +POSTHOOK: query: desc extended alter_partition_format_test +POSTHOOK: type: DESCTABLE +key int from deserializer +value string from deserializer + +Detailed Table Information Table(tableName:alter_partition_format_test, dbName:default, owner:heyongqiang, createTime:1281044582, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:key, type:int, comment:null), FieldSchema(name:value, type:string, comment:null)], location:pfile:/Users/heyongqiang/Documents/workspace/Hive-2/build/ql/test/data/warehouse/alter_partition_format_test, inputFormat:org.apache.hadoop.hive.ql.io.RCFileInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.RCFileOutputFormat, 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=heyongqiang, last_modified_time=1281044582, transient_lastDdlTime=1281044582}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE) +PREHOOK: query: alter table alter_partition_format_test set location "file:/test/test/" +PREHOOK: type: null +POSTHOOK: query: alter table alter_partition_format_test set location "file:/test/test/" +POSTHOOK: type: null +POSTHOOK: Input: default@alter_partition_format_test +POSTHOOK: Output: default@alter_partition_format_test +PREHOOK: query: desc extended alter_partition_format_test +PREHOOK: type: DESCTABLE +POSTHOOK: query: desc extended alter_partition_format_test +POSTHOOK: type: DESCTABLE +key int from deserializer +value string from deserializer + +Detailed Table Information Table(tableName:alter_partition_format_test, dbName:default, owner:heyongqiang, createTime:1281044582, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:key, type:int, comment:null), FieldSchema(name:value, type:string, comment:null)], location:file:/test/test/, inputFormat:org.apache.hadoop.hive.ql.io.RCFileInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.RCFileOutputFormat, 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=heyongqiang, last_modified_time=1281044582, transient_lastDdlTime=1281044582}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE) +PREHOOK: query: drop table alter_partition_format_test +PREHOOK: type: DROPTABLE +POSTHOOK: query: drop table alter_partition_format_test +POSTHOOK: type: DROPTABLE +POSTHOOK: Output: default@alter_partition_format_test +PREHOOK: query: --partitioned table +create table alter_partition_format_test (key int, value string) partitioned by (ds string) +PREHOOK: type: CREATETABLE +POSTHOOK: query: --partitioned table +create table alter_partition_format_test (key int, value string) partitioned by (ds string) +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: default@alter_partition_format_test +PREHOOK: query: alter table alter_partition_format_test add partition(ds='2010') +PREHOOK: type: ALTERTABLE_ADDPARTS +POSTHOOK: query: alter table alter_partition_format_test add partition(ds='2010') +POSTHOOK: type: ALTERTABLE_ADDPARTS +POSTHOOK: Output: default@alter_partition_format_test@ds=2010 +PREHOOK: query: desc extended alter_partition_format_test partition(ds='2010') +PREHOOK: type: DESCTABLE +POSTHOOK: query: desc extended alter_partition_format_test partition(ds='2010') +POSTHOOK: type: DESCTABLE +key int +value string +ds string + +Detailed Partition Information Partition(values:[2010], dbName:default, tableName:alter_partition_format_test, createTime:1281044583, lastAccessTime:0, sd:StorageDescriptor(cols:[FieldSchema(name:key, type:int, comment:null), FieldSchema(name:value, type:string, comment:null)], location:pfile:/Users/heyongqiang/Documents/workspace/Hive-2/build/ql/test/data/warehouse/alter_partition_format_test/ds=2010, 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=1281044583}) +PREHOOK: query: alter table alter_partition_format_test partition(ds='2010') set fileformat rcfile +PREHOOK: type: null +POSTHOOK: query: alter table alter_partition_format_test partition(ds='2010') set fileformat rcfile +POSTHOOK: type: null +POSTHOOK: Input: default@alter_partition_format_test +POSTHOOK: Output: default@alter_partition_format_test +PREHOOK: query: desc extended alter_partition_format_test partition(ds='2010') +PREHOOK: type: DESCTABLE +POSTHOOK: query: desc extended alter_partition_format_test partition(ds='2010') +POSTHOOK: type: DESCTABLE +key int +value string +ds string + +Detailed Partition Information Partition(values:[2010], dbName:default, tableName:alter_partition_format_test, createTime:1281044583, lastAccessTime:0, sd:StorageDescriptor(cols:[FieldSchema(name:key, type:int, comment:null), FieldSchema(name:value, type:string, comment:null)], location:pfile:/Users/heyongqiang/Documents/workspace/Hive-2/build/ql/test/data/warehouse/alter_partition_format_test/ds=2010, inputFormat:org.apache.hadoop.hive.ql.io.RCFileInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.RCFileOutputFormat, 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=heyongqiang, last_modified_time=1281044583, transient_lastDdlTime=1281044583}) +PREHOOK: query: alter table alter_partition_format_test partition(ds='2010') set location "file:/test/test/ds=2010" +PREHOOK: type: null +POSTHOOK: query: alter table alter_partition_format_test partition(ds='2010') set location "file:/test/test/ds=2010" +POSTHOOK: type: null +POSTHOOK: Input: default@alter_partition_format_test +POSTHOOK: Output: default@alter_partition_format_test +PREHOOK: query: desc extended alter_partition_format_test partition(ds='2010') +PREHOOK: type: DESCTABLE +POSTHOOK: query: desc extended alter_partition_format_test partition(ds='2010') +POSTHOOK: type: DESCTABLE +key int +value string +ds string + +Detailed Partition Information Partition(values:[2010], dbName:default, tableName:alter_partition_format_test, createTime:1281044583, lastAccessTime:0, sd:StorageDescriptor(cols:[FieldSchema(name:key, type:int, comment:null), FieldSchema(name:value, type:string, comment:null)], location:file:/test/test/ds=2010, inputFormat:org.apache.hadoop.hive.ql.io.RCFileInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.RCFileOutputFormat, 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=heyongqiang, last_modified_time=1281044583, transient_lastDdlTime=1281044583}) +PREHOOK: query: desc extended alter_partition_format_test +PREHOOK: type: DESCTABLE +POSTHOOK: query: desc extended alter_partition_format_test +POSTHOOK: type: DESCTABLE +key int +value string +ds string + +Detailed Table Information Table(tableName:alter_partition_format_test, dbName:default, owner:heyongqiang, createTime:1281044583, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:key, type:int, comment:null), FieldSchema(name:value, type:string, comment:null)], location:pfile:/Users/heyongqiang/Documents/workspace/Hive-2/build/ql/test/data/warehouse/alter_partition_format_test, 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:[FieldSchema(name:ds, type:string, comment:null)], parameters:{transient_lastDdlTime=1281044583}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE) +PREHOOK: query: alter table alter_partition_format_test set fileformat rcfile +PREHOOK: type: null +POSTHOOK: query: alter table alter_partition_format_test set fileformat rcfile +POSTHOOK: type: null +POSTHOOK: Input: default@alter_partition_format_test +POSTHOOK: Output: default@alter_partition_format_test +PREHOOK: query: desc extended alter_partition_format_test +PREHOOK: type: DESCTABLE +POSTHOOK: query: desc extended alter_partition_format_test +POSTHOOK: type: DESCTABLE +key int from deserializer +value string from deserializer +ds string + +Detailed Table Information Table(tableName:alter_partition_format_test, dbName:default, owner:heyongqiang, createTime:1281044583, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:key, type:int, comment:null), FieldSchema(name:value, type:string, comment:null)], location:pfile:/Users/heyongqiang/Documents/workspace/Hive-2/build/ql/test/data/warehouse/alter_partition_format_test, inputFormat:org.apache.hadoop.hive.ql.io.RCFileInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.RCFileOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[FieldSchema(name:ds, type:string, comment:null)], parameters:{last_modified_by=heyongqiang, last_modified_time=1281044584, transient_lastDdlTime=1281044584}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE) +PREHOOK: query: alter table alter_partition_format_test set location "file:/test/test/" +PREHOOK: type: null +POSTHOOK: query: alter table alter_partition_format_test set location "file:/test/test/" +POSTHOOK: type: null +POSTHOOK: Input: default@alter_partition_format_test +POSTHOOK: Output: default@alter_partition_format_test +PREHOOK: query: desc extended alter_partition_format_test +PREHOOK: type: DESCTABLE +POSTHOOK: query: desc extended alter_partition_format_test +POSTHOOK: type: DESCTABLE +key int from deserializer +value string from deserializer +ds string + +Detailed Table Information Table(tableName:alter_partition_format_test, dbName:default, owner:heyongqiang, createTime:1281044583, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:key, type:int, comment:null), FieldSchema(name:value, type:string, comment:null)], location:file:/test/test/, inputFormat:org.apache.hadoop.hive.ql.io.RCFileInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.RCFileOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[FieldSchema(name:ds, type:string, comment:null)], parameters:{last_modified_by=heyongqiang, last_modified_time=1281044584, transient_lastDdlTime=1281044584}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE) +PREHOOK: query: drop table alter_partition_format_test +PREHOOK: type: DROPTABLE +POSTHOOK: query: drop table alter_partition_format_test +POSTHOOK: type: DROPTABLE +POSTHOOK: Output: default@alter_partition_format_test Index: ql/src/test/queries/clientpositive/alter_partition_format_loc.q =================================================================== --- ql/src/test/queries/clientpositive/alter_partition_format_loc.q (revision 0) +++ ql/src/test/queries/clientpositive/alter_partition_format_loc.q (revision 0) @@ -0,0 +1,32 @@ +create table alter_partition_format_test (key int, value string); +desc extended alter_partition_format_test; + +alter table alter_partition_format_test set fileformat rcfile; +desc extended alter_partition_format_test; + +alter table alter_partition_format_test set location "file:/test/test/"; +desc extended alter_partition_format_test; + +drop table alter_partition_format_test; + +--partitioned table +create table alter_partition_format_test (key int, value string) partitioned by (ds string); + +alter table alter_partition_format_test add partition(ds='2010'); +desc extended alter_partition_format_test partition(ds='2010'); + +alter table alter_partition_format_test partition(ds='2010') set fileformat rcfile; +desc extended alter_partition_format_test partition(ds='2010'); + +alter table alter_partition_format_test partition(ds='2010') set location "file:/test/test/ds=2010"; +desc extended alter_partition_format_test partition(ds='2010'); + +desc extended alter_partition_format_test; + +alter table alter_partition_format_test set fileformat rcfile; +desc extended alter_partition_format_test; + +alter table alter_partition_format_test set location "file:/test/test/"; +desc extended alter_partition_format_test; + +drop table alter_partition_format_test; \ No newline at end of file Index: ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (revision 982003) +++ ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (working copy) @@ -1583,6 +1583,11 @@ // alter the table Table tbl = db.getTable(MetaStoreUtils.DEFAULT_DATABASE_NAME, alterTbl .getOldName()); + + Partition part = null; + if(alterTbl.getPartSpec() != null) { + part = db.getPartition(tbl, alterTbl.getPartSpec(), false); + } validateAlterTableType(tbl, alterTbl.getOp()); @@ -1724,10 +1729,19 @@ tbl.setFields(Hive.getFieldsFromDeserializer(tbl.getTableName(), tbl .getDeserializer())); } else if (alterTbl.getOp() == AlterTableDesc.AlterTableTypes.ADDFILEFORMAT) { - tbl.getTTable().getSd().setInputFormat(alterTbl.getInputFormat()); - tbl.getTTable().getSd().setOutputFormat(alterTbl.getOutputFormat()); - if (alterTbl.getSerdeName() != null) { - tbl.setSerializationLib(alterTbl.getSerdeName()); + if(part != null) { + part.getTPartition().getSd().setInputFormat(alterTbl.getInputFormat()); + part.getTPartition().getSd().setOutputFormat(alterTbl.getOutputFormat()); + if (alterTbl.getSerdeName() != null) { + part.getTPartition().getSd().getSerdeInfo().setSerializationLib( + alterTbl.getSerdeName()); + } + } else { + tbl.getTTable().getSd().setInputFormat(alterTbl.getInputFormat()); + tbl.getTTable().getSd().setOutputFormat(alterTbl.getOutputFormat()); + if (alterTbl.getSerdeName() != null) { + tbl.setSerializationLib(alterTbl.getSerdeName()); + } } } else if (alterTbl.getOp() == AlterTableDesc.AlterTableTypes.ADDCLUSTERSORTCOLUMN) { // validate sort columns and bucket columns @@ -1756,32 +1770,63 @@ tbl.getTTable().getSd().setBucketCols(bucketCols); tbl.getTTable().getSd().setNumBuckets(numBuckets); tbl.getTTable().getSd().setSortCols(sortCols); + } else if (alterTbl.getOp() == AlterTableDesc.AlterTableTypes.ALTERLOCATION) { + String newLocation = alterTbl.getNewLocation(); + try { + URI locURI = new URI(newLocation); + if (!locURI.isAbsolute() || locURI.getScheme() == null + || locURI.getScheme().trim().equals("")) { + throw new HiveException( + newLocation + + " is not absolute or has no scheme information. " + + "Please specify a complete absolute uri with scheme information."); + } + if (part != null) { + part.setLocation(newLocation); + } else { + tbl.setDataLocation(locURI); + } + } catch (URISyntaxException e) { + throw new HiveException(e); + } } else { console.printError("Unsupported Alter commnad"); return 1; } // set last modified by properties + String user = null; try { - tbl.setProperty("last_modified_by", conf.getUser()); + user = conf.getUser(); } catch (IOException e) { console.printError("Unable to get current user: " + e.getMessage(), stringifyException(e)); return 1; } - tbl.setProperty("last_modified_time", Long.toString(System - .currentTimeMillis() / 1000)); - try { - tbl.checkValidity(); - } catch (HiveException e) { - console.printError("Invalid table columns : " + e.getMessage(), - stringifyException(e)); - return 1; + if(part == null) { + tbl.setProperty("last_modified_by", user); + tbl.setProperty("last_modified_time", Long.toString(System + .currentTimeMillis() / 1000)); + try { + tbl.checkValidity(); + } catch (HiveException e) { + console.printError("Invalid table columns : " + e.getMessage(), + stringifyException(e)); + return 1; + } + } else { + part.getParameters().put("last_modified_by", user); + part.getParameters().put("last_modified_time", Long.toString(System + .currentTimeMillis() / 1000)); } - + try { - db.alterTable(alterTbl.getOldName(), tbl); + if (part == null) { + db.alterTable(alterTbl.getOldName(), tbl); + } else { + db.alterPartition(tbl.getTableName(), part); + } } catch (InvalidOperationException e) { console.printError("Invalid alter operation: " + e.getMessage()); LOG.info("alter table: " + stringifyException(e)); Index: ql/src/java/org/apache/hadoop/hive/ql/plan/AlterTableDesc.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/plan/AlterTableDesc.java (revision 982003) +++ ql/src/java/org/apache/hadoop/hive/ql/plan/AlterTableDesc.java (working copy) @@ -42,7 +42,7 @@ public static enum AlterTableTypes { RENAME, ADDCOLS, REPLACECOLS, ADDPROPS, ADDSERDE, ADDSERDEPROPS, ADDFILEFORMAT, ADDCLUSTERSORTCOLUMN, RENAMECOLUMN, ADDPARTITION, - TOUCH, ARCHIVE, UNARCHIVE, + TOUCH, ARCHIVE, UNARCHIVE, ALTERLOCATION, }; AlterTableTypes op; @@ -65,6 +65,8 @@ boolean first; String afterCol; boolean expectView; + HashMap partSpec; + private String newLocation; public AlterTableDesc() { } @@ -142,9 +144,10 @@ * new table input format * @param outputFormat * new table output format + * @param partSpec */ public AlterTableDesc(String name, String inputFormat, String outputFormat, - String serdeName, String storageHandler) { + String serdeName, String storageHandler, HashMap partSpec) { super(); op = AlterTableTypes.ADDFILEFORMAT; oldName = name; @@ -152,6 +155,7 @@ this.outputFormat = outputFormat; this.serdeName = serdeName; this.storageHandler = storageHandler; + this.partSpec = partSpec; } public AlterTableDesc(String tableName, int numBuckets, @@ -163,6 +167,14 @@ sortColumns = new ArrayList(sortCols); } + public AlterTableDesc(String tableName, String newLocation, + HashMap partSpec) { + op = AlterTableTypes.ALTERLOCATION; + this.oldName = tableName; + this.newLocation = newLocation; + this.partSpec = partSpec; + } + @Explain(displayName = "new columns") public List getNewColsString() { return Utilities.getFieldSchemaString(getNewCols()); @@ -473,4 +485,32 @@ public void setExpectView(boolean expectView) { this.expectView = expectView; } + + /** + * @return part specification + */ + public HashMap getPartSpec() { + return partSpec; + } + + /** + * @param partSpec + */ + public void setPartSpec(HashMap partSpec) { + this.partSpec = partSpec; + } + + /** + * @return new location + */ + public String getNewLocation() { + return newLocation; + } + + /** + * @param newLocation new location + */ + public void setNewLocation(String newLocation) { + this.newLocation = newLocation; + } } Index: ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (revision 982003) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (working copy) @@ -5,7 +5,7 @@ output=AST; ASTLabelType=CommonTree; backtrack=false; -k=3; +k=15; } tokens { @@ -104,7 +104,9 @@ TOK_ALTERTABLE_UNARCHIVE; TOK_ALTERTABLE_SERDEPROPERTIES; TOK_ALTERTABLE_SERIALIZER; +TOK_TABLE_PARTITION; TOK_ALTERTABLE_FILEFORMAT; +TOK_ALTERTABLE_LOCATION; TOK_ALTERTABLE_PROPERTIES; TOK_ALTERTABLE_CHANGECOL_AFTER_POSITION; TOK_ALTERINDEX_REBUILD; @@ -352,6 +354,7 @@ | alterStatementSuffixProperties | alterStatementSuffixSerdeProperties | alterStatementSuffixFileFormat + | alterStatementSuffixLocation | alterStatementSuffixClusterbySortby ; @@ -457,10 +460,24 @@ alterStatementSuffixFileFormat @init {msgs.push("alter fileformat statement"); } @after {msgs.pop(); } - :name=Identifier KW_SET KW_FILEFORMAT fileFormat - -> ^(TOK_ALTERTABLE_FILEFORMAT $name fileFormat) + :tablePartitionPrefix KW_SET KW_FILEFORMAT fileFormat + -> ^(TOK_ALTERTABLE_FILEFORMAT tablePartitionPrefix fileFormat) ; +alterStatementSuffixLocation +@init {msgs.push("alter location");} +@after {msgs.pop();} + : tablePartitionPrefix KW_SET KW_LOCATION newLoc=StringLiteral + -> ^(TOK_ALTERTABLE_LOCATION tablePartitionPrefix $newLoc) + ; + +tablePartitionPrefix +@init {msgs.push("table partition prefix");} +@after {msgs.pop();} + :name=Identifier partitionSpec? + ->^(TOK_TABLE_PARTITION $name partitionSpec?) + ; + alterStatementSuffixClusterbySortby @init {msgs.push("alter cluster by sort by statement");} @after{msgs.pop();} Index: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java (revision 982003) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java (working copy) @@ -108,6 +108,7 @@ case HiveParser.TOK_ALTERTABLE_TOUCH: case HiveParser.TOK_ALTERTABLE_ARCHIVE: case HiveParser.TOK_ALTERTABLE_UNARCHIVE: + case HiveParser.TOK_ALTERTABLE_LOCATION: return new DDLSemanticAnalyzer(conf); case HiveParser.TOK_CREATEFUNCTION: case HiveParser.TOK_DROPFUNCTION: Index: ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java (revision 982003) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java (working copy) @@ -107,6 +107,24 @@ return TokenToTypeName.get(token); } + static class TablePartition { + String tableName; + HashMap partSpec = null; + + public TablePartition(){ + } + + public TablePartition (ASTNode tblPart) throws SemanticException { + tableName = unescapeIdentifier(tblPart.getChild(0).getText()); + if (tblPart.getChildCount() > 1) { + ASTNode part = (ASTNode) tblPart.getChild(1); + if (part.getToken().getType() == HiveParser.TOK_PARTSPEC) { + this.partSpec = DDLSemanticAnalyzer.getPartSpec(part); + } + } + } + } + public DDLSemanticAnalyzer(HiveConf conf) throws SemanticException { super(conf); // Partition can't have this name @@ -180,6 +198,8 @@ } else if (ast.getToken().getType() == HiveParser.TOK_SHOWPARTITIONS) { ctx.setResFile(new Path(ctx.getLocalTmpFileURI())); analyzeShowPartitions(ast); + } else if (ast.getToken().getType() == HiveParser.TOK_ALTERTABLE_LOCATION) { + analyzeAlterTableLocation(ast); } else { throw new SemanticException("Unsupported command."); } @@ -393,7 +413,11 @@ private void analyzeAlterTableFileFormat(ASTNode ast) throws SemanticException { - String tableName = unescapeIdentifier(ast.getChild(0).getText()); + + TablePartition tblPart = new TablePartition((ASTNode)ast.getChild(0)); + String tableName = tblPart.tableName; + HashMap partSpec = tblPart.partSpec; + String inputFormat = null; String outputFormat = null; String storageHandler = null; @@ -436,12 +460,25 @@ serde = COLUMNAR_SERDE; break; } + AlterTableDesc alterTblDesc = new AlterTableDesc(tableName, inputFormat, - outputFormat, serde, storageHandler); + outputFormat, serde, storageHandler, partSpec); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), alterTblDesc), conf)); } + + private void analyzeAlterTableLocation(ASTNode ast) throws SemanticException { + TablePartition tblPart = new TablePartition((ASTNode)ast.getChild(0)); + String tableName = tblPart.tableName; + HashMap partSpec = tblPart.partSpec; + String newLocation = unescapeSQLString(ast.getChild(1).getText()); + + AlterTableDesc alterTblDesc = new AlterTableDesc (tableName, newLocation, partSpec); + rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), + alterTblDesc), conf)); + } + private void analyzeAlterTableClusterSort(ASTNode ast) throws SemanticException { String tableName = unescapeIdentifier(ast.getChild(0).getText()); @@ -540,7 +577,7 @@ LOG.info("analyzeDescribeTable done"); } - private HashMap getPartSpec(ASTNode partspec) + private static HashMap getPartSpec(ASTNode partspec) throws SemanticException { HashMap partSpec = new LinkedHashMap(); for (int i = 0; i < partspec.getChildCount(); ++i) {