commit ae2a410f9adca04d83522a06e51ac05ded2185eb Author: Dan Burkert Date: Thu Jun 29 15:54:02 2017 -0700 HIVE-16993: ThriftHiveMetastore.create_database can fail if the locationUri is not set diff --git a/hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/SemanticAnalysis/CreateDatabaseHook.java b/hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/SemanticAnalysis/CreateDatabaseHook.java index 887a64dcd5..f042325b53 100644 --- a/hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/SemanticAnalysis/CreateDatabaseHook.java +++ b/hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/SemanticAnalysis/CreateDatabaseHook.java @@ -89,7 +89,8 @@ protected void authorizeDDLWork(HiveSemanticAnalyzerHookContext context, CreateDatabaseDesc createDb = work.getCreateDatabaseDesc(); if (createDb != null) { Database db = new Database(createDb.getName(), createDb.getComment(), - createDb.getLocationUri(), createDb.getDatabaseProperties()); + createDb.getDatabaseProperties()); + db.setLocationUri(createDb.getLocationUri()); authorize(db, Privilege.CREATE); } } diff --git a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/common/TestHiveClientCache.java b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/common/TestHiveClientCache.java index c77bc48e6c..3c48560093 100644 --- a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/common/TestHiveClientCache.java +++ b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/common/TestHiveClientCache.java @@ -194,7 +194,7 @@ public void testHMSCBreakability() throws IOException, MetaException, LoginExcep } catch (Exception e) { } - client.createDatabase(new Database(DB_NAME, "", null, null)); + client.createDatabase(new Database(DB_NAME, "", null)); List fields = new ArrayList(); fields.add(new FieldSchema("colname", serdeConstants.STRING_TYPE_NAME, "")); diff --git a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatOutputFormat.java b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatOutputFormat.java index d96b3852fe..67deb93363 100644 --- a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatOutputFormat.java +++ b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatOutputFormat.java @@ -97,7 +97,7 @@ private void initTable() throws Exception { client.dropDatabase(dbName); } catch (Exception e) { } - client.createDatabase(new Database(dbName, "", null, null)); + client.createDatabase(new Database(dbName, "", null)); assertNotNull((client.getDatabase(dbName).getLocationUri())); List fields = new ArrayList(); diff --git a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java index 808c9c7c36..4164f91a7f 100644 --- a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java +++ b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java @@ -284,7 +284,8 @@ public void createDatabase() throws Exception { String dbName2 = "createdb2"; String dbLocationUri = "file:/tmp"; String dbDescription = "no description"; - Database db = new Database(dbName, dbDescription, dbLocationUri, emptyParameters); + Database db = new Database(dbName, dbDescription, emptyParameters); + db.setLocationUri(dbLocationUri); msClient.createDatabase(db); // Read notification from metastore @@ -309,7 +310,8 @@ public void createDatabase() throws Exception { // When hive.metastore.transactional.event.listeners is set, // a failed event should not create a new notification DummyRawStoreFailEvent.setEventSucceed(false); - db = new Database(dbName2, dbDescription, dbLocationUri, emptyParameters); + db = new Database(dbName2, dbDescription, emptyParameters); + db.setLocationUri(dbLocationUri); try { msClient.createDatabase(db); fail("Error: create database should've failed"); @@ -326,7 +328,8 @@ public void dropDatabase() throws Exception { String dbName2 = "dropdb2"; String dbLocationUri = "file:/tmp"; String dbDescription = "no description"; - Database db = new Database(dbName, dbDescription, dbLocationUri, emptyParameters); + Database db = new Database(dbName, dbDescription, emptyParameters); + db.setLocationUri(dbLocationUri); msClient.createDatabase(db); msClient.dropDatabase(dbName); @@ -354,7 +357,8 @@ public void dropDatabase() throws Exception { // When hive.metastore.transactional.event.listeners is set, // a failed event should not create a new notification - db = new Database(dbName2, dbDescription, dbLocationUri, emptyParameters); + db = new Database(dbName2, dbDescription, emptyParameters); + db.setLocationUri(dbLocationUri); msClient.createDatabase(db); DummyRawStoreFailEvent.setEventSucceed(false); try { @@ -1278,11 +1282,14 @@ public void insertPartition() throws Exception { @Test public void getOnlyMaxEvents() throws Exception { - Database db = new Database("db1", "no description", "file:/tmp", emptyParameters); + Database db = new Database("db1", "no description", emptyParameters); + db.setLocationUri("file:/tmp"); msClient.createDatabase(db); - db = new Database("db2", "no description", "file:/tmp", emptyParameters); + db = new Database("db2", "no description", emptyParameters); + db.setLocationUri("file:/tmp"); msClient.createDatabase(db); - db = new Database("db3", "no description", "file:/tmp", emptyParameters); + db = new Database("db3", "no description", emptyParameters); + db.setLocationUri("file:/tmp"); msClient.createDatabase(db); // Get notifications from metastore @@ -1294,9 +1301,11 @@ public void getOnlyMaxEvents() throws Exception { @Test public void filter() throws Exception { - Database db = new Database("f1", "no description", "file:/tmp", emptyParameters); + Database db = new Database("f1", "no description", emptyParameters); + db.setLocationUri("file:/tmp"); msClient.createDatabase(db); - db = new Database("f2", "no description", "file:/tmp", emptyParameters); + db = new Database("f2", "no description", emptyParameters); + db.setLocationUri("file:/tmp"); msClient.createDatabase(db); msClient.dropDatabase("f2"); @@ -1315,9 +1324,11 @@ public boolean accept(NotificationEvent event) { @Test public void filterWithMax() throws Exception { - Database db = new Database("f10", "no description", "file:/tmp", emptyParameters); + Database db = new Database("f10", "no description", emptyParameters); + db.setLocationUri("file:/tmp"); msClient.createDatabase(db); - db = new Database("f11", "no description", "file:/tmp", emptyParameters); + db = new Database("f11", "no description", emptyParameters); + db.setLocationUri("file:/tmp"); msClient.createDatabase(db); msClient.dropDatabase("f11"); @@ -1541,7 +1552,8 @@ private void verifyInsert(NotificationEvent event, String dbName, String tblName @Test public void cleanupNotifs() throws Exception { - Database db = new Database("cleanup1", "no description", "file:/tmp", emptyParameters); + Database db = new Database("cleanup1", "no description", emptyParameters); + db.setLocationUri("file:/tmp"); msClient.createDatabase(db); msClient.dropDatabase("cleanup1"); diff --git a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseImport.java b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseImport.java index b1d31746b7..e913e36e99 100644 --- a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseImport.java +++ b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseImport.java @@ -274,7 +274,7 @@ public void importOneFunc() throws Exception { // Create the database so I can put the function in it. store.createDatabase( - new Database(dbNames[0], "no description", "file:/tmp", emptyParameters)); + new Database(dbNames[0], "no description", emptyParameters)); HBaseImport importer = new HBaseImport("-f", dbNames[0] + "." + funcNames[0]); importer.setConnections(rdbms, store); @@ -321,7 +321,7 @@ public void importOneTableNonPartitioned() throws Exception { // Create the database so I can put the table in it. store.createDatabase( - new Database(dbNames[0], "no description", "file:/tmp", emptyParameters)); + new Database(dbNames[0], "no description", emptyParameters)); HBaseImport importer = new HBaseImport("-t", dbNames[0] + "." + tableNames[0]); importer.setConnections(rdbms, store); @@ -362,7 +362,7 @@ public void importTablesWithConstraints() throws Exception { // Create the database so I can put the table in it. store.createDatabase( - new Database(dbNames[0], "no description", "file:/tmp", emptyParameters)); + new Database(dbNames[0], "no description", emptyParameters)); HBaseImport importer = new HBaseImport("-d", dbNames[0]); importer.setConnections(rdbms, store); @@ -430,7 +430,7 @@ public void importOneTablePartitioned() throws Exception { // Create the database so I can put the table in it. store.createDatabase( - new Database(dbNames[0], "no description", "file:/tmp", emptyParameters)); + new Database(dbNames[0], "no description", emptyParameters)); HBaseImport importer = new HBaseImport("-t", dbNames[0] + "." + tableNames[1]); importer.setConnections(rdbms, store); @@ -576,7 +576,7 @@ private void setupObjectStore(RawStore rdbms, String[] roles, String[] dbNames, for (int i = 0; i < dbNames.length; i++) { rdbms.createDatabase( - new Database(dbNames[i], "no description", "file:/tmp", emptyParameters)); + new Database(dbNames[i], "no description", emptyParameters)); List cols = new ArrayList<>(); cols.add(new FieldSchema("col1", "int", "nocomment")); @@ -655,7 +655,7 @@ public void parallel() throws Exception { for (int i = 0; i < dbNames.length; i++) { rdbms.createDatabase( - new Database(dbNames[i], "no description", "file:/tmp", emptyParameters)); + new Database(dbNames[i], "no description", emptyParameters)); List cols = new ArrayList<>(); cols.add(new FieldSchema("col1", "int", "nocomment")); @@ -722,7 +722,7 @@ public void parallelOdd() throws Exception { for (int i = 0; i < dbNames.length; i++) { rdbms.createDatabase( - new Database(dbNames[i], "no description", "file:/tmp", emptyParameters)); + new Database(dbNames[i], "no description", emptyParameters)); List cols = new ArrayList<>(); cols.add(new FieldSchema("col1", "int", "nocomment")); diff --git a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseSchemaTool.java b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseSchemaTool.java index c98911a73a..c5161625b7 100644 --- a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseSchemaTool.java +++ b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseSchemaTool.java @@ -290,7 +290,8 @@ public void oneMondoTest() throws Exception { String[] dbNames = new String[3]; for (int i = 0; i < dbNames.length; i++) { dbNames[i] = "db" + i; - Database db = new Database(dbNames[i], "no description", "file:///tmp", emptyParameters); + Database db = new Database(dbNames[i], "no description", emptyParameters); + db.setLocationUri("file:///tmp"); store.createDatabase(db); } diff --git a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java index 2cc1373108..5781563e51 100644 --- a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java +++ b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java @@ -97,7 +97,8 @@ public void setup() throws IOException { @Test public void createDb() throws Exception { String dbname = "mydb"; - Database db = new Database(dbname, "no description", "file:///tmp", emptyParameters); + Database db = new Database(dbname, "no description", emptyParameters); + db.setLocationUri("file:///tmp"); store.createDatabase(db); Database d = store.getDatabase("mydb"); @@ -109,7 +110,8 @@ public void createDb() throws Exception { @Test public void dropDb() throws Exception { String dbname = "anotherdb"; - Database db = new Database(dbname, "no description", "file:///tmp", emptyParameters); + Database db = new Database(dbname, "no description", emptyParameters); + db.setLocationUri("file:///tmp"); store.createDatabase(db); Database d = store.getDatabase(dbname); @@ -125,7 +127,8 @@ public void getAllDbs() throws Exception { String[] dbNames = new String[3]; for (int i = 0; i < dbNames.length; i++) { dbNames[i] = "db" + i; - Database db = new Database(dbNames[i], "no description", "file:///tmp", emptyParameters); + Database db = new Database(dbNames[i], "no description", emptyParameters); + db.setLocationUri("file:///tmp"); store.createDatabase(db); } @@ -141,7 +144,8 @@ public void getDbsRegex() throws Exception { String[] dbNames = new String[3]; for (int i = 0; i < dbNames.length; i++) { dbNames[i] = "db" + i; - Database db = new Database(dbNames[i], "no description", "file:///tmp", emptyParameters); + Database db = new Database(dbNames[i], "no description", emptyParameters); + db.setLocationUri("file:///tmp"); store.createDatabase(db); } @@ -256,7 +260,7 @@ public void getAllTables() throws Exception { String tableNames[] = new String[]{"curly", "larry", "moe"}; for (int i = 0; i < dbNames.length; i++) { - store.createDatabase(new Database(dbNames[i], "no description", "file:///tmp", + store.createDatabase(new Database(dbNames[i], "no description", emptyParameters)); } @@ -903,7 +907,8 @@ public void grantRevokeGlobalPrivileges() throws Exception { public void grantRevokeDbPrivileges() throws Exception { String dbName = "grdbp_db"; try { - Database db = new Database(dbName, "no description", "file:///tmp", emptyParameters); + Database db = new Database(dbName, "no description", emptyParameters); + db.setLocationUri("file:///tmp"); store.createDatabase(db); doGrantRevoke(HiveObjectType.DATABASE, dbName, null, new String[] {"grdbp_role1", "grdbp_role2"}, @@ -918,7 +923,8 @@ public void grantRevokeTablePrivileges() throws Exception { String dbName = "grtp_db"; String tableName = "grtp_table"; try { - Database db = new Database(dbName, "no description", "file:///tmp", emptyParameters); + Database db = new Database(dbName, "no description", emptyParameters); + db.setLocationUri("file:///tmp"); store.createDatabase(db); int startTime = (int)(System.currentTimeMillis() / 1000); List cols = new ArrayList(); @@ -1137,9 +1143,11 @@ private void checkRoleRemovedFromAllPrivileges(HiveObjectType objectType, String public void listDbGrants() throws Exception { String dbNames[] = new String[] {"ldbg_db1", "ldbg_db2"}; try { - Database db = new Database(dbNames[0], "no description", "file:///tmp", emptyParameters); + Database db = new Database(dbNames[0], "no description", emptyParameters); + db.setLocationUri("file:///tmp"); store.createDatabase(db); - db = new Database(dbNames[1], "no description", "file:///tmp", emptyParameters); + db = new Database(dbNames[1], "no description", emptyParameters); + db.setLocationUri("file:///tmp"); store.createDatabase(db); String[] roleNames = new String[]{"ldbg_role1", "ldbg_role2"}; String[] userNames = new String[]{"frodo", "sam"}; @@ -1308,7 +1316,8 @@ public void listTableGrants() throws Exception { String dbName = "ltg_db"; String[] tableNames = new String[] {"ltg_t1", "ltg_t2"}; try { - Database db = new Database(dbName, "no description", "file:///tmp", emptyParameters); + Database db = new Database(dbName, "no description", emptyParameters); + db.setLocationUri("file:///tmp"); store.createDatabase(db); int startTime = (int)(System.currentTimeMillis() / 1000); List cols = new ArrayList(); diff --git a/metastore/if/hive_metastore.thrift b/metastore/if/hive_metastore.thrift index 042a5d8d0b..433e73b6f8 100755 --- a/metastore/if/hive_metastore.thrift +++ b/metastore/if/hive_metastore.thrift @@ -267,7 +267,7 @@ struct GrantRevokeRoleResponse { struct Database { 1: string name, 2: string description, - 3: string locationUri, + 3: optional string locationUri, 4: map parameters, // properties associated with the database 5: optional PrincipalPrivilegeSet privileges, 6: optional string ownerName, diff --git a/metastore/src/gen/thrift/gen-cpp/hive_metastore_types.cpp b/metastore/src/gen/thrift/gen-cpp/hive_metastore_types.cpp index d178f10a21..c1082da3e1 100644 --- a/metastore/src/gen/thrift/gen-cpp/hive_metastore_types.cpp +++ b/metastore/src/gen/thrift/gen-cpp/hive_metastore_types.cpp @@ -3745,6 +3745,7 @@ void Database::__set_description(const std::string& val) { void Database::__set_locationUri(const std::string& val) { this->locationUri = val; +__isset.locationUri = true; } void Database::__set_parameters(const std::map & val) { @@ -3885,10 +3886,11 @@ uint32_t Database::write(::apache::thrift::protocol::TProtocol* oprot) const { xfer += oprot->writeString(this->description); xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("locationUri", ::apache::thrift::protocol::T_STRING, 3); - xfer += oprot->writeString(this->locationUri); - xfer += oprot->writeFieldEnd(); - + if (this->__isset.locationUri) { + xfer += oprot->writeFieldBegin("locationUri", ::apache::thrift::protocol::T_STRING, 3); + xfer += oprot->writeString(this->locationUri); + xfer += oprot->writeFieldEnd(); + } xfer += oprot->writeFieldBegin("parameters", ::apache::thrift::protocol::T_MAP, 4); { xfer += oprot->writeMapBegin(::apache::thrift::protocol::T_STRING, ::apache::thrift::protocol::T_STRING, static_cast(this->parameters.size())); @@ -3960,7 +3962,7 @@ void Database::printTo(std::ostream& out) const { out << "Database("; out << "name=" << to_string(name); out << ", " << "description=" << to_string(description); - out << ", " << "locationUri=" << to_string(locationUri); + out << ", " << "locationUri="; (__isset.locationUri ? (out << to_string(locationUri)) : (out << "")); out << ", " << "parameters=" << to_string(parameters); out << ", " << "privileges="; (__isset.privileges ? (out << to_string(privileges)) : (out << "")); out << ", " << "ownerName="; (__isset.ownerName ? (out << to_string(ownerName)) : (out << "")); diff --git a/metastore/src/gen/thrift/gen-cpp/hive_metastore_types.h b/metastore/src/gen/thrift/gen-cpp/hive_metastore_types.h index 2bba534975..f401a7f512 100644 --- a/metastore/src/gen/thrift/gen-cpp/hive_metastore_types.h +++ b/metastore/src/gen/thrift/gen-cpp/hive_metastore_types.h @@ -1929,7 +1929,9 @@ class Database { return false; if (!(description == rhs.description)) return false; - if (!(locationUri == rhs.locationUri)) + if (__isset.locationUri != rhs.__isset.locationUri) + return false; + else if (__isset.locationUri && !(locationUri == rhs.locationUri)) return false; if (!(parameters == rhs.parameters)) return false; diff --git a/metastore/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/Database.java b/metastore/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/Database.java index 2769845584..277ed5c2c3 100644 --- a/metastore/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/Database.java +++ b/metastore/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/Database.java @@ -54,7 +54,7 @@ private String name; // required private String description; // required - private String locationUri; // required + private String locationUri; // optional private Map parameters; // required private PrincipalPrivilegeSet privileges; // optional private String ownerName; // optional @@ -141,7 +141,7 @@ public String getFieldName() { } // isset id assignments - private static final _Fields optionals[] = {_Fields.PRIVILEGES,_Fields.OWNER_NAME,_Fields.OWNER_TYPE}; + private static final _Fields optionals[] = {_Fields.LOCATION_URI,_Fields.PRIVILEGES,_Fields.OWNER_NAME,_Fields.OWNER_TYPE}; 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); @@ -149,7 +149,7 @@ public String getFieldName() { new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); tmpMap.put(_Fields.DESCRIPTION, new org.apache.thrift.meta_data.FieldMetaData("description", org.apache.thrift.TFieldRequirementType.DEFAULT, 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, + tmpMap.put(_Fields.LOCATION_URI, new org.apache.thrift.meta_data.FieldMetaData("locationUri", org.apache.thrift.TFieldRequirementType.OPTIONAL, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); tmpMap.put(_Fields.PARAMETERS, new org.apache.thrift.meta_data.FieldMetaData("parameters", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.MapMetaData(org.apache.thrift.protocol.TType.MAP, @@ -171,13 +171,11 @@ public Database() { public Database( String name, String description, - String locationUri, Map parameters) { this(); this.name = name; this.description = description; - this.locationUri = locationUri; this.parameters = parameters; } @@ -751,14 +749,16 @@ public String toString() { sb.append(this.description); } first = false; - if (!first) sb.append(", "); - sb.append("locationUri:"); - if (this.locationUri == null) { - sb.append("null"); - } else { - sb.append(this.locationUri); + if (isSetLocationUri()) { + if (!first) sb.append(", "); + sb.append("locationUri:"); + if (this.locationUri == null) { + sb.append("null"); + } else { + sb.append(this.locationUri); + } + first = false; } - first = false; if (!first) sb.append(", "); sb.append("parameters:"); if (this.parameters == null) { @@ -936,9 +936,11 @@ public void write(org.apache.thrift.protocol.TProtocol oprot, Database struct) t oprot.writeFieldEnd(); } if (struct.locationUri != null) { - oprot.writeFieldBegin(LOCATION_URI_FIELD_DESC); - oprot.writeString(struct.locationUri); - oprot.writeFieldEnd(); + if (struct.isSetLocationUri()) { + oprot.writeFieldBegin(LOCATION_URI_FIELD_DESC); + oprot.writeString(struct.locationUri); + oprot.writeFieldEnd(); + } } if (struct.parameters != null) { oprot.writeFieldBegin(PARAMETERS_FIELD_DESC); diff --git a/metastore/src/gen/thrift/gen-rb/hive_metastore_types.rb b/metastore/src/gen/thrift/gen-rb/hive_metastore_types.rb index 02c5717c54..13feb840c1 100644 --- a/metastore/src/gen/thrift/gen-rb/hive_metastore_types.rb +++ b/metastore/src/gen/thrift/gen-rb/hive_metastore_types.rb @@ -662,7 +662,7 @@ class Database FIELDS = { NAME => {:type => ::Thrift::Types::STRING, :name => 'name'}, DESCRIPTION => {:type => ::Thrift::Types::STRING, :name => 'description'}, - LOCATIONURI => {:type => ::Thrift::Types::STRING, :name => 'locationUri'}, + LOCATIONURI => {:type => ::Thrift::Types::STRING, :name => 'locationUri', :optional => true}, PARAMETERS => {:type => ::Thrift::Types::MAP, :name => 'parameters', :key => {:type => ::Thrift::Types::STRING}, :value => {:type => ::Thrift::Types::STRING}}, PRIVILEGES => {:type => ::Thrift::Types::STRUCT, :name => 'privileges', :class => ::PrincipalPrivilegeSet, :optional => true}, OWNERNAME => {:type => ::Thrift::Types::STRING, :name => 'ownerName', :optional => true}, diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 9765ec2a3c..6002663cde 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -632,8 +632,8 @@ private void createDefaultDB_core(RawStore ms) throws MetaException, InvalidObje try { ms.getDatabase(DEFAULT_DATABASE_NAME); } catch (NoSuchObjectException e) { - Database db = new Database(DEFAULT_DATABASE_NAME, DEFAULT_DATABASE_COMMENT, - wh.getDefaultDatabasePath(DEFAULT_DATABASE_NAME).toString(), null); + Database db = new Database(DEFAULT_DATABASE_NAME, DEFAULT_DATABASE_COMMENT, null); + db.setLocationUri(wh.getDefaultDatabasePath(DEFAULT_DATABASE_NAME).toString()); db.setOwnerName(PUBLIC); db.setOwnerType(PrincipalType.ROLE); ms.createDatabase(db); diff --git a/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java b/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java index 61fe7e1d91..1a3d11bbd6 100644 --- a/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java +++ b/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java @@ -148,7 +148,6 @@ private static void clearAndRecreateDB(HiveMetaStoreClient hmsc) throws Exceptio hmsc.createDatabase(new Database(dbName, "", // Description. - null, // Location. null // Parameters. )); } diff --git a/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java b/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java index b28ea73593..ea18a405a1 100644 --- a/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java +++ b/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java @@ -180,8 +180,10 @@ public void testNotificationOps() throws InterruptedException { */ @Test public void testDatabaseOps() throws MetaException, InvalidObjectException, NoSuchObjectException { - Database db1 = new Database(DB1, "description", "locationurl", null); - Database db2 = new Database(DB2, "description", "locationurl", null); + Database db1 = new Database(DB1, "description", null); + db1.setLocationUri("locationurl"); + Database db2 = new Database(DB2, "description", null); + db2.setLocationUri("locationurl"); objectStore.createDatabase(db1); objectStore.createDatabase(db2); @@ -204,7 +206,8 @@ public void testDatabaseOps() throws MetaException, InvalidObjectException, NoSu */ @Test public void testTableOps() throws MetaException, InvalidObjectException, NoSuchObjectException, InvalidInputException { - Database db1 = new Database(DB1, "description", "locationurl", null); + Database db1 = new Database(DB1, "description", null); + db1.setLocationUri("locationurl"); objectStore.createDatabase(db1); StorageDescriptor sd1 = new StorageDescriptor(ImmutableList.of(new FieldSchema("pk_col", "double", null)), "location", null, null, false, 0, new SerDeInfo("SerDeName", "serializationLib", null), @@ -275,7 +278,8 @@ public void testTableOps() throws MetaException, InvalidObjectException, NoSuchO */ @Test public void testPartitionOps() throws MetaException, InvalidObjectException, NoSuchObjectException, InvalidInputException { - Database db1 = new Database(DB1, "description", "locationurl", null); + Database db1 = new Database(DB1, "description", null); + db1.setLocationUri("locationurl"); objectStore.createDatabase(db1); StorageDescriptor sd = new StorageDescriptor(null, "location", null, null, false, 0, new SerDeInfo("SerDeName", "serializationLib", null), null, null, null); HashMap tableParams = new HashMap(); diff --git a/metastore/src/test/org/apache/hadoop/hive/metastore/cache/TestCachedStore.java b/metastore/src/test/org/apache/hadoop/hive/metastore/cache/TestCachedStore.java index 1fa9447145..9235289455 100644 --- a/metastore/src/test/org/apache/hadoop/hive/metastore/cache/TestCachedStore.java +++ b/metastore/src/test/org/apache/hadoop/hive/metastore/cache/TestCachedStore.java @@ -86,7 +86,8 @@ public void testDatabaseOps() throws Exception { String dbLocation = "file:/tmp"; Map dbParams = new HashMap(); String dbOwner = "user1"; - Database db = new Database(dbName, dbDescription, dbLocation, dbParams); + Database db = new Database(dbName, dbDescription, dbParams); + db.setLocationUri(dbLocation); db.setOwnerName(dbOwner); db.setOwnerType(PrincipalType.USER); objectStore.createDatabase(db); @@ -101,7 +102,8 @@ public void testDatabaseOps() throws Exception { // Add another db via CachedStore final String dbName1 = "testDatabaseOps1"; final String dbDescription1 = "testDatabaseOps1"; - Database db1 = new Database(dbName1, dbDescription1, dbLocation, dbParams); + Database db1 = new Database(dbName1, dbDescription1, dbParams); + db1.setLocationUri(dbLocation); db1.setOwnerName(dbOwner); db1.setOwnerType(PrincipalType.USER); cachedStore.createDatabase(db1); @@ -112,7 +114,8 @@ public void testDatabaseOps() throws Exception { Assert.assertEquals(db1, dbNew); // Alter the db via CachedStore (can only alter owner or parameters) - db = new Database(dbName, dbDescription, dbLocation, dbParams); + db = new Database(dbName, dbDescription, dbParams); + db.setLocationUri(dbLocation); dbOwner = "user2"; db.setOwnerName(dbOwner); db.setOwnerType(PrincipalType.USER); @@ -126,7 +129,8 @@ public void testDatabaseOps() throws Exception { // Add another db via ObjectStore final String dbName2 = "testDatabaseOps2"; final String dbDescription2 = "testDatabaseOps2"; - Database db2 = new Database(dbName2, dbDescription2, dbLocation, dbParams); + Database db2 = new Database(dbName2, dbDescription2, dbParams); + db2.setLocationUri(dbLocation); db2.setOwnerName(dbOwner); db2.setOwnerType(PrincipalType.USER); objectStore.createDatabase(db2); @@ -134,7 +138,8 @@ public void testDatabaseOps() throws Exception { // Alter db "testDatabaseOps" via ObjectStore dbOwner = "user1"; - db = new Database(dbName, dbDescription, dbLocation, dbParams); + db = new Database(dbName, dbDescription, dbParams); + db.setLocationUri(dbLocation); db.setOwnerName(dbOwner); db.setOwnerType(PrincipalType.USER); objectStore.alterDatabase(dbName, db); @@ -177,7 +182,8 @@ public void testTableOps() throws Exception { String dbLocation = "file:/tmp"; Map dbParams = new HashMap(); String dbOwner = "user1"; - Database db = new Database(dbName, dbDescription, dbLocation, dbParams); + Database db = new Database(dbName, dbDescription, dbParams); + db.setLocationUri(dbLocation); db.setOwnerName(dbOwner); db.setOwnerType(PrincipalType.USER); objectStore.createDatabase(db); @@ -281,7 +287,8 @@ public void testPartitionOps() throws Exception { String dbLocation = "file:/tmp"; Map dbParams = new HashMap(); String dbOwner = "user1"; - Database db = new Database(dbName, dbDescription, dbLocation, dbParams); + Database db = new Database(dbName, dbDescription, dbParams); + db.setLocationUri(dbLocation); db.setOwnerName(dbOwner); db.setOwnerType(PrincipalType.USER); objectStore.createDatabase(db); @@ -382,7 +389,8 @@ public void testTableColStatsOps() throws Exception { String dbLocation = "file:/tmp"; Map dbParams = new HashMap(); String dbOwner = "user1"; - Database db = new Database(dbName, dbDescription, dbLocation, dbParams); + Database db = new Database(dbName, dbDescription, dbParams); + db.setLocationUri(dbLocation); db.setOwnerName(dbOwner); db.setOwnerType(PrincipalType.USER); objectStore.createDatabase(db); @@ -681,7 +689,8 @@ public void testAggrStatsRepeatedRead() throws Exception { String tblName = "tbl"; String colName = "f1"; - Database db = new Database(dbName, null, "some_location", null); + Database db = new Database(dbName, null, null); + db.setLocationUri("some_location"); cachedStore.createDatabase(db); List cols = new ArrayList(); diff --git a/metastore/src/test/org/apache/hadoop/hive/metastore/hbase/TestHBaseStore.java b/metastore/src/test/org/apache/hadoop/hive/metastore/hbase/TestHBaseStore.java index 4aa8c34618..52ceeab457 100644 --- a/metastore/src/test/org/apache/hadoop/hive/metastore/hbase/TestHBaseStore.java +++ b/metastore/src/test/org/apache/hadoop/hive/metastore/hbase/TestHBaseStore.java @@ -301,7 +301,8 @@ public void init() throws IOException { @Test public void createDb() throws Exception { String dbname = "mydb"; - Database db = new Database(dbname, "no description", "file:///tmp", emptyParameters); + Database db = new Database(dbname, "no description", emptyParameters); + db.setLocationUri("file:///tmp"); store.createDatabase(db); Database d = store.getDatabase(dbname); @@ -313,7 +314,8 @@ public void createDb() throws Exception { @Test public void alterDb() throws Exception { String dbname = "mydb"; - Database db = new Database(dbname, "no description", "file:///tmp", emptyParameters); + Database db = new Database(dbname, "no description", emptyParameters); + db.setLocationUri("file:///tmp"); store.createDatabase(db); db.setDescription("a description"); store.alterDatabase(dbname, db); @@ -327,7 +329,8 @@ public void alterDb() throws Exception { @Test public void dropDb() throws Exception { String dbname = "anotherdb"; - Database db = new Database(dbname, "no description", "file:///tmp", emptyParameters); + Database db = new Database(dbname, "no description", emptyParameters); + db.setLocationUri("file:///tmp"); store.createDatabase(db); Database d = store.getDatabase(dbname); diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java index 5b7fc25417..a779a6e400 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java @@ -822,7 +822,8 @@ private void analyzeCreateDatabase(ASTNode ast) throws SemanticException { if (dbProps != null) { createDatabaseDesc.setDatabaseProperties(dbProps); } - Database database = new Database(dbName, dbComment, dbLocation, dbProps); + Database database = new Database(dbName, dbComment, dbProps); + database.setLocationUri(dbLocation); outputs.add(new WriteEntity(database, WriteEntity.WriteType.DDL_NO_LOCK)); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(),