Index: metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (revision 10036) +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (working copy) @@ -784,8 +784,10 @@ // set create time long time = System.currentTimeMillis() / 1000; tbl.setCreateTime((int) time); - tbl.putToParameters(Constants.DDL_TIME, Long.toString(time)); - + if (tbl.getParameters() == null || + tbl.getParameters().get(Constants.DDL_TIME) == null) { + tbl.putToParameters(Constants.DDL_TIME, Long.toString(time)); + } ms.createTable(tbl); success = ms.commitTransaction(); @@ -1160,8 +1162,10 @@ // set create time long time = System.currentTimeMillis() / 1000; part.setCreateTime((int) time); - part.putToParameters(Constants.DDL_TIME, Long.toString(time)); - + if (part.getParameters() == null || + part.getParameters().get(Constants.DDL_TIME) == null) { + part.putToParameters(Constants.DDL_TIME, Long.toString(time)); + } success = ms.addPartition(part) && ms.commitTransaction(); } finally { @@ -1360,8 +1364,13 @@ final String tbl_name, final Partition new_part) throws InvalidOperationException, MetaException, TException { try { - new_part.putToParameters(Constants.DDL_TIME, Long.toString(System - .currentTimeMillis() / 1000)); + // Set DDL time to now if not specified + if (new_part.getParameters() == null || + new_part.getParameters().get(Constants.DDL_TIME) == null || + Integer.parseInt(new_part.getParameters().get(Constants.DDL_TIME)) == 0) { + new_part.putToParameters(Constants.DDL_TIME, Long.toString(System + .currentTimeMillis() / 1000)); + } ms.alterPartition(db_name, tbl_name, new_part); } catch (InvalidObjectException e) { throw new InvalidOperationException("alter is not possible"); @@ -1414,9 +1423,14 @@ incrementCounter("alter_table"); logStartFunction("alter_table: db=" + dbname + " tbl=" + name + " newtbl=" + newTable.getTableName()); - newTable.putToParameters(Constants.DDL_TIME, Long.toString(System - .currentTimeMillis() / 1000)); + // Update the time if it hasn't been specified. + if (newTable.getParameters() == null || + newTable.getParameters().get(Constants.DDL_TIME) == null) { + newTable.putToParameters(Constants.DDL_TIME, Long.toString(System + .currentTimeMillis() / 1000)); + } + try { executeWithRetry(new Command() { @Override Index: metastore/if/hive_metastore.thrift =================================================================== --- metastore/if/hive_metastore.thrift (revision 10036) +++ metastore/if/hive_metastore.thrift (working copy) @@ -178,6 +178,7 @@ // sd.inputFormat (SequenceFileInputFormat (binary like falcon tables or u_full) or TextInputFormat) // sd.outputFormat (SequenceFileInputFormat (binary) or TextInputFormat) // sd.serdeInfo.serializationLib (SerDe class name eg org.apache.hadoop.hive.serde.simple_meta.MetadataTypedColumnsetSerDe + // * See notes on DDL_TIME void create_table(1:Table tbl) throws(1:AlreadyExistsException o1, 2:InvalidObjectException o2, 3:MetaException o3, 4:NoSuchObjectException o4) // drops the table and all the partitions associated with it if the table has partitions // delete data (including partitions) if deleteData is set to true @@ -189,10 +190,12 @@ Table get_table(1:string dbname, 2:string tbl_name) throws (1:MetaException o1, 2:NoSuchObjectException o2) // alter table applies to only future partitions not for existing partitions + // * See notes on DDL_TIME void alter_table(1:string dbname, 2:string tbl_name, 3:Table new_tbl) throws (1:InvalidOperationException o1, 2:MetaException o2) // the following applies to only tables that have partitions + // * See notes on DDL_TIME Partition add_partition(1:Partition new_part) throws(1:InvalidObjectException o1, 2:AlreadyExistsException o2, 3:MetaException o3) Partition append_partition(1:string db_name, 2:string tbl_name, 3:list part_vals) @@ -235,6 +238,7 @@ // changes the partition to the new partition object. partition is identified from the part values // in the new_part + // * See notes on DDL_TIME void alter_partition(1:string db_name, 2:string tbl_name, 3:Partition new_part) throws(1:InvalidOperationException o1, 2:MetaException o2) @@ -267,6 +271,9 @@ throws(1:MetaException o2) } +// * Note about the DDL_TIME: When creating or altering a table or a partition, +// if the DDL_TIME is not set, the current time will be used. + // For storing info about archived partitions in parameters // Whether the partition is archived Index: ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java (revision 10036) +++ ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java (working copy) @@ -54,6 +54,7 @@ import org.apache.hadoop.hive.metastore.TableType; import org.apache.hadoop.hive.metastore.Warehouse; import org.apache.hadoop.hive.metastore.api.AlreadyExistsException; +import org.apache.hadoop.hive.metastore.api.Constants; import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.metastore.api.Index; @@ -336,6 +337,10 @@ public void alterTable(String tblName, Table newTbl) throws InvalidOperationException, HiveException { try { + // Remove the DDL_TIME so it gets refreshed + if (newTbl.getParameters() != null) { + newTbl.getParameters().remove(Constants.DDL_TIME); + } getMSC().alter_table(getCurrentDatabase(), tblName, newTbl.getTTable()); } catch (MetaException e) { throw new HiveException("Unable to alter table.", e); @@ -358,6 +363,10 @@ public void alterPartition(String tblName, Partition newPart) throws InvalidOperationException, HiveException { try { + // Remove the DDL time so that it gets refreshed + if (newPart.getParameters() != null) { + newPart.getParameters().remove(Constants.DDL_TIME); + } getMSC().alter_partition(getCurrentDatabase(), tblName, newPart.getTPartition()); @@ -398,6 +407,9 @@ tbl.getDeserializer())); } tbl.checkValidity(); + if (tbl.getParameters() != null) { + tbl.getParameters().remove(Constants.DDL_TIME); + } getMSC().createTable(tbl.getTTable()); } catch (AlreadyExistsException e) { if (!ifNotExists) { @@ -1087,6 +1099,8 @@ try { Partition tmpPart = new Partition(tbl, partSpec, location); + // No need to clear DDL_TIME in parameters since we know it's + // not populated on construction. partition = getMSC().add_partition(tmpPart.getTPartition()); } catch (Exception e) { LOG.error(StringUtils.stringifyException(e));