commit 49d2ffc01d66d35ab42c74aaa5611f904bc903b6 Author: Vihang Karajgaonkar Date: Thu Jan 3 10:56:05 2019 -0800 HIVE-21077 : Database and Catalogs should have creation time (Vihang Karajgaonkar reviewed by Karthik Manamcheri and Bharath Krishna) diff --git a/standalone-metastore/src/gen/thrift/gen-cpp/hive_metastore_types.cpp b/standalone-metastore/src/gen/thrift/gen-cpp/hive_metastore_types.cpp index 26420ddf4ca776979eb639dfe5731a06dce6f9a3..b848718bd9a2b049365dc796ce8cf3d3d30d6a94 100644 --- a/standalone-metastore/src/gen/thrift/gen-cpp/hive_metastore_types.cpp +++ b/standalone-metastore/src/gen/thrift/gen-cpp/hive_metastore_types.cpp @@ -4456,6 +4456,11 @@ void Catalog::__set_locationUri(const std::string& val) { this->locationUri = val; } +void Catalog::__set_createTime(const int32_t val) { + this->createTime = val; +__isset.createTime = true; +} + uint32_t Catalog::read(::apache::thrift::protocol::TProtocol* iprot) { apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); @@ -4501,6 +4506,14 @@ uint32_t Catalog::read(::apache::thrift::protocol::TProtocol* iprot) { xfer += iprot->skip(ftype); } break; + case 4: + if (ftype == ::apache::thrift::protocol::T_I32) { + xfer += iprot->readI32(this->createTime); + this->__isset.createTime = true; + } else { + xfer += iprot->skip(ftype); + } + break; default: xfer += iprot->skip(ftype); break; @@ -4531,6 +4544,11 @@ uint32_t Catalog::write(::apache::thrift::protocol::TProtocol* oprot) const { xfer += oprot->writeString(this->locationUri); xfer += oprot->writeFieldEnd(); + if (this->__isset.createTime) { + xfer += oprot->writeFieldBegin("createTime", ::apache::thrift::protocol::T_I32, 4); + xfer += oprot->writeI32(this->createTime); + xfer += oprot->writeFieldEnd(); + } xfer += oprot->writeFieldStop(); xfer += oprot->writeStructEnd(); return xfer; @@ -4541,6 +4559,7 @@ void swap(Catalog &a, Catalog &b) { swap(a.name, b.name); swap(a.description, b.description); swap(a.locationUri, b.locationUri); + swap(a.createTime, b.createTime); swap(a.__isset, b.__isset); } @@ -4548,12 +4567,14 @@ Catalog::Catalog(const Catalog& other130) { name = other130.name; description = other130.description; locationUri = other130.locationUri; + createTime = other130.createTime; __isset = other130.__isset; } Catalog& Catalog::operator=(const Catalog& other131) { name = other131.name; description = other131.description; locationUri = other131.locationUri; + createTime = other131.createTime; __isset = other131.__isset; return *this; } @@ -4563,6 +4584,7 @@ void Catalog::printTo(std::ostream& out) const { out << "name=" << to_string(name); out << ", " << "description="; (__isset.description ? (out << to_string(description)) : (out << "")); out << ", " << "locationUri=" << to_string(locationUri); + out << ", " << "createTime="; (__isset.createTime ? (out << to_string(createTime)) : (out << "")); out << ")"; } @@ -5163,6 +5185,11 @@ void Database::__set_catalogName(const std::string& val) { __isset.catalogName = true; } +void Database::__set_createTime(const int32_t val) { + this->createTime = val; +__isset.createTime = true; +} + uint32_t Database::read(::apache::thrift::protocol::TProtocol* iprot) { apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); @@ -5265,6 +5292,14 @@ uint32_t Database::read(::apache::thrift::protocol::TProtocol* iprot) { xfer += iprot->skip(ftype); } break; + case 9: + if (ftype == ::apache::thrift::protocol::T_I32) { + xfer += iprot->readI32(this->createTime); + this->__isset.createTime = true; + } else { + xfer += iprot->skip(ftype); + } + break; default: xfer += iprot->skip(ftype); break; @@ -5327,6 +5362,11 @@ uint32_t Database::write(::apache::thrift::protocol::TProtocol* oprot) const { xfer += oprot->writeString(this->catalogName); xfer += oprot->writeFieldEnd(); } + if (this->__isset.createTime) { + xfer += oprot->writeFieldBegin("createTime", ::apache::thrift::protocol::T_I32, 9); + xfer += oprot->writeI32(this->createTime); + xfer += oprot->writeFieldEnd(); + } xfer += oprot->writeFieldStop(); xfer += oprot->writeStructEnd(); return xfer; @@ -5342,6 +5382,7 @@ void swap(Database &a, Database &b) { swap(a.ownerName, b.ownerName); swap(a.ownerType, b.ownerType); swap(a.catalogName, b.catalogName); + swap(a.createTime, b.createTime); swap(a.__isset, b.__isset); } @@ -5354,6 +5395,7 @@ Database::Database(const Database& other159) { ownerName = other159.ownerName; ownerType = other159.ownerType; catalogName = other159.catalogName; + createTime = other159.createTime; __isset = other159.__isset; } Database& Database::operator=(const Database& other160) { @@ -5365,6 +5407,7 @@ Database& Database::operator=(const Database& other160) { ownerName = other160.ownerName; ownerType = other160.ownerType; catalogName = other160.catalogName; + createTime = other160.createTime; __isset = other160.__isset; return *this; } @@ -5379,6 +5422,7 @@ void Database::printTo(std::ostream& out) const { out << ", " << "ownerName="; (__isset.ownerName ? (out << to_string(ownerName)) : (out << "")); out << ", " << "ownerType="; (__isset.ownerType ? (out << to_string(ownerType)) : (out << "")); out << ", " << "catalogName="; (__isset.catalogName ? (out << to_string(catalogName)) : (out << "")); + out << ", " << "createTime="; (__isset.createTime ? (out << to_string(createTime)) : (out << "")); out << ")"; } diff --git a/standalone-metastore/src/gen/thrift/gen-cpp/hive_metastore_types.h b/standalone-metastore/src/gen/thrift/gen-cpp/hive_metastore_types.h index d0c299b8b03da34e4bc5475f89eba549cf50c372..a4e36d2a0270040c55bb1dc9dc8d27337053a65c 100644 --- a/standalone-metastore/src/gen/thrift/gen-cpp/hive_metastore_types.h +++ b/standalone-metastore/src/gen/thrift/gen-cpp/hive_metastore_types.h @@ -2353,10 +2353,11 @@ inline std::ostream& operator<<(std::ostream& out, const GrantRevokeRoleResponse } typedef struct _Catalog__isset { - _Catalog__isset() : name(false), description(false), locationUri(false) {} + _Catalog__isset() : name(false), description(false), locationUri(false), createTime(false) {} bool name :1; bool description :1; bool locationUri :1; + bool createTime :1; } _Catalog__isset; class Catalog { @@ -2364,13 +2365,14 @@ class Catalog { Catalog(const Catalog&); Catalog& operator=(const Catalog&); - Catalog() : name(), description(), locationUri() { + Catalog() : name(), description(), locationUri(), createTime(0) { } virtual ~Catalog() throw(); std::string name; std::string description; std::string locationUri; + int32_t createTime; _Catalog__isset __isset; @@ -2380,6 +2382,8 @@ class Catalog { void __set_locationUri(const std::string& val); + void __set_createTime(const int32_t val); + bool operator == (const Catalog & rhs) const { if (!(name == rhs.name)) @@ -2390,6 +2394,10 @@ class Catalog { return false; if (!(locationUri == rhs.locationUri)) return false; + if (__isset.createTime != rhs.__isset.createTime) + return false; + else if (__isset.createTime && !(createTime == rhs.createTime)) + return false; return true; } bool operator != (const Catalog &rhs) const { @@ -2695,7 +2703,7 @@ inline std::ostream& operator<<(std::ostream& out, const DropCatalogRequest& obj } typedef struct _Database__isset { - _Database__isset() : name(false), description(false), locationUri(false), parameters(false), privileges(false), ownerName(false), ownerType(false), catalogName(false) {} + _Database__isset() : name(false), description(false), locationUri(false), parameters(false), privileges(false), ownerName(false), ownerType(false), catalogName(false), createTime(false) {} bool name :1; bool description :1; bool locationUri :1; @@ -2704,6 +2712,7 @@ typedef struct _Database__isset { bool ownerName :1; bool ownerType :1; bool catalogName :1; + bool createTime :1; } _Database__isset; class Database { @@ -2711,7 +2720,7 @@ class Database { Database(const Database&); Database& operator=(const Database&); - Database() : name(), description(), locationUri(), ownerName(), ownerType((PrincipalType::type)0), catalogName() { + Database() : name(), description(), locationUri(), ownerName(), ownerType((PrincipalType::type)0), catalogName(), createTime(0) { } virtual ~Database() throw(); @@ -2723,6 +2732,7 @@ class Database { std::string ownerName; PrincipalType::type ownerType; std::string catalogName; + int32_t createTime; _Database__isset __isset; @@ -2742,6 +2752,8 @@ class Database { void __set_catalogName(const std::string& val); + void __set_createTime(const int32_t val); + bool operator == (const Database & rhs) const { if (!(name == rhs.name)) @@ -2768,6 +2780,10 @@ class Database { return false; else if (__isset.catalogName && !(catalogName == rhs.catalogName)) return false; + if (__isset.createTime != rhs.__isset.createTime) + return false; + else if (__isset.createTime && !(createTime == rhs.createTime)) + return false; return true; } bool operator != (const Database &rhs) const { diff --git a/standalone-metastore/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/Catalog.java b/standalone-metastore/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/Catalog.java index 3eb4dbd51110dd6e5d04c3bdacde2e5bdba09a7c..3e968dcc5dc3dcc1499e5c1e2baabe06d8e4f833 100644 --- a/standalone-metastore/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/Catalog.java +++ b/standalone-metastore/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/Catalog.java @@ -41,6 +41,7 @@ private static final org.apache.thrift.protocol.TField NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("name", org.apache.thrift.protocol.TType.STRING, (short)1); private static final org.apache.thrift.protocol.TField DESCRIPTION_FIELD_DESC = new org.apache.thrift.protocol.TField("description", org.apache.thrift.protocol.TType.STRING, (short)2); private static final org.apache.thrift.protocol.TField LOCATION_URI_FIELD_DESC = new org.apache.thrift.protocol.TField("locationUri", org.apache.thrift.protocol.TType.STRING, (short)3); + private static final org.apache.thrift.protocol.TField CREATE_TIME_FIELD_DESC = new org.apache.thrift.protocol.TField("createTime", org.apache.thrift.protocol.TType.I32, (short)4); private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); static { @@ -51,12 +52,14 @@ private String name; // required private String description; // optional private String locationUri; // required + private int createTime; // optional /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ public enum _Fields implements org.apache.thrift.TFieldIdEnum { NAME((short)1, "name"), DESCRIPTION((short)2, "description"), - LOCATION_URI((short)3, "locationUri"); + LOCATION_URI((short)3, "locationUri"), + CREATE_TIME((short)4, "createTime"); private static final Map byName = new HashMap(); @@ -77,6 +80,8 @@ public static _Fields findByThriftId(int fieldId) { return DESCRIPTION; case 3: // LOCATION_URI return LOCATION_URI; + case 4: // CREATE_TIME + return CREATE_TIME; default: return null; } @@ -117,7 +122,9 @@ public String getFieldName() { } // isset id assignments - private static final _Fields optionals[] = {_Fields.DESCRIPTION}; + private static final int __CREATETIME_ISSET_ID = 0; + private byte __isset_bitfield = 0; + private static final _Fields optionals[] = {_Fields.DESCRIPTION,_Fields.CREATE_TIME}; public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); @@ -127,6 +134,8 @@ public String getFieldName() { new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); tmpMap.put(_Fields.LOCATION_URI, new org.apache.thrift.meta_data.FieldMetaData("locationUri", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.CREATE_TIME, new org.apache.thrift.meta_data.FieldMetaData("createTime", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Catalog.class, metaDataMap); } @@ -147,6 +156,7 @@ public Catalog( * Performs a deep copy on other. */ public Catalog(Catalog other) { + __isset_bitfield = other.__isset_bitfield; if (other.isSetName()) { this.name = other.name; } @@ -156,6 +166,7 @@ public Catalog(Catalog other) { if (other.isSetLocationUri()) { this.locationUri = other.locationUri; } + this.createTime = other.createTime; } public Catalog deepCopy() { @@ -167,6 +178,8 @@ public void clear() { this.name = null; this.description = null; this.locationUri = null; + setCreateTimeIsSet(false); + this.createTime = 0; } public String getName() { @@ -238,6 +251,28 @@ public void setLocationUriIsSet(boolean value) { } } + public int getCreateTime() { + return this.createTime; + } + + public void setCreateTime(int createTime) { + this.createTime = createTime; + setCreateTimeIsSet(true); + } + + public void unsetCreateTime() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __CREATETIME_ISSET_ID); + } + + /** Returns true if field createTime is set (has been assigned a value) and false otherwise */ + public boolean isSetCreateTime() { + return EncodingUtils.testBit(__isset_bitfield, __CREATETIME_ISSET_ID); + } + + public void setCreateTimeIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __CREATETIME_ISSET_ID, value); + } + public void setFieldValue(_Fields field, Object value) { switch (field) { case NAME: @@ -264,6 +299,14 @@ public void setFieldValue(_Fields field, Object value) { } break; + case CREATE_TIME: + if (value == null) { + unsetCreateTime(); + } else { + setCreateTime((Integer)value); + } + break; + } } @@ -278,6 +321,9 @@ public Object getFieldValue(_Fields field) { case LOCATION_URI: return getLocationUri(); + case CREATE_TIME: + return getCreateTime(); + } throw new IllegalStateException(); } @@ -295,6 +341,8 @@ public boolean isSet(_Fields field) { return isSetDescription(); case LOCATION_URI: return isSetLocationUri(); + case CREATE_TIME: + return isSetCreateTime(); } throw new IllegalStateException(); } @@ -339,6 +387,15 @@ public boolean equals(Catalog that) { return false; } + boolean this_present_createTime = true && this.isSetCreateTime(); + boolean that_present_createTime = true && that.isSetCreateTime(); + if (this_present_createTime || that_present_createTime) { + if (!(this_present_createTime && that_present_createTime)) + return false; + if (this.createTime != that.createTime) + return false; + } + return true; } @@ -361,6 +418,11 @@ public int hashCode() { if (present_locationUri) list.add(locationUri); + boolean present_createTime = true && (isSetCreateTime()); + list.add(present_createTime); + if (present_createTime) + list.add(createTime); + return list.hashCode(); } @@ -402,6 +464,16 @@ public int compareTo(Catalog other) { return lastComparison; } } + lastComparison = Boolean.valueOf(isSetCreateTime()).compareTo(other.isSetCreateTime()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCreateTime()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.createTime, other.createTime); + if (lastComparison != 0) { + return lastComparison; + } + } return 0; } @@ -447,6 +519,12 @@ public String toString() { sb.append(this.locationUri); } first = false; + if (isSetCreateTime()) { + if (!first) sb.append(", "); + sb.append("createTime:"); + sb.append(this.createTime); + first = false; + } sb.append(")"); return sb.toString(); } @@ -466,6 +544,8 @@ private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOExcept private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); @@ -514,6 +594,14 @@ public void read(org.apache.thrift.protocol.TProtocol iprot, Catalog struct) thr org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; + case 4: // CREATE_TIME + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.createTime = iprot.readI32(); + struct.setCreateTimeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; default: org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } @@ -544,6 +632,11 @@ public void write(org.apache.thrift.protocol.TProtocol oprot, Catalog struct) th oprot.writeString(struct.locationUri); oprot.writeFieldEnd(); } + if (struct.isSetCreateTime()) { + oprot.writeFieldBegin(CREATE_TIME_FIELD_DESC); + oprot.writeI32(struct.createTime); + oprot.writeFieldEnd(); + } oprot.writeFieldStop(); oprot.writeStructEnd(); } @@ -571,7 +664,10 @@ public void write(org.apache.thrift.protocol.TProtocol prot, Catalog struct) thr if (struct.isSetLocationUri()) { optionals.set(2); } - oprot.writeBitSet(optionals, 3); + if (struct.isSetCreateTime()) { + optionals.set(3); + } + oprot.writeBitSet(optionals, 4); if (struct.isSetName()) { oprot.writeString(struct.name); } @@ -581,12 +677,15 @@ public void write(org.apache.thrift.protocol.TProtocol prot, Catalog struct) thr if (struct.isSetLocationUri()) { oprot.writeString(struct.locationUri); } + if (struct.isSetCreateTime()) { + oprot.writeI32(struct.createTime); + } } @Override public void read(org.apache.thrift.protocol.TProtocol prot, Catalog struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; - BitSet incoming = iprot.readBitSet(3); + BitSet incoming = iprot.readBitSet(4); if (incoming.get(0)) { struct.name = iprot.readString(); struct.setNameIsSet(true); @@ -599,6 +698,10 @@ public void read(org.apache.thrift.protocol.TProtocol prot, Catalog struct) thro struct.locationUri = iprot.readString(); struct.setLocationUriIsSet(true); } + if (incoming.get(3)) { + struct.createTime = iprot.readI32(); + struct.setCreateTimeIsSet(true); + } } } diff --git a/standalone-metastore/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/Database.java b/standalone-metastore/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/Database.java index 9cde9b869965ea43f29613c05a7bdef94ffe73a3..80f7d999c8d3dfa088ce52ba4649127a08f2c157 100644 --- a/standalone-metastore/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/Database.java +++ b/standalone-metastore/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/Database.java @@ -46,6 +46,7 @@ private static final org.apache.thrift.protocol.TField OWNER_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("ownerName", org.apache.thrift.protocol.TType.STRING, (short)6); private static final org.apache.thrift.protocol.TField OWNER_TYPE_FIELD_DESC = new org.apache.thrift.protocol.TField("ownerType", org.apache.thrift.protocol.TType.I32, (short)7); private static final org.apache.thrift.protocol.TField CATALOG_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("catalogName", org.apache.thrift.protocol.TType.STRING, (short)8); + private static final org.apache.thrift.protocol.TField CREATE_TIME_FIELD_DESC = new org.apache.thrift.protocol.TField("createTime", org.apache.thrift.protocol.TType.I32, (short)9); private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); static { @@ -61,6 +62,7 @@ private String ownerName; // optional private PrincipalType ownerType; // optional private String catalogName; // optional + private int createTime; // optional /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ public enum _Fields implements org.apache.thrift.TFieldIdEnum { @@ -75,7 +77,8 @@ * @see PrincipalType */ OWNER_TYPE((short)7, "ownerType"), - CATALOG_NAME((short)8, "catalogName"); + CATALOG_NAME((short)8, "catalogName"), + CREATE_TIME((short)9, "createTime"); private static final Map byName = new HashMap(); @@ -106,6 +109,8 @@ public static _Fields findByThriftId(int fieldId) { return OWNER_TYPE; case 8: // CATALOG_NAME return CATALOG_NAME; + case 9: // CREATE_TIME + return CREATE_TIME; default: return null; } @@ -146,7 +151,9 @@ public String getFieldName() { } // isset id assignments - private static final _Fields optionals[] = {_Fields.PRIVILEGES,_Fields.OWNER_NAME,_Fields.OWNER_TYPE,_Fields.CATALOG_NAME}; + private static final int __CREATETIME_ISSET_ID = 0; + private byte __isset_bitfield = 0; + private static final _Fields optionals[] = {_Fields.PRIVILEGES,_Fields.OWNER_NAME,_Fields.OWNER_TYPE,_Fields.CATALOG_NAME,_Fields.CREATE_TIME}; public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); @@ -168,6 +175,8 @@ public String getFieldName() { new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, PrincipalType.class))); tmpMap.put(_Fields.CATALOG_NAME, new org.apache.thrift.meta_data.FieldMetaData("catalogName", org.apache.thrift.TFieldRequirementType.OPTIONAL, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.CREATE_TIME, new org.apache.thrift.meta_data.FieldMetaData("createTime", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Database.class, metaDataMap); } @@ -192,6 +201,7 @@ public Database( * Performs a deep copy on other. */ public Database(Database other) { + __isset_bitfield = other.__isset_bitfield; if (other.isSetName()) { this.name = other.name; } @@ -217,6 +227,7 @@ public Database(Database other) { if (other.isSetCatalogName()) { this.catalogName = other.catalogName; } + this.createTime = other.createTime; } public Database deepCopy() { @@ -233,6 +244,8 @@ public void clear() { this.ownerName = null; this.ownerType = null; this.catalogName = null; + setCreateTimeIsSet(false); + this.createTime = 0; } public String getName() { @@ -438,6 +451,28 @@ public void setCatalogNameIsSet(boolean value) { } } + public int getCreateTime() { + return this.createTime; + } + + public void setCreateTime(int createTime) { + this.createTime = createTime; + setCreateTimeIsSet(true); + } + + public void unsetCreateTime() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __CREATETIME_ISSET_ID); + } + + /** Returns true if field createTime is set (has been assigned a value) and false otherwise */ + public boolean isSetCreateTime() { + return EncodingUtils.testBit(__isset_bitfield, __CREATETIME_ISSET_ID); + } + + public void setCreateTimeIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __CREATETIME_ISSET_ID, value); + } + public void setFieldValue(_Fields field, Object value) { switch (field) { case NAME: @@ -504,6 +539,14 @@ public void setFieldValue(_Fields field, Object value) { } break; + case CREATE_TIME: + if (value == null) { + unsetCreateTime(); + } else { + setCreateTime((Integer)value); + } + break; + } } @@ -533,6 +576,9 @@ public Object getFieldValue(_Fields field) { case CATALOG_NAME: return getCatalogName(); + case CREATE_TIME: + return getCreateTime(); + } throw new IllegalStateException(); } @@ -560,6 +606,8 @@ public boolean isSet(_Fields field) { return isSetOwnerType(); case CATALOG_NAME: return isSetCatalogName(); + case CREATE_TIME: + return isSetCreateTime(); } throw new IllegalStateException(); } @@ -649,6 +697,15 @@ public boolean equals(Database that) { return false; } + boolean this_present_createTime = true && this.isSetCreateTime(); + boolean that_present_createTime = true && that.isSetCreateTime(); + if (this_present_createTime || that_present_createTime) { + if (!(this_present_createTime && that_present_createTime)) + return false; + if (this.createTime != that.createTime) + return false; + } + return true; } @@ -696,6 +753,11 @@ public int hashCode() { if (present_catalogName) list.add(catalogName); + boolean present_createTime = true && (isSetCreateTime()); + list.add(present_createTime); + if (present_createTime) + list.add(createTime); + return list.hashCode(); } @@ -787,6 +849,16 @@ public int compareTo(Database other) { return lastComparison; } } + lastComparison = Boolean.valueOf(isSetCreateTime()).compareTo(other.isSetCreateTime()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCreateTime()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.createTime, other.createTime); + if (lastComparison != 0) { + return lastComparison; + } + } return 0; } @@ -878,6 +950,12 @@ public String toString() { } first = false; } + if (isSetCreateTime()) { + if (!first) sb.append(", "); + sb.append("createTime:"); + sb.append(this.createTime); + first = false; + } sb.append(")"); return sb.toString(); } @@ -900,6 +978,8 @@ private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOExcept private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); @@ -1001,6 +1081,14 @@ public void read(org.apache.thrift.protocol.TProtocol iprot, Database struct) th org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; + case 9: // CREATE_TIME + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.createTime = iprot.readI32(); + struct.setCreateTimeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; default: org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } @@ -1070,6 +1158,11 @@ public void write(org.apache.thrift.protocol.TProtocol oprot, Database struct) t oprot.writeFieldEnd(); } } + if (struct.isSetCreateTime()) { + oprot.writeFieldBegin(CREATE_TIME_FIELD_DESC); + oprot.writeI32(struct.createTime); + oprot.writeFieldEnd(); + } oprot.writeFieldStop(); oprot.writeStructEnd(); } @@ -1112,7 +1205,10 @@ public void write(org.apache.thrift.protocol.TProtocol prot, Database struct) th if (struct.isSetCatalogName()) { optionals.set(7); } - oprot.writeBitSet(optionals, 8); + if (struct.isSetCreateTime()) { + optionals.set(8); + } + oprot.writeBitSet(optionals, 9); if (struct.isSetName()) { oprot.writeString(struct.name); } @@ -1144,12 +1240,15 @@ public void write(org.apache.thrift.protocol.TProtocol prot, Database struct) th if (struct.isSetCatalogName()) { oprot.writeString(struct.catalogName); } + if (struct.isSetCreateTime()) { + oprot.writeI32(struct.createTime); + } } @Override public void read(org.apache.thrift.protocol.TProtocol prot, Database struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; - BitSet incoming = iprot.readBitSet(8); + BitSet incoming = iprot.readBitSet(9); if (incoming.get(0)) { struct.name = iprot.readString(); struct.setNameIsSet(true); @@ -1194,6 +1293,10 @@ public void read(org.apache.thrift.protocol.TProtocol prot, Database struct) thr struct.catalogName = iprot.readString(); struct.setCatalogNameIsSet(true); } + if (incoming.get(8)) { + struct.createTime = iprot.readI32(); + struct.setCreateTimeIsSet(true); + } } } diff --git a/standalone-metastore/src/gen/thrift/gen-php/metastore/Types.php b/standalone-metastore/src/gen/thrift/gen-php/metastore/Types.php index ae12471afea9db93ba1458006a6e76ab6a49c5fc..bd84cf7c7be5a054149f2e978de2ca196a2c2198 100644 --- a/standalone-metastore/src/gen/thrift/gen-php/metastore/Types.php +++ b/standalone-metastore/src/gen/thrift/gen-php/metastore/Types.php @@ -4495,6 +4495,10 @@ class Catalog { * @var string */ public $locationUri = null; + /** + * @var int + */ + public $createTime = null; public function __construct($vals=null) { if (!isset(self::$_TSPEC)) { @@ -4511,6 +4515,10 @@ class Catalog { 'var' => 'locationUri', 'type' => TType::STRING, ), + 4 => array( + 'var' => 'createTime', + 'type' => TType::I32, + ), ); } if (is_array($vals)) { @@ -4523,6 +4531,9 @@ class Catalog { if (isset($vals['locationUri'])) { $this->locationUri = $vals['locationUri']; } + if (isset($vals['createTime'])) { + $this->createTime = $vals['createTime']; + } } } @@ -4566,6 +4577,13 @@ class Catalog { $xfer += $input->skip($ftype); } break; + case 4: + if ($ftype == TType::I32) { + $xfer += $input->readI32($this->createTime); + } else { + $xfer += $input->skip($ftype); + } + break; default: $xfer += $input->skip($ftype); break; @@ -4594,6 +4612,11 @@ class Catalog { $xfer += $output->writeString($this->locationUri); $xfer += $output->writeFieldEnd(); } + if ($this->createTime !== null) { + $xfer += $output->writeFieldBegin('createTime', TType::I32, 4); + $xfer += $output->writeI32($this->createTime); + $xfer += $output->writeFieldEnd(); + } $xfer += $output->writeFieldStop(); $xfer += $output->writeStructEnd(); return $xfer; @@ -5150,6 +5173,10 @@ class Database { * @var string */ public $catalogName = null; + /** + * @var int + */ + public $createTime = null; public function __construct($vals=null) { if (!isset(self::$_TSPEC)) { @@ -5195,6 +5222,10 @@ class Database { 'var' => 'catalogName', 'type' => TType::STRING, ), + 9 => array( + 'var' => 'createTime', + 'type' => TType::I32, + ), ); } if (is_array($vals)) { @@ -5222,6 +5253,9 @@ class Database { if (isset($vals['catalogName'])) { $this->catalogName = $vals['catalogName']; } + if (isset($vals['createTime'])) { + $this->createTime = $vals['createTime']; + } } } @@ -5314,6 +5348,13 @@ class Database { $xfer += $input->skip($ftype); } break; + case 9: + if ($ftype == TType::I32) { + $xfer += $input->readI32($this->createTime); + } else { + $xfer += $input->skip($ftype); + } + break; default: $xfer += $input->skip($ftype); break; @@ -5383,6 +5424,11 @@ class Database { $xfer += $output->writeString($this->catalogName); $xfer += $output->writeFieldEnd(); } + if ($this->createTime !== null) { + $xfer += $output->writeFieldBegin('createTime', TType::I32, 9); + $xfer += $output->writeI32($this->createTime); + $xfer += $output->writeFieldEnd(); + } $xfer += $output->writeFieldStop(); $xfer += $output->writeStructEnd(); return $xfer; diff --git a/standalone-metastore/src/gen/thrift/gen-py/hive_metastore/ttypes.py b/standalone-metastore/src/gen/thrift/gen-py/hive_metastore/ttypes.py index 1285c086c935f1b44a77b485fbea47676d0d8bdc..583f7de3c5774c101c68362836dbcb9a51048d43 100644 --- a/standalone-metastore/src/gen/thrift/gen-py/hive_metastore/ttypes.py +++ b/standalone-metastore/src/gen/thrift/gen-py/hive_metastore/ttypes.py @@ -3253,6 +3253,7 @@ class Catalog: - name - description - locationUri + - createTime """ thrift_spec = ( @@ -3260,12 +3261,14 @@ class Catalog: (1, TType.STRING, 'name', None, None, ), # 1 (2, TType.STRING, 'description', None, None, ), # 2 (3, TType.STRING, 'locationUri', None, None, ), # 3 + (4, TType.I32, 'createTime', None, None, ), # 4 ) - def __init__(self, name=None, description=None, locationUri=None,): + def __init__(self, name=None, description=None, locationUri=None, createTime=None,): self.name = name self.description = description self.locationUri = locationUri + self.createTime = createTime def read(self, iprot): if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None: @@ -3291,6 +3294,11 @@ def read(self, iprot): self.locationUri = iprot.readString() else: iprot.skip(ftype) + elif fid == 4: + if ftype == TType.I32: + self.createTime = iprot.readI32() + else: + iprot.skip(ftype) else: iprot.skip(ftype) iprot.readFieldEnd() @@ -3313,6 +3321,10 @@ def write(self, oprot): oprot.writeFieldBegin('locationUri', TType.STRING, 3) oprot.writeString(self.locationUri) oprot.writeFieldEnd() + if self.createTime is not None: + oprot.writeFieldBegin('createTime', TType.I32, 4) + oprot.writeI32(self.createTime) + oprot.writeFieldEnd() oprot.writeFieldStop() oprot.writeStructEnd() @@ -3325,6 +3337,7 @@ def __hash__(self): value = (value * 31) ^ hash(self.name) value = (value * 31) ^ hash(self.description) value = (value * 31) ^ hash(self.locationUri) + value = (value * 31) ^ hash(self.createTime) return value def __repr__(self): @@ -3763,6 +3776,7 @@ class Database: - ownerName - ownerType - catalogName + - createTime """ thrift_spec = ( @@ -3775,9 +3789,10 @@ class Database: (6, TType.STRING, 'ownerName', None, None, ), # 6 (7, TType.I32, 'ownerType', None, None, ), # 7 (8, TType.STRING, 'catalogName', None, None, ), # 8 + (9, TType.I32, 'createTime', None, None, ), # 9 ) - def __init__(self, name=None, description=None, locationUri=None, parameters=None, privileges=None, ownerName=None, ownerType=None, catalogName=None,): + def __init__(self, name=None, description=None, locationUri=None, parameters=None, privileges=None, ownerName=None, ownerType=None, catalogName=None, createTime=None,): self.name = name self.description = description self.locationUri = locationUri @@ -3786,6 +3801,7 @@ def __init__(self, name=None, description=None, locationUri=None, parameters=Non self.ownerName = ownerName self.ownerType = ownerType self.catalogName = catalogName + self.createTime = createTime def read(self, iprot): if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None: @@ -3843,6 +3859,11 @@ def read(self, iprot): self.catalogName = iprot.readString() else: iprot.skip(ftype) + elif fid == 9: + if ftype == TType.I32: + self.createTime = iprot.readI32() + else: + iprot.skip(ftype) else: iprot.skip(ftype) iprot.readFieldEnd() @@ -3889,6 +3910,10 @@ def write(self, oprot): oprot.writeFieldBegin('catalogName', TType.STRING, 8) oprot.writeString(self.catalogName) oprot.writeFieldEnd() + if self.createTime is not None: + oprot.writeFieldBegin('createTime', TType.I32, 9) + oprot.writeI32(self.createTime) + oprot.writeFieldEnd() oprot.writeFieldStop() oprot.writeStructEnd() @@ -3906,6 +3931,7 @@ def __hash__(self): value = (value * 31) ^ hash(self.ownerName) value = (value * 31) ^ hash(self.ownerType) value = (value * 31) ^ hash(self.catalogName) + value = (value * 31) ^ hash(self.createTime) return value def __repr__(self): diff --git a/standalone-metastore/src/gen/thrift/gen-rb/hive_metastore_types.rb b/standalone-metastore/src/gen/thrift/gen-rb/hive_metastore_types.rb index a0fabfe7813c7bff182a237169164d053a73b154..2ef68207da447a2dcc475aab3b64df69dddd17f4 100644 --- a/standalone-metastore/src/gen/thrift/gen-rb/hive_metastore_types.rb +++ b/standalone-metastore/src/gen/thrift/gen-rb/hive_metastore_types.rb @@ -789,11 +789,13 @@ class Catalog NAME = 1 DESCRIPTION = 2 LOCATIONURI = 3 + CREATETIME = 4 FIELDS = { NAME => {:type => ::Thrift::Types::STRING, :name => 'name'}, DESCRIPTION => {:type => ::Thrift::Types::STRING, :name => 'description', :optional => true}, - LOCATIONURI => {:type => ::Thrift::Types::STRING, :name => 'locationUri'} + LOCATIONURI => {:type => ::Thrift::Types::STRING, :name => 'locationUri'}, + CREATETIME => {:type => ::Thrift::Types::I32, :name => 'createTime', :optional => true} } def struct_fields; FIELDS; end @@ -912,6 +914,7 @@ class Database OWNERNAME = 6 OWNERTYPE = 7 CATALOGNAME = 8 + CREATETIME = 9 FIELDS = { NAME => {:type => ::Thrift::Types::STRING, :name => 'name'}, @@ -921,7 +924,8 @@ class Database PRIVILEGES => {:type => ::Thrift::Types::STRUCT, :name => 'privileges', :class => ::PrincipalPrivilegeSet, :optional => true}, OWNERNAME => {:type => ::Thrift::Types::STRING, :name => 'ownerName', :optional => true}, OWNERTYPE => {:type => ::Thrift::Types::I32, :name => 'ownerType', :optional => true, :enum_class => ::PrincipalType}, - CATALOGNAME => {:type => ::Thrift::Types::STRING, :name => 'catalogName', :optional => true} + CATALOGNAME => {:type => ::Thrift::Types::STRING, :name => 'catalogName', :optional => true}, + CREATETIME => {:type => ::Thrift::Types::I32, :name => 'createTime', :optional => true} } def struct_fields; FIELDS; end diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index b4f6480a02949c70cc7b5a2b2068ae3f940f011e..40affeff1714eab68800fb2acd191ae5c90097de 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -742,6 +742,8 @@ public static void createDefaultCatalog(RawStore ms, Warehouse wh) throws MetaEx } catch (NoSuchObjectException e) { Catalog cat = new Catalog(DEFAULT_CATALOG_NAME, wh.getWhRoot().toString()); + long time = System.currentTimeMillis() / 1000; + cat.setCreateTime((int) time); cat.setDescription(Warehouse.DEFAULT_CATALOG_COMMENT); ms.createCatalog(cat); } @@ -752,10 +754,12 @@ private void createDefaultDB_core(RawStore ms) throws MetaException, InvalidObje ms.getDatabase(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME); } catch (NoSuchObjectException e) { Database db = new Database(DEFAULT_DATABASE_NAME, DEFAULT_DATABASE_COMMENT, - wh.getDefaultDatabasePath(DEFAULT_DATABASE_NAME).toString(), null); + wh.getDefaultDatabasePath(DEFAULT_DATABASE_NAME).toString(), null); db.setOwnerName(PUBLIC); db.setOwnerType(PrincipalType.ROLE); db.setCatalogName(DEFAULT_CATALOG_NAME); + long time = System.currentTimeMillis() / 1000; + db.setCreateTime((int) time); ms.createDatabase(db); } } @@ -1031,13 +1035,16 @@ public void create_catalog(CreateCatalogRequest rqst) } madeDir = true; } - + // set the create time of catalog + long time = System.currentTimeMillis() / 1000; + catalog.setCreateTime((int) time); ms.openTransaction(); ms.createCatalog(catalog); // Create a default database inside the catalog - Database db = new Database(DEFAULT_DATABASE_NAME, "Default database for catalog " + - catalog.getName(), catalog.getLocationUri(), Collections.emptyMap()); + Database db = new Database(DEFAULT_DATABASE_NAME, + "Default database for catalog " + catalog.getName(), catalog.getLocationUri(), + Collections.emptyMap()); db.setCatalogName(catalog.getName()); create_database_core(ms, db); @@ -1260,7 +1267,8 @@ private void create_database_core(RawStore ms, final Database db) } Path dbPath = wh.determineDatabasePath(cat, db); db.setLocationUri(dbPath.toString()); - + long time = System.currentTimeMillis()/1000; + db.setCreateTime((int) time); boolean success = false; boolean madeDir = false; Map transactionalListenersResponses = Collections.emptyMap(); diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java index c7d28561f8984f69a44d919931b5ec36f333a2ce..5b6a4d345026b9ee828051451971074aba3be99d 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java @@ -323,7 +323,7 @@ public Database getDatabase(String catName, String dbName) throws MetaException{ String queryTextDbSelector= "select " + "\"DB_ID\", \"NAME\", \"DB_LOCATION_URI\", \"DESC\", " - + "\"OWNER_NAME\", \"OWNER_TYPE\", \"CTLG_NAME\" " + + "\"OWNER_NAME\", \"OWNER_TYPE\", \"CTLG_NAME\" , \"CREATE_TIME\"" + "FROM "+ DBS + " where \"NAME\" = ? and \"CTLG_NAME\" = ? "; Object[] params = new Object[] { dbName, catName }; @@ -376,6 +376,7 @@ public Database getDatabase(String catName, String dbName) throws MetaException{ db.setOwnerType( (null == type || type.trim().isEmpty()) ? null : PrincipalType.valueOf(type)); db.setCatalogName(extractSqlString(dbline[6])); + db.setCreateTime(extractSqlInt(dbline[7])); db.setParameters(MetaStoreUtils.trimMapNulls(dbParams,convertMapNullsToEmptyStrings)); if (LOG.isDebugEnabled()){ LOG.debug("getDatabase: directsql returning db " + db.getName() diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java index ccb2ddbae13a03a939306ba110c8c3886625988f..1a4f98b0ad19f245da5870fd8425207f5b590059 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -685,6 +685,7 @@ private MCatalog catToMCat(Catalog cat) { mCat.setDescription(cat.getDescription()); } mCat.setLocationUri(cat.getLocationUri()); + mCat.setCreateTime(cat.getCreateTime()); return mCat; } @@ -693,6 +694,7 @@ private Catalog mCatToCat(MCatalog mCat) { if (mCat.getDescription() != null) { cat.setDescription(mCat.getDescription()); } + cat.setCreateTime(mCat.getCreateTime()); return cat; } @@ -710,6 +712,7 @@ public void createDatabase(Database db) throws InvalidObjectException, MetaExcep mdb.setOwnerName(db.getOwnerName()); PrincipalType ownerType = db.getOwnerType(); mdb.setOwnerType((null == ownerType ? PrincipalType.USER.name() : ownerType.name())); + mdb.setCreateTime(db.getCreateTime()); try { openTransaction(); pm.makePersistent(mdb); @@ -803,6 +806,7 @@ public Database getJDODatabase(String catName, String name) throws NoSuchObjectE PrincipalType principalType = (type == null) ? null : PrincipalType.valueOf(type); db.setOwnerType(principalType); db.setCatalogName(catName); + db.setCreateTime(mdb.getCreateTime()); return db; } diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/client/builder/DatabaseBuilder.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/client/builder/DatabaseBuilder.java index f3d2182a04ab81417a55554ba58d9340721513e8..dcd57c4177b81c1e199be0f1ba1a7dc1d74fa0b2 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/client/builder/DatabaseBuilder.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/client/builder/DatabaseBuilder.java @@ -41,6 +41,7 @@ private Map params = new HashMap<>(); private String ownerName; private PrincipalType ownerType; + private int createTime; public DatabaseBuilder() { } @@ -90,11 +91,17 @@ public DatabaseBuilder setOwnerType(PrincipalType ownerType) { return this; } + public DatabaseBuilder setCreateTime(int createTime) { + this.createTime = createTime; + return this; + } + public Database build(Configuration conf) throws MetaException { if (name == null) throw new MetaException("You must name the database"); if (catalogName == null) catalogName = MetaStoreUtils.getDefaultCatalog(conf); Database db = new Database(name, description, location, params); db.setCatalogName(catalogName); + db.setCreateTime(createTime); try { if (ownerName == null) ownerName = SecurityUtils.getUser(); db.setOwnerName(ownerName); diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/model/MCatalog.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/model/MCatalog.java index e82cb4322f6e2ac7afeb5efcec7517a68c8b2dee..a3ed82f39bf35099840ad97694edd232add536f4 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/model/MCatalog.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/model/MCatalog.java @@ -21,6 +21,7 @@ private String name; private String description; private String locationUri; + private int createTime; public MCatalog() { @@ -55,4 +56,12 @@ public String getLocationUri() { public void setLocationUri(String locationUri) { this.locationUri = locationUri; } + + public int getCreateTime() { + return createTime; + } + + public void setCreateTime(int createTime) { + this.createTime = createTime; + } } diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/model/MDatabase.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/model/MDatabase.java index 815b39c483b2233660310983d58194fb1ab2d107..8901eedb83ce9542cd0971727c5cee0973cf14f7 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/model/MDatabase.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/model/MDatabase.java @@ -40,6 +40,7 @@ private String ownerName; private String ownerType; private String catalogName; + private int createTime; /** * Default construction to keep jpox/jdo happy @@ -154,4 +155,12 @@ public String getCatalogName() { public void setCatalogName(String catalogName) { this.catalogName = catalogName; } + + public int getCreateTime() { + return createTime; + } + + public void setCreateTime(int createTime) { + this.createTime = createTime; + } } diff --git a/standalone-metastore/src/main/resources/package.jdo b/standalone-metastore/src/main/resources/package.jdo index b2350e2f74b561aa4a38f476f965518329cf18a7..cccc6774ce63fb575ebd01c03cfc1ca71e8f5729 100644 --- a/standalone-metastore/src/main/resources/package.jdo +++ b/standalone-metastore/src/main/resources/package.jdo @@ -65,6 +65,10 @@ + + + + @@ -81,6 +85,10 @@ + + + + diff --git a/standalone-metastore/src/main/sql/derby/hive-schema-3.2.0.derby.sql b/standalone-metastore/src/main/sql/derby/hive-schema-3.2.0.derby.sql index 50d0815395161b1c4774414c15845b8980b35cca..9b9745d33e0ddf6843be3a9b667c22d9a725bba5 100644 --- a/standalone-metastore/src/main/sql/derby/hive-schema-3.2.0.derby.sql +++ b/standalone-metastore/src/main/sql/derby/hive-schema-3.2.0.derby.sql @@ -22,7 +22,8 @@ CREATE TABLE "APP"."DBS" ( "NAME" VARCHAR(128), "OWNER_NAME" VARCHAR(128), "OWNER_TYPE" VARCHAR(10), - "CTLG_NAME" VARCHAR(256) NOT NULL + "CTLG_NAME" VARCHAR(256) NOT NULL, + "CREATE_TIME" INTEGER ); CREATE TABLE "APP"."TBL_PRIVS" ("TBL_GRANT_ID" BIGINT NOT NULL, "CREATE_TIME" INTEGER NOT NULL, "GRANT_OPTION" SMALLINT NOT NULL, "GRANTOR" VARCHAR(128), "GRANTOR_TYPE" VARCHAR(128), "PRINCIPAL_NAME" VARCHAR(128), "PRINCIPAL_TYPE" VARCHAR(128), "TBL_PRIV" VARCHAR(128), "TBL_ID" BIGINT, "AUTHORIZER" VARCHAR(128)); @@ -210,7 +211,8 @@ CREATE TABLE "APP"."CTLGS" ( "CTLG_ID" BIGINT NOT NULL, "NAME" VARCHAR(256) UNIQUE, "DESC" VARCHAR(4000), - "LOCATION_URI" VARCHAR(4000) NOT NULL); + "LOCATION_URI" VARCHAR(4000) NOT NULL, + "CREATE_TIME" INTEGER); -- ---------------------------------------------- -- DML Statements diff --git a/standalone-metastore/src/main/sql/derby/upgrade-3.1.0-to-3.2.0.derby.sql b/standalone-metastore/src/main/sql/derby/upgrade-3.1.0-to-3.2.0.derby.sql index 5fcefd66ae7bccbf7c168b176a3550ee6a41154a..1a8b26cce3fb4d46c7f4dcecf7c76305a5d40f32 100644 --- a/standalone-metastore/src/main/sql/derby/upgrade-3.1.0-to-3.2.0.derby.sql +++ b/standalone-metastore/src/main/sql/derby/upgrade-3.1.0-to-3.2.0.derby.sql @@ -15,5 +15,9 @@ CREATE TABLE TXN_WRITE_NOTIFICATION_LOG ( ); INSERT INTO SEQUENCE_TABLE (SEQUENCE_NAME, NEXT_VAL) VALUES ('org.apache.hadoop.hive.metastore.model.MTxnWriteNotificationLog', 1); +-- HIVE-21077 +ALTER TABLE "APP"."DBS" ADD COLUMN CREATE_TIME INTEGER; +ALTER TABLE "APP"."CTLGS" ADD COLUMN CREATE_TIME INTEGER; + -- This needs to be the last thing done. Insert any changes above this line. UPDATE "APP".VERSION SET SCHEMA_VERSION='3.2.0', VERSION_COMMENT='Hive release version 3.2.0' where VER_ID=1; diff --git a/standalone-metastore/src/main/sql/mssql/hive-schema-3.2.0.mssql.sql b/standalone-metastore/src/main/sql/mssql/hive-schema-3.2.0.mssql.sql index 9e586e8ac39f44b52adbcda512b2d49aad761459..b427f004e0761f48598905df2412dbbdfee58cc4 100644 --- a/standalone-metastore/src/main/sql/mssql/hive-schema-3.2.0.mssql.sql +++ b/standalone-metastore/src/main/sql/mssql/hive-schema-3.2.0.mssql.sql @@ -285,7 +285,8 @@ CREATE TABLE DBS "NAME" nvarchar(128) NULL, OWNER_NAME nvarchar(128) NULL, OWNER_TYPE nvarchar(10) NULL, - CTLG_NAME nvarchar(256) + CTLG_NAME nvarchar(256), + CREATE_TIME BIGINT ); ALTER TABLE DBS ADD CONSTRAINT DBS_PK PRIMARY KEY (DB_ID); @@ -697,7 +698,8 @@ CREATE TABLE CTLGS ( CTLG_ID bigint primary key, "NAME" nvarchar(256), "DESC" nvarchar(4000), - LOCATION_URI nvarchar(4000) not null + LOCATION_URI nvarchar(4000) not null, + CREATE_TIME BIGINT ); CREATE UNIQUE INDEX UNIQUE_CTLG ON CTLGS ("NAME"); diff --git a/standalone-metastore/src/main/sql/mssql/upgrade-3.1.0-to-3.2.0.mssql.sql b/standalone-metastore/src/main/sql/mssql/upgrade-3.1.0-to-3.2.0.mssql.sql index 86bd3cc2e4fbfcb8b30d50fe653bddbbe431265a..47a585c323c093f7e44ab366507d92990983b88b 100644 --- a/standalone-metastore/src/main/sql/mssql/upgrade-3.1.0-to-3.2.0.mssql.sql +++ b/standalone-metastore/src/main/sql/mssql/upgrade-3.1.0-to-3.2.0.mssql.sql @@ -16,6 +16,10 @@ CREATE TABLE TXN_WRITE_NOTIFICATION_LOG ( ALTER TABLE TXN_WRITE_NOTIFICATION_LOG ADD CONSTRAINT TXN_WRITE_NOTIFICATION_LOG_PK PRIMARY KEY (WNL_TXNID, WNL_DATABASE, WNL_TABLE, WNL_PARTITION); INSERT INTO SEQUENCE_TABLE (SEQUENCE_NAME, NEXT_VAL) VALUES ('org.apache.hadoop.hive.metastore.model.MTxnWriteNotificationLog', 1); +-- HIVE-21077 +ALTER TABLE DBS ADD CREATE_TIME BIGINT; +ALTER TABLE CTLGS ADD CREATE_TIME BIGINT; + -- These lines need to be last. Insert any changes above. UPDATE VERSION SET SCHEMA_VERSION='3.2.0', VERSION_COMMENT='Hive release version 3.2.0' where VER_ID=1; SELECT 'Finished upgrading MetaStore schema from 3.1.0 to 3.2.0' AS MESSAGE; diff --git a/standalone-metastore/src/main/sql/mysql/hive-schema-3.2.0.mysql.sql b/standalone-metastore/src/main/sql/mysql/hive-schema-3.2.0.mysql.sql index bb2668cb4143bd6c53d5d7b77cbbe66286051cc4..7e884834a42487d67399c7ee5a4c406a4db60a10 100644 --- a/standalone-metastore/src/main/sql/mysql/hive-schema-3.2.0.mysql.sql +++ b/standalone-metastore/src/main/sql/mysql/hive-schema-3.2.0.mysql.sql @@ -82,6 +82,7 @@ CREATE TABLE `CTLGS` ( `NAME` VARCHAR(256), `DESC` VARCHAR(4000), `LOCATION_URI` VARCHAR(4000) NOT NULL, + `CREATE_TIME` INT(11), UNIQUE KEY `UNIQUE_CATALOG` (`NAME`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; @@ -100,6 +101,7 @@ CREATE TABLE IF NOT EXISTS `DBS` ( `OWNER_NAME` varchar(128) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL, `OWNER_TYPE` varchar(10) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL, `CTLG_NAME` varchar(256) NOT NULL, + `CREATE_TIME` INT(11), PRIMARY KEY (`DB_ID`), UNIQUE KEY `UNIQUE_DATABASE` (`NAME`, `CTLG_NAME`), CONSTRAINT `CTLG_FK1` FOREIGN KEY (`CTLG_NAME`) REFERENCES `CTLGS` (`NAME`) diff --git a/standalone-metastore/src/main/sql/mysql/upgrade-3.1.0-to-3.2.0.mysql.sql b/standalone-metastore/src/main/sql/mysql/upgrade-3.1.0-to-3.2.0.mysql.sql index b253fce65f01b7c78f9cc9658098d37f285c52fd..08659044010b3f6ce24fcd9e57173957535d03f3 100644 --- a/standalone-metastore/src/main/sql/mysql/upgrade-3.1.0-to-3.2.0.mysql.sql +++ b/standalone-metastore/src/main/sql/mysql/upgrade-3.1.0-to-3.2.0.mysql.sql @@ -16,6 +16,10 @@ CREATE TABLE TXN_WRITE_NOTIFICATION_LOG ( ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `SEQUENCE_TABLE` (`SEQUENCE_NAME`, `NEXT_VAL`) VALUES ('org.apache.hadoop.hive.metastore.model.MTxnWriteNotificationLog', 1); +-- HIVE-21077 +ALTER TABLE `DBS` ADD `CREATE_TIME` INT(11); +ALTER TABLE `CTLGS` ADD `CREATE_TIME` INT(11); + -- These lines need to be last. Insert any changes above. UPDATE VERSION SET SCHEMA_VERSION='3.2.0', VERSION_COMMENT='Hive release version 3.2.0' where VER_ID=1; SELECT 'Finished upgrading MetaStore schema from 3.1.0 to 3.2.0' AS ' '; diff --git a/standalone-metastore/src/main/sql/oracle/hive-schema-3.2.0.oracle.sql b/standalone-metastore/src/main/sql/oracle/hive-schema-3.2.0.oracle.sql index 6360a8a9ad5f5e3e17e48cf24127824ef341ab52..f1d9699ff484e60379a77c7a66cd9690aac3dd2d 100644 --- a/standalone-metastore/src/main/sql/oracle/hive-schema-3.2.0.oracle.sql +++ b/standalone-metastore/src/main/sql/oracle/hive-schema-3.2.0.oracle.sql @@ -92,7 +92,8 @@ CREATE TABLE DBS "NAME" VARCHAR2(128) NULL, OWNER_NAME VARCHAR2(128) NULL, OWNER_TYPE VARCHAR2(10) NULL, - CTLG_NAME VARCHAR2(256) + CTLG_NAME VARCHAR2(256), + CREATE_TIME NUMBER (10) ); ALTER TABLE DBS ADD CONSTRAINT DBS_PK PRIMARY KEY (DB_ID); diff --git a/standalone-metastore/src/main/sql/oracle/upgrade-3.1.0-to-3.2.0.oracle.sql b/standalone-metastore/src/main/sql/oracle/upgrade-3.1.0-to-3.2.0.oracle.sql index f21e872fd65f0b70e336384b397c0af73577fb13..5cdbf78d8a7c8d398edb2887d87fc7668c25fd8f 100644 --- a/standalone-metastore/src/main/sql/oracle/upgrade-3.1.0-to-3.2.0.oracle.sql +++ b/standalone-metastore/src/main/sql/oracle/upgrade-3.1.0-to-3.2.0.oracle.sql @@ -18,6 +18,10 @@ CREATE INDEX TXN_WRITE_NOTIFICATION_LOG_IDX ON TXN_WRITE_NOTIFICATION_LOG (WNL_T INSERT INTO SEQUENCE_TABLE (SEQUENCE_NAME, NEXT_VAL) VALUES ('org.apache.hadoop.hive.metastore.model.MTxnWriteNotificationLog', 1); +-- HIVE-21077 +ALTER TABLE DBS add CREATE_TIME NUMBER(10); +ALTER TABLE CTLGS add CREATE_TIME NUMBER(10); + -- These lines need to be last. Insert any changes above. UPDATE VERSION SET SCHEMA_VERSION='3.2.0', VERSION_COMMENT='Hive release version 3.2.0' where VER_ID=1; SELECT 'Finished upgrading MetaStore schema from 3.1.0 to 3.2.0' AS Status from dual; diff --git a/standalone-metastore/src/main/sql/postgres/hive-schema-3.2.0.postgres.sql b/standalone-metastore/src/main/sql/postgres/hive-schema-3.2.0.postgres.sql index 828ac3c9232f37ec6fd8f7551fb5bdb7125c0a05..b27d8303b218a718d64531a1045cc206c90c5a1e 100644 --- a/standalone-metastore/src/main/sql/postgres/hive-schema-3.2.0.postgres.sql +++ b/standalone-metastore/src/main/sql/postgres/hive-schema-3.2.0.postgres.sql @@ -63,7 +63,8 @@ CREATE TABLE "CTLGS" ( "CTLG_ID" BIGINT PRIMARY KEY, "NAME" VARCHAR(256) UNIQUE, "DESC" VARCHAR(4000), - "LOCATION_URI" VARCHAR(4000) NOT NULL + "LOCATION_URI" VARCHAR(4000) NOT NULL, + "CREATE_TIME" bigint ); -- @@ -77,7 +78,8 @@ CREATE TABLE "DBS" ( "NAME" character varying(128) DEFAULT NULL::character varying, "OWNER_NAME" character varying(128) DEFAULT NULL::character varying, "OWNER_TYPE" character varying(10) DEFAULT NULL::character varying, - "CTLG_NAME" varchar(256) + "CTLG_NAME" varchar(256), + "CREATE_TIME" bigint ); diff --git a/standalone-metastore/src/main/sql/postgres/upgrade-3.1.0-to-3.2.0.postgres.sql b/standalone-metastore/src/main/sql/postgres/upgrade-3.1.0-to-3.2.0.postgres.sql index 6a035103bb3dca115d8637ebdab838ac3fd7bda5..6553111de207b56637e5d6746f3848960ebae97a 100644 --- a/standalone-metastore/src/main/sql/postgres/upgrade-3.1.0-to-3.2.0.postgres.sql +++ b/standalone-metastore/src/main/sql/postgres/upgrade-3.1.0-to-3.2.0.postgres.sql @@ -16,6 +16,10 @@ CREATE TABLE "TXN_WRITE_NOTIFICATION_LOG" ( ); INSERT INTO "SEQUENCE_TABLE" ("SEQUENCE_NAME", "NEXT_VAL") VALUES ('org.apache.hadoop.hive.metastore.model.MTxnWriteNotificationLog', 1); +-- HIVE-21077 +ALTER TABLE "DBS" ADD "CREATE_TIME" BIGINT; +ALTER TABLE "CTLGS" ADD "CREATE_TIME" BIGINT; + -- These lines need to be last. Insert any changes above. UPDATE "VERSION" SET "SCHEMA_VERSION"='3.2.0', "VERSION_COMMENT"='Hive release version 3.2.0' where "VER_ID"=1; SELECT 'Finished upgrading MetaStore schema from 3.1.0 to 3.2.0'; diff --git a/standalone-metastore/src/main/thrift/hive_metastore.thrift b/standalone-metastore/src/main/thrift/hive_metastore.thrift index 4b5f48c98041cd410685bc0913ea4c42e6ee576f..46930214b8cbeb369b3d633be6505c2dd908ee0f 100644 --- a/standalone-metastore/src/main/thrift/hive_metastore.thrift +++ b/standalone-metastore/src/main/thrift/hive_metastore.thrift @@ -329,9 +329,10 @@ struct GrantRevokeRoleResponse { struct Catalog { 1: string name, // Name of the catalog 2: optional string description, // description of the catalog - 3: string locationUri // default storage location. When databases are created in - // this catalog, if they do not specify a location, they will - // be placed in this location. + 3: string locationUri, // default storage location. When databases are created in + // this catalog, if they do not specify a location, they will + // be placed in this location. + 4: optional i32 createTime // creation time of catalog in seconds since epoch } struct CreateCatalogRequest { @@ -368,7 +369,8 @@ struct Database { 5: optional PrincipalPrivilegeSet privileges, 6: optional string ownerName, 7: optional PrincipalType ownerType, - 8: optional string catalogName + 8: optional string catalogName, + 9: optional i32 createTime // creation time of database in seconds since epoch } // This object holds the information needed by SerDes diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/cache/TestCachedStore.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/cache/TestCachedStore.java index 62ed380dfcc22e90ccdf4b1516cc33f128f6b3e7..6cc411d6ab0acd489a75a145ab1e384a2c97f253 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/cache/TestCachedStore.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/cache/TestCachedStore.java @@ -1043,6 +1043,7 @@ private Database createTestDb(String dbName, String dbOwner) { db.setOwnerName(dbOwner); db.setOwnerType(PrincipalType.USER); db.setCatalogName(DEFAULT_CATALOG_NAME); + db.setCreateTime((int) (System.currentTimeMillis() / 1000)); return db; } diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestCatalogs.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestCatalogs.java index 4ccbd099cd9038481e5d192c3db7c8282ffacf02..b6f3db32dba06c082facb0343bd79bd968da1369 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestCatalogs.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestCatalogs.java @@ -124,6 +124,8 @@ public void catalogOperations() throws TException { Assert.assertTrue(catNames[i].equalsIgnoreCase(cat.getName())); Assert.assertEquals(description[i], cat.getDescription()); Assert.assertEquals(location[i], cat.getLocationUri()); + Assert.assertTrue("Create time of catalog should be set", cat.isSetCreateTime()); + Assert.assertTrue("Create time of catalog should be non-zero", cat.getCreateTime() > 0); File dir = new File(cat.getLocationUri()); Assert.assertTrue(dir.exists() && dir.isDirectory()); diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDatabases.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDatabases.java index d558de66d04c529286d91bce2dad8603a4ebfe0b..8257c95c56f3ef7548c9b7b4ef8de9f7c3a607e1 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDatabases.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDatabases.java @@ -122,6 +122,7 @@ public void testCreateGetDeleteDatabase() throws Exception { Database createdDatabase = client.getDatabase(database.getName()); // The createTime will be set on the server side, so the comparison should skip it + database.setCreateTime(createdDatabase.getCreateTime()); Assert.assertEquals("Comparing databases", database, createdDatabase); Assert.assertTrue("The directory should be created", metaStore.isPathExists( new Path(database.getLocationUri()))); @@ -206,6 +207,33 @@ public void testDefaultDatabaseData() throws Exception { Assert.assertEquals("Default database owner", "public", database.getOwnerName()); Assert.assertEquals("Default database owner type", PrincipalType.ROLE, database.getOwnerType()); Assert.assertNull("Default database privileges", database.getPrivileges()); + Assert.assertTrue("database create time should be set", database.isSetCreateTime()); + Assert.assertTrue("Database create time should be non-zero", database.getCreateTime() > 0); + } + + @Test + public void testDatabaseCreateTime() throws Exception { + // create db without specifying createtime + Database testDb = + new DatabaseBuilder().setName("test_create_time").create(client, metaStore.getConf()); + Database database = client.getDatabase("test_create_time"); + Assert.assertTrue("Database create time should have been set", + database.getCreateTime() > 0); + } + + @Test + public void testDbCreateTimeOverride() throws Exception { + // create db by providing a create time. Should be overridden, create time should + // always be set by metastore + Database testDb = + new DatabaseBuilder().setName("test_create_time") + .setCreateTime(1) + .create(client, metaStore.getConf()); + Database database = client.getDatabase("test_create_time"); + Assert.assertTrue("Database create time should have been set", + database.getCreateTime() > 0); + Assert.assertTrue("Database create time should have been reset by metastore", + database.getCreateTime() != 1); } @Test @@ -429,6 +457,7 @@ public void testAlterDatabase() throws Exception { .setDescription("dummy description 2") .addParam("param_key_1", "param_value_1_2") .addParam("param_key_2_3", "param_value_2_3") + .setCreateTime(originalDatabase.getCreateTime()) .build(metaStore.getConf()); client.alterDatabase(originalDatabase.getName(), newDatabase); diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/tools/TestSchemaToolForMetastore.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/tools/TestSchemaToolForMetastore.java index 0657ae5255373fb5d5f99c50d2c7189afd77d2a8..edad93f6519109e572e11e00a6c84b2b4dc87107 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/tools/TestSchemaToolForMetastore.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/tools/TestSchemaToolForMetastore.java @@ -110,11 +110,12 @@ public void testValidateSequences() throws Exception { boolean isValid = validator.validateSequences(conn); Assert.assertTrue(isValid); + String time = String.valueOf(System.currentTimeMillis()/1000); // Test valid case String[] scripts = new String[] { - "insert into CTLGS values(99, 'test_cat_1', 'description', 'hdfs://myhost.com:8020/user/hive/warehouse/mydb');", + "insert into CTLGS values(99, 'test_cat_1', 'description', 'hdfs://myhost.com:8020/user/hive/warehouse/mydb', " + time + ");", "insert into SEQUENCE_TABLE values('org.apache.hadoop.hive.metastore.model.MDatabase', 100);", - "insert into DBS values(99, 'test db1', 'hdfs:///tmp', 'db1', 'test', 'test', 'test_cat_1');" + "insert into DBS values(99, 'test db1', 'hdfs:///tmp', 'db1', 'test', 'test', 'test_cat_1', " + time + ");" }; File scriptFile = generateTestScript(scripts); schemaTool.execSql(scriptFile.getPath()); @@ -126,7 +127,7 @@ public void testValidateSequences() throws Exception { "delete from SEQUENCE_TABLE;", "delete from DBS;", "insert into SEQUENCE_TABLE values('org.apache.hadoop.hive.metastore.model.MDatabase', 100);", - "insert into DBS values(102, 'test db1', 'hdfs:///tmp', 'db1', 'test', 'test', 'test_cat_1');" + "insert into DBS values(102, 'test db1', 'hdfs:///tmp', 'db1', 'test', 'test', 'test_cat_1', " + time + ");" }; scriptFile = generateTestScript(scripts); schemaTool.execSql(scriptFile.getPath()); @@ -359,11 +360,12 @@ public void testValidateLocations() throws Exception { isValid = validator.validateLocations(conn, new URI[] {defaultRoot, defaultRoot2}); Assert.assertTrue(isValid); + String time = String.valueOf(System.currentTimeMillis()/1000); // Test valid case String[] scripts = new String[] { - "insert into CTLGS values(3, 'test_cat_2', 'description', 'hdfs://myhost.com:8020/user/hive/warehouse/mydb');", - "insert into DBS values(2, 'my db', 'hdfs://myhost.com:8020/user/hive/warehouse/mydb', 'mydb', 'public', 'role', 'test_cat_2');", - "insert into DBS values(7, 'db with bad port', 'hdfs://myhost.com:8020/', 'haDB', 'public', 'role', 'test_cat_2');", + "insert into CTLGS values(3, 'test_cat_2', 'description', 'hdfs://myhost.com:8020/user/hive/warehouse/mydb', " + time + ");", + "insert into DBS values(2, 'my db', 'hdfs://myhost.com:8020/user/hive/warehouse/mydb', 'mydb', 'public', 'role', 'test_cat_2', " + time + ");", + "insert into DBS values(7, 'db with bad port', 'hdfs://myhost.com:8020/', 'haDB', 'public', 'role', 'test_cat_2', " + time + ");", "insert into SDS(SD_ID,CD_ID,INPUT_FORMAT,IS_COMPRESSED,IS_STOREDASSUBDIRECTORIES,LOCATION,NUM_BUCKETS,OUTPUT_FORMAT,SERDE_ID) values (1,null,'org.apache.hadoop.mapred.TextInputFormat','N','N','hdfs://myhost.com:8020/user/hive/warehouse/mydb',-1,'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',null);", "insert into SDS(SD_ID,CD_ID,INPUT_FORMAT,IS_COMPRESSED,IS_STOREDASSUBDIRECTORIES,LOCATION,NUM_BUCKETS,OUTPUT_FORMAT,SERDE_ID) values (2,null,'org.apache.hadoop.mapred.TextInputFormat','N','N','hdfs://myhost.com:8020/user/admin/2015_11_18',-1,'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',null);", "insert into SDS(SD_ID,CD_ID,INPUT_FORMAT,IS_COMPRESSED,IS_STOREDASSUBDIRECTORIES,LOCATION,NUM_BUCKETS,OUTPUT_FORMAT,SERDE_ID) values (3,null,'org.apache.hadoop.mapred.TextInputFormat','N','N',null,-1,'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',null);", @@ -390,10 +392,10 @@ public void testValidateLocations() throws Exception { "delete from TBLS;", "delete from SDS;", "delete from DBS;", - "insert into DBS values(2, 'my db', '/user/hive/warehouse/mydb', 'mydb', 'public', 'role', 'test_cat_2');", - "insert into DBS values(4, 'my db2', 'hdfs://myhost.com:8020', '', 'public', 'role', 'test_cat_2');", - "insert into DBS values(6, 'db with bad port', 'hdfs://myhost.com:8020:', 'zDB', 'public', 'role', 'test_cat_2');", - "insert into DBS values(7, 'db with bad port', 'hdfs://mynameservice.com/', 'haDB', 'public', 'role', 'test_cat_2');", + "insert into DBS values(2, 'my db', '/user/hive/warehouse/mydb', 'mydb', 'public', 'role', 'test_cat_2', " + time + ");", + "insert into DBS values(4, 'my db2', 'hdfs://myhost.com:8020', '', 'public', 'role', 'test_cat_2', " + time + ");", + "insert into DBS values(6, 'db with bad port', 'hdfs://myhost.com:8020:', 'zDB', 'public', 'role', 'test_cat_2', " + time + ");", + "insert into DBS values(7, 'db with bad port', 'hdfs://mynameservice.com/', 'haDB', 'public', 'role', 'test_cat_2', " + time + ");", "insert into SDS(SD_ID,CD_ID,INPUT_FORMAT,IS_COMPRESSED,IS_STOREDASSUBDIRECTORIES,LOCATION,NUM_BUCKETS,OUTPUT_FORMAT,SERDE_ID) values (1,null,'org.apache.hadoop.mapred.TextInputFormat','N','N','hdfs://yourhost.com:8020/user/hive/warehouse/mydb',-1,'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',null);", "insert into SDS(SD_ID,CD_ID,INPUT_FORMAT,IS_COMPRESSED,IS_STOREDASSUBDIRECTORIES,LOCATION,NUM_BUCKETS,OUTPUT_FORMAT,SERDE_ID) values (2,null,'org.apache.hadoop.mapred.TextInputFormat','N','N','file:///user/admin/2015_11_18',-1,'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',null);", "insert into TBLS(TBL_ID,CREATE_TIME,DB_ID,LAST_ACCESS_TIME,OWNER,RETENTION,SD_ID,TBL_NAME,TBL_TYPE,VIEW_EXPANDED_TEXT,VIEW_ORIGINAL_TEXT,IS_REWRITE_ENABLED) values (2 ,1435255431,2,0 ,'hive',0,1,'mytal','MANAGED_TABLE',NULL,NULL,'n');", @@ -490,9 +492,10 @@ private String writeDummyPreUpgradeScript(int index, String upgradeScriptName, // Insert the records in DB to simulate a hive table private void createTestHiveTableSchemas() throws IOException { + String time = String.valueOf(System.currentTimeMillis()/1000); String[] scripts = new String[] { - "insert into CTLGS values (1, 'mycat', 'my description', 'hdfs://myhost.com:8020/user/hive/warehouse');", - "insert into DBS values(2, 'my db', 'hdfs://myhost.com:8020/user/hive/warehouse/mydb', 'mydb', 'public', 'role', 'mycat');", + "insert into CTLGS values (1, 'mycat', 'my description', 'hdfs://myhost.com:8020/user/hive/warehouse', " + time + ");", + "insert into DBS values(2, 'my db', 'hdfs://myhost.com:8020/user/hive/warehouse/mydb', 'mydb', 'public', 'role', 'mycat', " + time + ");", "insert into SDS(SD_ID,CD_ID,INPUT_FORMAT,IS_COMPRESSED,IS_STOREDASSUBDIRECTORIES,LOCATION,NUM_BUCKETS,OUTPUT_FORMAT,SERDE_ID) values (1,null,'org.apache.hadoop.mapred.TextInputFormat','N','N','hdfs://myhost.com:8020/user/hive/warehouse/mydb',-1,'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',null);", "insert into SDS(SD_ID,CD_ID,INPUT_FORMAT,IS_COMPRESSED,IS_STOREDASSUBDIRECTORIES,LOCATION,NUM_BUCKETS,OUTPUT_FORMAT,SERDE_ID) values (2,null,'org.apache.hadoop.mapred.TextInputFormat','N','N','hdfs://myhost.com:8020/user/admin/2015_11_18',-1,'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',null);", "insert into TBLS(TBL_ID,CREATE_TIME,DB_ID,LAST_ACCESS_TIME,OWNER,RETENTION,SD_ID,TBL_NAME,TBL_TYPE,VIEW_EXPANDED_TEXT,VIEW_ORIGINAL_TEXT,IS_REWRITE_ENABLED) values (2 ,1435255431,2,0 ,'hive',0,1,'mytal','MANAGED_TABLE',NULL,NULL,'n');",