http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/InjectableBehaviourObjectStore.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/InjectableBehaviourObjectStore.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/InjectableBehaviourObjectStore.java index d7a40b6..fdb0dc4 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/InjectableBehaviourObjectStore.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/InjectableBehaviourObjectStore.java @@ -88,13 +88,13 @@ public class InjectableBehaviourObjectStore extends ObjectStore { // ObjectStore methods to be overridden with injected behavior @Override - public Table getTable(String dbName, String tableName) throws MetaException { - return getTableModifier.apply(super.getTable(dbName, tableName)); + public Table getTable(String catName, String dbName, String tableName) throws MetaException { + return getTableModifier.apply(super.getTable(catName, dbName, tableName)); } @Override - public List<String> listPartitionNames(String dbName, String tableName, short max) throws MetaException { - return listPartitionNamesModifier.apply(super.listPartitionNames(dbName, tableName, max)); + public List<String> listPartitionNames(String catName, String dbName, String tableName, short max) throws MetaException { + return listPartitionNamesModifier.apply(super.listPartitionNames(catName, dbName, tableName, max)); } @Override
http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/MetaStoreTestUtils.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/MetaStoreTestUtils.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/MetaStoreTestUtils.java index 60fcb86..1d12cf9 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/MetaStoreTestUtils.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/MetaStoreTestUtils.java @@ -17,11 +17,13 @@ */ package org.apache.hadoop.hive.metastore; +import java.io.File; import java.io.IOException; import java.net.ConnectException; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; +import java.util.List; import java.util.Map; import org.apache.hadoop.conf.Configuration; @@ -30,9 +32,12 @@ import org.apache.hadoop.hive.metastore.conf.MetastoreConf; import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars; import org.apache.hadoop.hive.metastore.events.EventCleanerTask; import org.apache.hadoop.hive.metastore.security.HadoopThriftAuthBridge; +import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_CATALOG_NAME; + public class MetaStoreTestUtils { private static final Logger LOG = LoggerFactory.getLogger(MetaStoreTestUtils.class); public static final int RETRY_COUNT = 10; @@ -220,4 +225,28 @@ public class MetaStoreTestUtils { DefaultPartitionExpressionProxy.class, PartitionExpressionProxy.class); } } + + + public static String getTestWarehouseDir(String name) { + File dir = new File(System.getProperty("java.io.tmpdir"), name); + dir.deleteOnExit(); + return dir.getAbsolutePath(); + } + + /** + * There is no cascade option for dropping a catalog for security reasons. But this in + * inconvenient in tests, so this method does it. + * @param client metastore client + * @param catName catalog to drop, cannot be the default catalog + * @throws TException from underlying client calls + */ + public static void dropCatalogCascade(IMetaStoreClient client, String catName) throws TException { + if (catName != null && !catName.equals(DEFAULT_CATALOG_NAME)) { + List<String> databases = client.getAllDatabases(catName); + for (String db : databases) { + client.dropDatabase(catName, db, true, false, true); + } + client.dropCatalog(catName); + } + } } http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestAggregateStatsCache.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestAggregateStatsCache.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestAggregateStatsCache.java index b95f1f2..75ab4e0 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestAggregateStatsCache.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestAggregateStatsCache.java @@ -41,6 +41,8 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; +import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_CATALOG_NAME; + @Category(MetastoreUnitTest.class) public class TestAggregateStatsCache { static String DB_NAME = "db"; @@ -117,11 +119,11 @@ public class TestAggregateStatsCache { @Test public void testCacheKey() { - Key k1 = new Key("db", "tbl1", "col"); - Key k2 = new Key("db", "tbl1", "col"); + Key k1 = new Key("cat", "db", "tbl1", "col"); + Key k2 = new Key("cat", "db", "tbl1", "col"); // k1 equals k2 Assert.assertEquals(k1, k2); - Key k3 = new Key("db", "tbl2", "col"); + Key k3 = new Key("cat", "db", "tbl2", "col"); // k1 not equals k3 Assert.assertNotEquals(k1, k3); } @@ -140,16 +142,16 @@ public class TestAggregateStatsCache { ColumnStatisticsObj aggrColStats = getDummyLongColStat(colName, highVal, lowVal, numDVs, numNulls); // Now add to cache the dummy colstats for these 10 partitions - cache.add(DB_NAME, tblName, colName, 10, aggrColStats, bloomFilter); + cache.add(DEFAULT_CATALOG_NAME, DB_NAME, tblName, colName, 10, aggrColStats, bloomFilter); // Now get from cache - AggrColStats aggrStatsCached = cache.get(DB_NAME, tblName, colName, partNames); + AggrColStats aggrStatsCached = cache.get(DEFAULT_CATALOG_NAME, DB_NAME, tblName, colName, partNames); Assert.assertNotNull(aggrStatsCached); ColumnStatisticsObj aggrColStatsCached = aggrStatsCached.getColStats(); Assert.assertEquals(aggrColStats, aggrColStatsCached); // Now get a non-existant entry - aggrStatsCached = cache.get("dbNotThere", tblName, colName, partNames); + aggrStatsCached = cache.get(DEFAULT_CATALOG_NAME, "dbNotThere", tblName, colName, partNames); Assert.assertNull(aggrStatsCached); } @@ -167,25 +169,25 @@ public class TestAggregateStatsCache { ColumnStatisticsObj aggrColStats = getDummyLongColStat(colName, highVal, lowVal, numDVs, numNulls); // Now add to cache - cache.add(DB_NAME, tblName, colName, 10, aggrColStats, bloomFilter); + cache.add(DEFAULT_CATALOG_NAME, DB_NAME, tblName, colName, 10, aggrColStats, bloomFilter); // Now prepare partnames with only 5 partitions: [tab1part1...tab1part5] partNames = preparePartNames(tables.get(0), 1, 5); // This get should fail because its variance ((10-5)/5) is way past MAX_VARIANCE (0.5) - AggrColStats aggrStatsCached = cache.get(DB_NAME, tblName, colName, partNames); + AggrColStats aggrStatsCached = cache.get(DEFAULT_CATALOG_NAME, DB_NAME, tblName, colName, partNames); Assert.assertNull(aggrStatsCached); // Now prepare partnames with 10 partitions: [tab1part11...tab1part20], but with no overlap partNames = preparePartNames(tables.get(0), 11, 20); // This get should fail because its variance ((10-0)/10) is way past MAX_VARIANCE (0.5) - aggrStatsCached = cache.get(DB_NAME, tblName, colName, partNames); + aggrStatsCached = cache.get(DEFAULT_CATALOG_NAME, DB_NAME, tblName, colName, partNames); Assert.assertNull(aggrStatsCached); // Now prepare partnames with 9 partitions: [tab1part1...tab1part8], which are contained in the // object that we added to the cache partNames = preparePartNames(tables.get(0), 1, 8); // This get should succeed because its variance ((10-9)/9) is within past MAX_VARIANCE (0.5) - aggrStatsCached = cache.get(DB_NAME, tblName, colName, partNames); + aggrStatsCached = cache.get(DEFAULT_CATALOG_NAME, DB_NAME, tblName, colName, partNames); Assert.assertNotNull(aggrStatsCached); ColumnStatisticsObj aggrColStatsCached = aggrStatsCached.getColStats(); Assert.assertEquals(aggrColStats, aggrColStatsCached); @@ -206,13 +208,13 @@ public class TestAggregateStatsCache { ColumnStatisticsObj aggrColStats = getDummyLongColStat(colName, highVal, lowVal, numDVs, numNulls); // Now add to cache - cache.add(DB_NAME, tblName, colName, 10, aggrColStats, bloomFilter); + cache.add(DEFAULT_CATALOG_NAME, DB_NAME, tblName, colName, 10, aggrColStats, bloomFilter); // Sleep for 3 seconds Thread.sleep(3000); // Get should fail now (since TTL is 2s) and we've snoozed for 3 seconds - AggrColStats aggrStatsCached = cache.get(DB_NAME, tblName, colName, partNames); + AggrColStats aggrStatsCached = cache.get(DEFAULT_CATALOG_NAME, DB_NAME, tblName, colName, partNames); Assert.assertNull(aggrStatsCached); } http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestCatalogNonDefaultClient.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestCatalogNonDefaultClient.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestCatalogNonDefaultClient.java new file mode 100644 index 0000000..dfe05e9 --- /dev/null +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestCatalogNonDefaultClient.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hive.metastore; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.metastore.api.Catalog; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder; +import org.apache.hadoop.hive.metastore.conf.MetastoreConf; +import org.apache.hadoop.hive.metastore.security.HadoopThriftAuthBridge; +import org.apache.thrift.TException; +import org.junit.After; + +/** + * This tests metastore client calls that do not specify a catalog but with the config on the + * client set to go to a non-default catalog. + */ +public class TestCatalogNonDefaultClient extends TestNonCatCallsWithCatalog { + + final private String catName = "non_default_catalog"; + private String catLocation; + + @After + public void dropCatalog() throws TException { + MetaStoreTestUtils.dropCatalogCascade(client, catName); + } + + @Override + protected IMetaStoreClient getClient() throws Exception { + + Configuration svrConf = new Configuration(conf); + int port = MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), + svrConf); + // Only set the default catalog on the client. + MetastoreConf.setVar(conf, MetastoreConf.ConfVars.THRIFT_URIS, "thrift://localhost:" + port); + MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CATALOG_DEFAULT, catName); + IMetaStoreClient client = new HiveMetaStoreClient(conf); + assert !client.isLocalMetaStore(); + // Don't make any calls but catalog calls until the catalog has been created, as we just told + // the client to direct all calls to a catalog that does not yet exist. + catLocation = MetaStoreTestUtils.getTestWarehouseDir(catName); + Catalog cat = new CatalogBuilder() + .setName(catName) + .setLocation(catLocation) + .build(); + client.createCatalog(cat); + return client; + } + + @Override + protected String expectedCatalog() { + return catName; + } + + @Override + protected String expectedBaseDir() throws MetaException { + return catLocation; + } +} http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestCatalogNonDefaultSvr.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestCatalogNonDefaultSvr.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestCatalogNonDefaultSvr.java new file mode 100644 index 0000000..13c8723 --- /dev/null +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestCatalogNonDefaultSvr.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hive.metastore; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.metastore.api.Catalog; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder; +import org.apache.hadoop.hive.metastore.conf.MetastoreConf; +import org.apache.hadoop.hive.metastore.security.HadoopThriftAuthBridge; +import org.apache.thrift.TException; +import org.junit.After; + +/** + * This tests metastore client calls that do not specify a catalog but with the config on the + * server set to go to a non-default catalog. + */ +public class TestCatalogNonDefaultSvr extends TestNonCatCallsWithCatalog { + + final private String catName = "non_default_svr_catalog"; + private String catLocation; + private IMetaStoreClient catalogCapableClient; + + @After + public void dropCatalog() throws TException { + MetaStoreTestUtils.dropCatalogCascade(catalogCapableClient, catName); + catalogCapableClient.close(); + } + + @Override + protected IMetaStoreClient getClient() throws Exception { + // Separate client to create the catalog + catalogCapableClient = new HiveMetaStoreClient(conf); + catLocation = MetaStoreTestUtils.getTestWarehouseDir(catName); + Catalog cat = new CatalogBuilder() + .setName(catName) + .setLocation(catLocation) + .build(); + catalogCapableClient.createCatalog(cat); + catalogCapableClient.close(); + + MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CATALOG_DEFAULT, catName); + return new HiveMetaStoreClientPreCatalog(conf); + } + + @Override + protected String expectedCatalog() { + return catName; + } + + @Override + protected String expectedBaseDir() throws MetaException { + return catLocation; + } +} http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestCatalogOldClient.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestCatalogOldClient.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestCatalogOldClient.java new file mode 100644 index 0000000..bb57b85 --- /dev/null +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestCatalogOldClient.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hive.metastore; + +import org.apache.hadoop.hive.metastore.api.MetaException; + +import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_CATALOG_NAME; + +/** + * This tests calls with an older client, to make sure that if the client supplies no catalog + * information the server still does the right thing. I assumes the default catalog + */ +public class TestCatalogOldClient extends TestNonCatCallsWithCatalog { + + @Override + protected IMetaStoreClient getClient() throws MetaException { + return new HiveMetaStoreClientPreCatalog(conf); + } + + @Override + protected String expectedCatalog() { + return DEFAULT_CATALOG_NAME; + } + + @Override + protected String expectedBaseDir() throws MetaException { + return new Warehouse(conf).getWhRoot().toUri().getPath(); + } +} http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestFilterHooks.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestFilterHooks.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestFilterHooks.java index ea5dd3c..7dc69bc 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestFilterHooks.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestFilterHooks.java @@ -75,11 +75,12 @@ public class TestFilterHooks { } @Override - public List<String> filterTableNames(String dbName, List<String> tableList) throws MetaException { + public List<String> filterTableNames(String catName, String dbName, List<String> tableList) + throws MetaException { if (blockResults) { return new ArrayList<>(); } - return super.filterTableNames(dbName, tableList); + return super.filterTableNames(catName, dbName, tableList); } @Override @@ -124,12 +125,12 @@ public class TestFilterHooks { } @Override - public List<String> filterPartitionNames(String dbName, String tblName, + public List<String> filterPartitionNames(String catName, String dbName, String tblName, List<String> partitionNames) throws MetaException { if (blockResults) { return new ArrayList<>(); } - return super.filterPartitionNames(dbName, tblName, partitionNames); + return super.filterPartitionNames(catName, dbName, tblName, partitionNames); } } @@ -159,36 +160,32 @@ public class TestFilterHooks { msc.dropDatabase(DBNAME2, true, true, true); Database db1 = new DatabaseBuilder() .setName(DBNAME1) - .build(); - msc.createDatabase(db1); + .setCatalogName(Warehouse.DEFAULT_CATALOG_NAME) + .create(msc, conf); Database db2 = new DatabaseBuilder() .setName(DBNAME2) - .build(); - msc.createDatabase(db2); - Table tab1 = new TableBuilder() + .setCatalogName(Warehouse.DEFAULT_CATALOG_NAME) + .create(msc, conf); + new TableBuilder() .setDbName(DBNAME1) .setTableName(TAB1) .addCol("id", "int") .addCol("name", "string") - .build(); - msc.createTable(tab1); + .create(msc, conf); Table tab2 = new TableBuilder() .setDbName(DBNAME1) .setTableName(TAB2) .addCol("id", "int") .addPartCol("name", "string") - .build(); - msc.createTable(tab2); - Partition part1 = new PartitionBuilder() - .fromTable(tab2) + .create(msc, conf); + new PartitionBuilder() + .inTable(tab2) .addValue("value1") - .build(); - msc.add_partition(part1); - Partition part2 = new PartitionBuilder() - .fromTable(tab2) + .addToTable(msc, conf); + new PartitionBuilder() + .inTable(tab2) .addValue("value2") - .build(); - msc.add_partition(part2); + .addToTable(msc, conf); } @AfterClass http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveAlterHandler.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveAlterHandler.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveAlterHandler.java index ba8c1a0..adc82b0 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveAlterHandler.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveAlterHandler.java @@ -18,17 +18,24 @@ package org.apache.hadoop.hive.metastore; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest; import org.apache.hadoop.hive.metastore.api.*; +import org.apache.hadoop.hive.metastore.conf.MetastoreConf; +import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils; import org.junit.Test; import org.junit.experimental.categories.Category; import org.mockito.Mockito; import java.util.Arrays; +import static org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.getDefaultCatalog; + @Category(MetastoreUnitTest.class) public class TestHiveAlterHandler { + private Configuration conf = MetastoreConf.newMetastoreConf(); + @Test public void testAlterTableAddColNotUpdateStats() throws MetaException, InvalidObjectException, NoSuchObjectException { FieldSchema col1 = new FieldSchema("col1", "string", "col1 comment"); @@ -50,8 +57,9 @@ public class TestHiveAlterHandler { RawStore msdb = Mockito.mock(RawStore.class); Mockito.doThrow(new RuntimeException("shouldn't be called")).when(msdb).getTableColumnStatistics( - oldTable.getDbName(), oldTable.getTableName(), Arrays.asList("col1", "col2", "col3")); + getDefaultCatalog(conf), oldTable.getDbName(), oldTable.getTableName(), Arrays.asList("col1", "col2", "col3")); HiveAlterHandler handler = new HiveAlterHandler(); + handler.setConf(conf); handler.alterTableUpdateTableColumnStats(msdb, oldTable, newTable); } @@ -76,9 +84,10 @@ public class TestHiveAlterHandler { RawStore msdb = Mockito.mock(RawStore.class); HiveAlterHandler handler = new HiveAlterHandler(); + handler.setConf(conf); handler.alterTableUpdateTableColumnStats(msdb, oldTable, newTable); Mockito.verify(msdb, Mockito.times(1)).getTableColumnStatistics( - oldTable.getDbName(), oldTable.getTableName(), Arrays.asList("col1", "col2", "col3", "col4") + getDefaultCatalog(conf), oldTable.getDbName(), oldTable.getTableName(), Arrays.asList("col1", "col2", "col3", "col4") ); } @@ -103,8 +112,9 @@ public class TestHiveAlterHandler { RawStore msdb = Mockito.mock(RawStore.class); Mockito.doThrow(new RuntimeException("shouldn't be called")).when(msdb).getTableColumnStatistics( - oldTable.getDbName(), oldTable.getTableName(), Arrays.asList("col1", "col2", "col3", "col4")); + getDefaultCatalog(conf), oldTable.getDbName(), oldTable.getTableName(), Arrays.asList("col1", "col2", "col3", "col4")); HiveAlterHandler handler = new HiveAlterHandler(); + handler.setConf(conf); handler.alterTableUpdateTableColumnStats(msdb, oldTable, newTable); } http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java index 7091c5b..9a56c1c 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java @@ -178,10 +178,10 @@ public abstract class TestHiveMetaStore { client.dropTable(dbName, tblName); silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - client.createDatabase(db); - db = client.getDatabase(dbName); + new DatabaseBuilder() + .setName(dbName) + .create(client, conf); + Database db = client.getDatabase(dbName); Path dbPath = new Path(db.getLocationUri()); FileSystem fs = FileSystem.get(dbPath.toUri(), conf); @@ -209,9 +209,7 @@ public abstract class TestHiveMetaStore { .setSkewedColValueLocationMaps(Collections.singletonMap(skewedColValue, "location1")) .addPartCol("ds", ColumnType.STRING_TYPE_NAME) .addPartCol("hr", ColumnType.STRING_TYPE_NAME) - .build(); - - client.createTable(tbl); + .create(client, conf); if (isThriftClient) { // the createTable() above does not update the location in the 'tbl' @@ -709,19 +707,17 @@ public abstract class TestHiveMetaStore { client.dropTable(dbName, tblName); silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - db.setDescription("Alter Partition Test database"); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .setDescription("Alter Partition Test database") + .create(client, conf); Table tbl = new TableBuilder() .setDbName(dbName) .setTableName(tblName) .addCol("name", ColumnType.STRING_TYPE_NAME) .addCol("income", ColumnType.INT_TYPE_NAME) - .build(); - - client.createTable(tbl); + .create(client, conf); if (isThriftClient) { // the createTable() above does not update the location in the 'tbl' @@ -804,10 +800,10 @@ public abstract class TestHiveMetaStore { client.dropTable(dbName, tblName); silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - db.setDescription("Alter Partition Test database"); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .setDescription("Alter Partition Test database") + .create(client, conf); Table tbl = new TableBuilder() .setDbName(dbName) @@ -819,9 +815,7 @@ public abstract class TestHiveMetaStore { .addSerdeParam(ColumnType.SERIALIZATION_FORMAT, "1") .addPartCol("ds", ColumnType.STRING_TYPE_NAME) .addPartCol("hr", ColumnType.INT_TYPE_NAME) - .build(); - - client.createTable(tbl); + .create(client, conf); if (isThriftClient) { // the createTable() above does not update the location in the 'tbl' @@ -884,10 +878,10 @@ public abstract class TestHiveMetaStore { client.dropTable(dbName, tblName); silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - db.setDescription("Rename Partition Test database"); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .setDescription("Rename Partition Test database") + .create(client, conf); Table tbl = new TableBuilder() .setDbName(dbName) @@ -896,9 +890,7 @@ public abstract class TestHiveMetaStore { .addCol("income", ColumnType.INT_TYPE_NAME) .addPartCol("ds", ColumnType.STRING_TYPE_NAME) .addPartCol("hr", ColumnType.INT_TYPE_NAME) - .build(); - - client.createTable(tbl); + .create(client, conf); if (isThriftClient) { // the createTable() above does not update the location in the 'tbl' @@ -988,7 +980,7 @@ public abstract class TestHiveMetaStore { Database db = new DatabaseBuilder() .setName(TEST_DB1_NAME) .setOwnerName(SecurityUtils.getUser()) - .build(); + .build(conf); Assert.assertEquals(SecurityUtils.getUser(), db.getOwnerName()); client.createDatabase(db); @@ -1000,9 +992,10 @@ public abstract class TestHiveMetaStore { warehouse.getDatabasePath(db).toString(), db.getLocationUri()); assertEquals(db.getOwnerName(), SecurityUtils.getUser()); assertEquals(db.getOwnerType(), PrincipalType.USER); - Database db2 = new Database(); - db2.setName(TEST_DB2_NAME); - client.createDatabase(db2); + assertEquals(Warehouse.DEFAULT_CATALOG_NAME, db.getCatalogName()); + Database db2 = new DatabaseBuilder() + .setName(TEST_DB2_NAME) + .create(client, conf); db2 = client.getDatabase(TEST_DB2_NAME); @@ -1041,15 +1034,16 @@ public abstract class TestHiveMetaStore { silentDropDatabase(TEST_DB1_NAME); - Database db = new Database(); - db.setName(TEST_DB1_NAME); String dbLocation = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/test/_testDB_create_"; FileSystem fs = FileSystem.get(new Path(dbLocation).toUri(), conf); fs.mkdirs( new Path(MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/test"), new FsPermission((short) 0)); - db.setLocationUri(dbLocation); + Database db = new DatabaseBuilder() + .setName(TEST_DB1_NAME) + .setLocation(dbLocation) + .build(conf); boolean createFailed = false; @@ -1081,14 +1075,14 @@ public abstract class TestHiveMetaStore { // clear up any existing databases silentDropDatabase(TEST_DB1_NAME); - Database db = new Database(); - db.setName(TEST_DB1_NAME); String dbLocation = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/_testDB_create_"; - db.setLocationUri(dbLocation); - client.createDatabase(db); + new DatabaseBuilder() + .setName(TEST_DB1_NAME) + .setLocation(dbLocation) + .create(client, conf); - db = client.getDatabase(TEST_DB1_NAME); + Database db = client.getDatabase(TEST_DB1_NAME); assertEquals("name of returned db is different from that of inserted db", TEST_DB1_NAME, db.getName()); @@ -1106,14 +1100,15 @@ public abstract class TestHiveMetaStore { } assertTrue("Database " + TEST_DB1_NAME + " exists ", objectNotExist); - db = new Database(); - db.setName(TEST_DB1_NAME); dbLocation = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/_testDB_file_"; FileSystem fs = FileSystem.get(new Path(dbLocation).toUri(), conf); fs.createNewFile(new Path(dbLocation)); fs.deleteOnExit(new Path(dbLocation)); - db.setLocationUri(dbLocation); + db = new DatabaseBuilder() + .setName(TEST_DB1_NAME) + .setLocation(dbLocation) + .build(conf); boolean createFailed = false; try { @@ -1247,9 +1242,9 @@ public abstract class TestHiveMetaStore { client.dropTable(dbName, tblName); silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .create(client, conf); client.dropType(typeName); Type typ1 = new Type(); @@ -1268,9 +1263,7 @@ public abstract class TestHiveMetaStore { .setNumBuckets(1) .addBucketCol("name") .addStorageDescriptorParam("test_param_1", "Use this for comments etc") - .build(); - - client.createTable(tbl); + .create(client, conf); if (isThriftClient) { // the createTable() above does not update the location in the 'tbl' @@ -1397,7 +1390,8 @@ public abstract class TestHiveMetaStore { udbe = e; } assertNotNull(udbe); - assertTrue("DB not found", udbe.getMessage().contains("not find database db_that_doesnt_exist")); + assertTrue("DB not found", + udbe.getMessage().contains("not find database hive.db_that_doesnt_exist")); udbe = null; try { @@ -1498,9 +1492,9 @@ public abstract class TestHiveMetaStore { try { cleanUp(dbName, tblName, typeName); - Database db = new Database(); - db.setName(dbName); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .create(client, conf); createTableForTestFilter(dbName,tblName, tblOwner, lastAccessed, true); // Create a ColumnStatistics Obj @@ -1658,17 +1652,16 @@ public abstract class TestHiveMetaStore { client.dropTable(dbName, tblName); silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .create(client, conf); Table tbl = new TableBuilder() .setDbName(dbName) .setTableName(tblName) .addCol("name", ColumnType.STRING_TYPE_NAME, "") .setSerdeLib("no.such.class") - .build(); - client.createTable(tbl); + .create(client, conf); client.getSchema(dbName, tblName); } @@ -1683,9 +1676,9 @@ public abstract class TestHiveMetaStore { client.dropTable(dbName, tblName); silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .create(client, conf); ArrayList<FieldSchema> invCols = new ArrayList<>(2); invCols.add(new FieldSchema("n-ame", ColumnType.STRING_TYPE_NAME, "")); @@ -1695,7 +1688,7 @@ public abstract class TestHiveMetaStore { .setDbName(dbName) .setTableName(invTblName) .setCols(invCols) - .build(); + .build(conf); boolean failed = false; try { @@ -1834,9 +1827,9 @@ public abstract class TestHiveMetaStore { try { client.dropTable(dbName, tblName); silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .create(client, conf); client.dropType(typeName); Type typ1 = new Type(); @@ -1857,9 +1850,7 @@ public abstract class TestHiveMetaStore { .setNumBuckets(1) .addBucketCol("name") .addStorageDescriptorParam("test_param_1","Use this for comments etc") - .build(); - - client.createTable(tbl); + .create(client, conf); Table tbl2 = client.getTable(dbName, tblName); assertEquals(tbl2.getDbName(), dbName); @@ -1920,22 +1911,21 @@ public abstract class TestHiveMetaStore { try { silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); String dbLocation = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "_testDB_table_create_"; - db.setLocationUri(dbLocation); - client.createDatabase(db); - db = client.getDatabase(dbName); + new DatabaseBuilder() + .setName(dbName) + .setLocation(dbLocation) + .create(client, conf); + Database db = client.getDatabase(dbName); Table tbl = new TableBuilder() .setDbName(dbName) .setTableName(tblName_1) .addCol("name", ColumnType.STRING_TYPE_NAME) .addCol("income", ColumnType.INT_TYPE_NAME) - .build(); + .create(client, conf); - client.createTable(tbl); tbl = client.getTable(dbName, tblName_1); Path path = new Path(tbl.getSd().getLocation()); @@ -2014,9 +2004,9 @@ public abstract class TestHiveMetaStore { silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .create(client, conf); Table tbl = new TableBuilder() .setDbName(dbName) @@ -2026,8 +2016,7 @@ public abstract class TestHiveMetaStore { .addPartCol("p1", ColumnType.STRING_TYPE_NAME) .addPartCol("p2", ColumnType.STRING_TYPE_NAME) .addPartCol("p3", ColumnType.INT_TYPE_NAME) - .build(); - client.createTable(tbl); + .create(client, conf); tbl = client.getTable(dbName, tblName); @@ -2188,9 +2177,9 @@ public abstract class TestHiveMetaStore { silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .create(client, conf); Table tbl = new TableBuilder() .setDbName(dbName) @@ -2198,8 +2187,7 @@ public abstract class TestHiveMetaStore { .addCol("c1", ColumnType.STRING_TYPE_NAME) .addCol("c2", ColumnType.INT_TYPE_NAME) .addPartCol("p1", ColumnType.STRING_TYPE_NAME) - .build(); - client.createTable(tbl); + .create(client, conf); tbl = client.getTable(dbName, tblName); @@ -2249,9 +2237,8 @@ public abstract class TestHiveMetaStore { .addCol("c2", ColumnType.INT_TYPE_NAME) .addPartCol("p1", ColumnType.STRING_TYPE_NAME) .addPartCol("p2", ColumnType.STRING_TYPE_NAME) - .build(); + .create(client, conf); - client.createTable(tbl); tbl = client.getTable(dbName, tblName); add_partition(client, tbl, vals, "part1"); @@ -2334,10 +2321,10 @@ public abstract class TestHiveMetaStore { client.dropTable(dbName, tableName2); client.dropTable(dbName, tableName3); silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - db.setDescription("Alter Partition Test database"); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .setDescription("Alter Partition Test database") + .create(client, conf); Table table1 = createTableForTestFilter(dbName,tableName1, owner1, lastAccessTime1, true); Table table2 = createTableForTestFilter(dbName,tableName2, owner2, lastAccessTime2, true); @@ -2475,8 +2462,7 @@ public abstract class TestHiveMetaStore { .setTableParams(tableParams) .setOwner(owner) .setLastAccessTime(lastAccessTime) - .build(); - client.createTable(tbl); + .create(client, conf); if (isThriftClient) { // the createTable() above does not update the location in the 'tbl' @@ -2508,8 +2494,7 @@ public abstract class TestHiveMetaStore { .setTableName(tblName) .addCol("c1", ColumnType.STRING_TYPE_NAME) .addCol("c2", ColumnType.INT_TYPE_NAME) - .build(); - client.createTable(tbl1); + .create(client, conf); // get the table from the client, verify the name is correct Table tbl2 = client.getTable(dbName, tblName); @@ -2692,10 +2677,9 @@ public abstract class TestHiveMetaStore { private Database createDb(String dbName) throws Exception { if(null == dbName) { return null; } - Database db = new Database(); - db.setName(dbName); - client.createDatabase(db); - return db; + return new DatabaseBuilder() + .setName(dbName) + .create(client, conf); } private Type createType(String typeName, Map<String, String> fields) throws Throwable { @@ -2717,13 +2701,12 @@ public abstract class TestHiveMetaStore { */ private void createTable(String dbName, String tableName) throws TException { - Table t = new TableBuilder() + new TableBuilder() .setDbName(dbName) .setTableName(tableName) .addCol("foo", "string") .addCol("bar", "string") - .build(); - client.createTable(t); + .create(client, conf); } private List<Partition> createPartitions(String dbName, Table tbl, @@ -2765,8 +2748,7 @@ public abstract class TestHiveMetaStore { .addCol("income", ColumnType.INT_TYPE_NAME) .addPartCol("ds", ColumnType.STRING_TYPE_NAME) .addPartCol("hr", ColumnType.STRING_TYPE_NAME) - .build(); - client.createTable(tbl); + .create(client, conf); if (isThriftClient) { // the createTable() above does not update the location in the 'tbl' @@ -2797,12 +2779,12 @@ public abstract class TestHiveMetaStore { final String role1 = "role1"; silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - db.setOwnerName(user1); - db.setOwnerType(PrincipalType.USER); + Database db = new DatabaseBuilder() + .setName(dbName) + .setOwnerName(user1) + .setOwnerType(PrincipalType.USER) + .create(client, conf); - client.createDatabase(db); checkDbOwnerType(dbName, user1, PrincipalType.USER); db.setOwnerName(user2); @@ -2827,9 +2809,9 @@ public abstract class TestHiveMetaStore { // Setup silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .create(client, conf); for (String tableName : tableNames) { createTable(dbName, tableName); } @@ -2853,12 +2835,12 @@ public abstract class TestHiveMetaStore { String defaultUri = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/default_location.db"; String newUri = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/new_location.db"; - Database db = new Database(); - db.setName(dbName); - db.setLocationUri(defaultUri); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .setLocation(defaultUri) + .create(client, conf); - db = client.getDatabase(dbName); + Database db = client.getDatabase(dbName); assertEquals("Incorrect default location of the database", warehouse.getDnsPath(new Path(defaultUri)).toString(), db.getLocationUri()); @@ -2981,19 +2963,18 @@ public abstract class TestHiveMetaStore { client.dropTable(dbName, tblName); silentDropDatabase(dbName); - Database db = new Database(); - db.setName(dbName); - db.setDescription("Validate Table Columns test"); - client.createDatabase(db); + new DatabaseBuilder() + .setName(dbName) + .setDescription("Validate Table Columns test") + .create(client, conf); Table tbl = new TableBuilder() .setDbName(dbName) .setTableName(tblName) .addCol("name", ColumnType.STRING_TYPE_NAME) .addCol("income", ColumnType.INT_TYPE_NAME) - .build(); + .create(client, conf); - client.createTable(tbl); if (isThriftClient) { tbl = client.getTable(dbName, tblName); } http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java index b2d1d5a..df83171 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java @@ -27,6 +27,7 @@ import org.apache.hadoop.hive.metastore.api.PartitionSpec; import org.apache.hadoop.hive.metastore.api.SerDeInfo; import org.apache.hadoop.hive.metastore.api.StorageDescriptor; import org.apache.hadoop.hive.metastore.api.Table; +import org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder; import org.apache.hadoop.hive.metastore.conf.MetastoreConf; import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars; import org.apache.hadoop.hive.metastore.partition.spec.CompositePartitionSpecProxy; @@ -121,11 +122,9 @@ public class TestHiveMetaStorePartitionSpecs { true // Cascade. ); - hmsc.createDatabase(new Database(dbName, - "", // Description. - null, // Location. - null // Parameters. - )); + new DatabaseBuilder() + .setName(dbName) + .create(hmsc, conf); } // Get partition-path. For grid='XYZ', place the partition outside the table-path. http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreSchemaMethods.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreSchemaMethods.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreSchemaMethods.java index 1b30090..3d48c5f 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreSchemaMethods.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreSchemaMethods.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hive.metastore; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest; import org.apache.hadoop.hive.metastore.api.AlreadyExistsException; +import org.apache.hadoop.hive.metastore.api.Catalog; import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.metastore.api.FindSchemasByColsResp; @@ -36,6 +37,7 @@ import org.apache.hadoop.hive.metastore.api.SchemaVersionDescriptor; import org.apache.hadoop.hive.metastore.api.SchemaVersionState; import org.apache.hadoop.hive.metastore.api.SerDeInfo; import org.apache.hadoop.hive.metastore.api.SerdeType; +import org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder; import org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder; import org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder; import org.apache.hadoop.hive.metastore.client.builder.SchemaVersionBuilder; @@ -64,6 +66,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_CATALOG_NAME; import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_DATABASE_NAME; // This does the testing using a remote metastore, as that finds more issues in thrift @@ -74,11 +77,12 @@ public class TestHiveMetaStoreSchemaMethods { private static Map<PreEventContext.PreEventType, Integer> preEvents; private static IMetaStoreClient client; + private static Configuration conf; @BeforeClass public static void startMetastore() throws Exception { - Configuration conf = MetastoreConf.newMetastoreConf(); + conf = MetastoreConf.newMetastoreConf(); MetaStoreTestUtils.setConfForStandloneMode(conf); MetastoreConf.setClass(conf, ConfVars.EVENT_LISTENERS, SchemaEventListener.class, MetaStoreEventListener.class); @@ -101,7 +105,7 @@ public class TestHiveMetaStoreSchemaMethods { @Test(expected = NoSuchObjectException.class) public void getNonExistentSchema() throws TException { - client.getISchema(DEFAULT_DATABASE_NAME, "no.such.schema"); + client.getISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, "no.such.schema"); } @Test @@ -124,11 +128,13 @@ public class TestHiveMetaStoreSchemaMethods { Assert.assertEquals(1, (int)events.get(EventMessage.EventType.CREATE_ISCHEMA)); Assert.assertEquals(1, (int)transactionalEvents.get(EventMessage.EventType.CREATE_ISCHEMA)); - schema = client.getISchema(DEFAULT_DATABASE_NAME, schemaName); + schema = client.getISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName); Assert.assertEquals(1, (int)preEvents.get(PreEventContext.PreEventType.READ_ISCHEMA)); Assert.assertEquals(SchemaType.AVRO, schema.getSchemaType()); Assert.assertEquals(schemaName, schema.getName()); + Assert.assertEquals(DEFAULT_CATALOG_NAME, schema.getCatName()); + Assert.assertEquals(DEFAULT_DATABASE_NAME, schema.getDbName()); Assert.assertEquals(SchemaCompatibility.FORWARD, schema.getCompatibility()); Assert.assertEquals(SchemaValidation.LATEST, schema.getValidationLevel()); Assert.assertFalse(schema.isCanEvolve()); @@ -142,12 +148,12 @@ public class TestHiveMetaStoreSchemaMethods { schema.setCanEvolve(true); schema.setSchemaGroup(schemaGroup); schema.setDescription(description); - client.alterISchema(DEFAULT_DATABASE_NAME, schemaName, schema); + client.alterISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, schema); Assert.assertEquals(1, (int)preEvents.get(PreEventContext.PreEventType.ALTER_ISCHEMA)); Assert.assertEquals(1, (int)events.get(EventMessage.EventType.ALTER_ISCHEMA)); Assert.assertEquals(1, (int)transactionalEvents.get(EventMessage.EventType.ALTER_ISCHEMA)); - schema = client.getISchema(DEFAULT_DATABASE_NAME, schemaName); + schema = client.getISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName); Assert.assertEquals(2, (int)preEvents.get(PreEventContext.PreEventType.READ_ISCHEMA)); Assert.assertEquals(SchemaType.AVRO, schema.getSchemaType()); @@ -158,12 +164,12 @@ public class TestHiveMetaStoreSchemaMethods { Assert.assertEquals(schemaGroup, schema.getSchemaGroup()); Assert.assertEquals(description, schema.getDescription()); - client.dropISchema(DEFAULT_DATABASE_NAME, schemaName); + client.dropISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName); Assert.assertEquals(1, (int)preEvents.get(PreEventContext.PreEventType.DROP_ISCHEMA)); Assert.assertEquals(1, (int)events.get(EventMessage.EventType.DROP_ISCHEMA)); Assert.assertEquals(1, (int)transactionalEvents.get(EventMessage.EventType.DROP_ISCHEMA)); try { - client.getISchema(DEFAULT_DATABASE_NAME, schemaName); + client.getISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName); Assert.fail(); } catch (NoSuchObjectException e) { // all good @@ -172,11 +178,18 @@ public class TestHiveMetaStoreSchemaMethods { @Test public void iSchemaOtherDatabase() throws TException { + String catName = "other_cat"; + Catalog cat = new CatalogBuilder() + .setName(catName) + .setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)) + .build(); + client.createCatalog(cat); + String dbName = "other_db"; Database db = new DatabaseBuilder() .setName(dbName) - .build(); - client.createDatabase(db); + .setCatalogName(catName) + .create(client, conf); String schemaName = uniqueSchemaName(); String schemaGroup = "group1"; @@ -184,7 +197,7 @@ public class TestHiveMetaStoreSchemaMethods { ISchema schema = new ISchemaBuilder() .setSchemaType(SchemaType.AVRO) .setName(schemaName) - .setDbName(dbName) + .inDb(db) .setCompatibility(SchemaCompatibility.FORWARD) .setValidationLevel(SchemaValidation.LATEST) .setCanEvolve(false) @@ -193,10 +206,11 @@ public class TestHiveMetaStoreSchemaMethods { .build(); client.createISchema(schema); - schema = client.getISchema(dbName, schemaName); + schema = client.getISchema(catName, dbName, schemaName); Assert.assertEquals(SchemaType.AVRO, schema.getSchemaType()); Assert.assertEquals(schemaName, schema.getName()); + Assert.assertEquals(catName, schema.getCatName()); Assert.assertEquals(dbName, schema.getDbName()); Assert.assertEquals(SchemaCompatibility.FORWARD, schema.getCompatibility()); Assert.assertEquals(SchemaValidation.LATEST, schema.getValidationLevel()); @@ -211,12 +225,13 @@ public class TestHiveMetaStoreSchemaMethods { schema.setCanEvolve(true); schema.setSchemaGroup(schemaGroup); schema.setDescription(description); - client.alterISchema(dbName, schemaName, schema); + client.alterISchema(catName, dbName, schemaName, schema); - schema = client.getISchema(dbName, schemaName); + schema = client.getISchema(catName, dbName, schemaName); Assert.assertEquals(SchemaType.AVRO, schema.getSchemaType()); Assert.assertEquals(schemaName, schema.getName()); + Assert.assertEquals(catName, schema.getCatName()); Assert.assertEquals(dbName, schema.getDbName()); Assert.assertEquals(SchemaCompatibility.BOTH, schema.getCompatibility()); Assert.assertEquals(SchemaValidation.ALL, schema.getValidationLevel()); @@ -224,9 +239,9 @@ public class TestHiveMetaStoreSchemaMethods { Assert.assertEquals(schemaGroup, schema.getSchemaGroup()); Assert.assertEquals(description, schema.getDescription()); - client.dropISchema(dbName, schemaName); + client.dropISchema(catName, dbName, schemaName); try { - client.getISchema(dbName, schemaName); + client.getISchema(catName, dbName, schemaName); Assert.fail(); } catch (NoSuchObjectException e) { // all good @@ -252,7 +267,6 @@ public class TestHiveMetaStoreSchemaMethods { .build(); client.createISchema(schema); - schema = client.getISchema(DEFAULT_DATABASE_NAME, schemaName); Assert.assertNotNull(schema); Assert.assertEquals(SchemaType.HIVE, schema.getSchemaType()); @@ -273,19 +287,18 @@ public class TestHiveMetaStoreSchemaMethods { .setName(schemaName) .setDescription("a new description") .build(); - client.alterISchema(DEFAULT_DATABASE_NAME, schemaName, schema); + client.alterISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, schema); } @Test(expected = NoSuchObjectException.class) public void dropNonExistentSchema() throws TException { - client.dropISchema(DEFAULT_DATABASE_NAME, "no_such_schema"); + client.dropISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, "no_such_schema"); } @Test(expected = NoSuchObjectException.class) public void createVersionOfNonExistentSchema() throws TException { SchemaVersion schemaVersion = new SchemaVersionBuilder() .setSchemaName("noSchemaOfThisNameExists") - .setDbName(DEFAULT_DATABASE_NAME) .setVersion(1) .addCol("a", ColumnType.STRING_TYPE_NAME) .build(); @@ -333,10 +346,11 @@ public class TestHiveMetaStoreSchemaMethods { Assert.assertEquals(1, (int)events.get(EventMessage.EventType.ADD_SCHEMA_VERSION)); Assert.assertEquals(1, (int)transactionalEvents.get(EventMessage.EventType.ADD_SCHEMA_VERSION)); - schemaVersion = client.getSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, version); + schemaVersion = client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, version); Assert.assertNotNull(schemaVersion); Assert.assertEquals(schemaName, schemaVersion.getSchema().getSchemaName()); Assert.assertEquals(DEFAULT_DATABASE_NAME, schemaVersion.getSchema().getDbName()); + Assert.assertEquals(DEFAULT_CATALOG_NAME, schemaVersion.getSchema().getCatName()); Assert.assertEquals(version, schemaVersion.getVersion()); Assert.assertEquals(creationTime, schemaVersion.getCreatedAt()); Assert.assertEquals(SchemaVersionState.INITIATED, schemaVersion.getState()); @@ -357,12 +371,12 @@ public class TestHiveMetaStoreSchemaMethods { Assert.assertEquals(ColumnType.FLOAT_TYPE_NAME, cols.get(1).getType()); Assert.assertEquals(1, (int)preEvents.get(PreEventContext.PreEventType.READ_SCHEMA_VERSION)); - client.dropSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, version); + client.dropSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, version); Assert.assertEquals(1, (int)preEvents.get(PreEventContext.PreEventType.DROP_SCHEMA_VERSION)); Assert.assertEquals(1, (int)events.get(EventMessage.EventType.DROP_SCHEMA_VERSION)); Assert.assertEquals(1, (int)transactionalEvents.get(EventMessage.EventType.DROP_SCHEMA_VERSION)); try { - client.getSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, version); + client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, version); Assert.fail(); } catch (NoSuchObjectException e) { // all good @@ -371,17 +385,24 @@ public class TestHiveMetaStoreSchemaMethods { @Test public void addSchemaVersionOtherDb() throws TException { + String catName = "other_cat_for_schema_version"; + Catalog cat = new CatalogBuilder() + .setName(catName) + .setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)) + .build(); + client.createCatalog(cat); + String dbName = "other_db_for_schema_version"; Database db = new DatabaseBuilder() .setName(dbName) - .build(); - client.createDatabase(db); + .setCatalogName(catName) + .create(client, conf); String schemaName = uniqueSchemaName(); int version = 1; ISchema schema = new ISchemaBuilder() - .setDbName(dbName) + .inDb(db) .setSchemaType(SchemaType.AVRO) .setName(schemaName) .build(); @@ -414,10 +435,11 @@ public class TestHiveMetaStoreSchemaMethods { .build(); client.addSchemaVersion(schemaVersion); - schemaVersion = client.getSchemaVersion(dbName, schemaName, version); + schemaVersion = client.getSchemaVersion(catName, dbName, schemaName, version); Assert.assertNotNull(schemaVersion); Assert.assertEquals(schemaName, schemaVersion.getSchema().getSchemaName()); Assert.assertEquals(dbName, schemaVersion.getSchema().getDbName()); + Assert.assertEquals(catName, schemaVersion.getSchema().getCatName()); Assert.assertEquals(version, schemaVersion.getVersion()); Assert.assertEquals(creationTime, schemaVersion.getCreatedAt()); Assert.assertEquals(SchemaVersionState.INITIATED, schemaVersion.getState()); @@ -438,9 +460,9 @@ public class TestHiveMetaStoreSchemaMethods { Assert.assertEquals(ColumnType.FLOAT_TYPE_NAME, cols.get(1).getType()); Assert.assertEquals(1, (int)preEvents.get(PreEventContext.PreEventType.READ_SCHEMA_VERSION)); - client.dropSchemaVersion(dbName, schemaName, version); + client.dropSchemaVersion(catName, dbName, schemaName, version); try { - client.getSchemaVersion(dbName, schemaName, version); + client.getSchemaVersion(catName, dbName, schemaName, version); Assert.fail(); } catch (NoSuchObjectException e) { // all good @@ -484,7 +506,7 @@ public class TestHiveMetaStoreSchemaMethods { Assert.assertEquals(3, (int)events.get(EventMessage.EventType.ADD_SCHEMA_VERSION)); Assert.assertEquals(3, (int)transactionalEvents.get(EventMessage.EventType.ADD_SCHEMA_VERSION)); - schemaVersion = client.getSchemaLatestVersion(DEFAULT_DATABASE_NAME, schemaName); + schemaVersion = client.getSchemaLatestVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName); Assert.assertEquals(3, schemaVersion.getVersion()); Assert.assertEquals(3, schemaVersion.getColsSize()); List<FieldSchema> cols = schemaVersion.getCols(); @@ -497,7 +519,7 @@ public class TestHiveMetaStoreSchemaMethods { Assert.assertEquals(ColumnType.TIMESTAMP_TYPE_NAME, cols.get(2).getType()); Assert.assertEquals(1, (int)preEvents.get(PreEventContext.PreEventType.READ_SCHEMA_VERSION)); - List<SchemaVersion> versions = client.getSchemaAllVersions(DEFAULT_DATABASE_NAME, schemaName); + List<SchemaVersion> versions = client.getSchemaAllVersions(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName); Assert.assertEquals(2, (int)preEvents.get(PreEventContext.PreEventType.READ_SCHEMA_VERSION)); Assert.assertEquals(3, versions.size()); versions.sort(Comparator.comparingInt(SchemaVersion::getVersion)); @@ -534,7 +556,7 @@ public class TestHiveMetaStoreSchemaMethods { .setName(schemaName) .build(); client.createISchema(schema); - client.getSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, 1); + client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, 1); } @Test(expected = NoSuchObjectException.class) @@ -545,7 +567,18 @@ public class TestHiveMetaStoreSchemaMethods { .setName(schemaName) .build(); client.createISchema(schema); - client.getSchemaVersion("bogus", schemaName, 1); + client.getSchemaVersion(DEFAULT_CATALOG_NAME, "bogus", schemaName, 1); + } + + @Test(expected = NoSuchObjectException.class) + public void schemaVersionBogusCatalog() throws TException { + String schemaName = uniqueSchemaName(); + ISchema schema = new ISchemaBuilder() + .setSchemaType(SchemaType.AVRO) + .setName(schemaName) + .build(); + client.createISchema(schema); + client.getSchemaVersion("bogus", DEFAULT_DATABASE_NAME, schemaName, 1); } @Test(expected = NoSuchObjectException.class) @@ -566,7 +599,7 @@ public class TestHiveMetaStoreSchemaMethods { .build(); client.addSchemaVersion(schemaVersion); - client.getSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, 2); + client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, 2); } @Test(expected = NoSuchObjectException.class) @@ -577,12 +610,12 @@ public class TestHiveMetaStoreSchemaMethods { .setName(schemaName) .build(); client.createISchema(schema); - client.getSchemaLatestVersion(DEFAULT_DATABASE_NAME, schemaName); + client.getSchemaLatestVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName); } @Test(expected = NoSuchObjectException.class) public void getLatestSchemaNoSuchSchema() throws TException { - client.getSchemaLatestVersion(DEFAULT_DATABASE_NAME, "no.such.schema.with.this.name"); + client.getSchemaLatestVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, "no.such.schema.with.this.name"); } @Test(expected = NoSuchObjectException.class) @@ -593,7 +626,18 @@ public class TestHiveMetaStoreSchemaMethods { .setName(schemaName) .build(); client.createISchema(schema); - client.getSchemaLatestVersion("bogus", schemaName); + client.getSchemaLatestVersion(DEFAULT_CATALOG_NAME, "bogus", schemaName); + } + + @Test(expected = NoSuchObjectException.class) + public void latestSchemaVersionBogusCatalog() throws TException { + String schemaName = uniqueSchemaName(); + ISchema schema = new ISchemaBuilder() + .setSchemaType(SchemaType.AVRO) + .setName(schemaName) + .build(); + client.createISchema(schema); + client.getSchemaLatestVersion("bogus", DEFAULT_DATABASE_NAME, schemaName); } @Test(expected = NoSuchObjectException.class) @@ -604,12 +648,12 @@ public class TestHiveMetaStoreSchemaMethods { .setName(schemaName) .build(); client.createISchema(schema); - client.getSchemaAllVersions(DEFAULT_DATABASE_NAME, schemaName); + client.getSchemaAllVersions(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName); } @Test(expected = NoSuchObjectException.class) public void getAllSchemaNoSuchSchema() throws TException { - client.getSchemaAllVersions(DEFAULT_DATABASE_NAME, "no.such.schema.with.this.name"); + client.getSchemaAllVersions(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, "no.such.schema.with.this.name"); } @Test(expected = NoSuchObjectException.class) @@ -620,7 +664,18 @@ public class TestHiveMetaStoreSchemaMethods { .setName(schemaName) .build(); client.createISchema(schema); - client.getSchemaAllVersions("bogus", schemaName); + client.getSchemaAllVersions(DEFAULT_CATALOG_NAME, "bogus", schemaName); + } + + @Test(expected = NoSuchObjectException.class) + public void allSchemaVersionBogusCatalog() throws TException { + String schemaName = uniqueSchemaName(); + ISchema schema = new ISchemaBuilder() + .setSchemaType(SchemaType.AVRO) + .setName(schemaName) + .build(); + client.createISchema(schema); + client.getSchemaAllVersions("bogus", DEFAULT_DATABASE_NAME, schemaName); } @Test(expected = AlreadyExistsException.class) @@ -648,7 +703,7 @@ public class TestHiveMetaStoreSchemaMethods { @Test(expected = NoSuchObjectException.class) public void mapSerDeNoSuchSchema() throws TException { SerDeInfo serDeInfo = new SerDeInfo(uniqueSerdeName(), "lib", Collections.emptyMap()); - client.mapSchemaVersionToSerde(DEFAULT_DATABASE_NAME, uniqueSchemaName(), 1, serDeInfo.getName()); + client.mapSchemaVersionToSerde(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, uniqueSchemaName(), 1, serDeInfo.getName()); } @Test(expected = NoSuchObjectException.class) @@ -659,7 +714,7 @@ public class TestHiveMetaStoreSchemaMethods { .setName(uniqueSchemaName()) .build(); client.createISchema(schema); - client.mapSchemaVersionToSerde(DEFAULT_DATABASE_NAME, schema.getName(), 3, serDeInfo.getName()); + client.mapSchemaVersionToSerde(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), 3, serDeInfo.getName()); } @Test(expected = NoSuchObjectException.class) @@ -676,7 +731,7 @@ public class TestHiveMetaStoreSchemaMethods { .addCol("x", ColumnType.BOOLEAN_TYPE_NAME) .build(); client.addSchemaVersion(schemaVersion); - client.mapSchemaVersionToSerde(DEFAULT_DATABASE_NAME, schema.getName(), schemaVersion.getVersion(), uniqueSerdeName()); + client.mapSchemaVersionToSerde(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), schemaVersion.getVersion(), uniqueSerdeName()); } @Test @@ -698,8 +753,8 @@ public class TestHiveMetaStoreSchemaMethods { SerDeInfo serDeInfo = new SerDeInfo(uniqueSerdeName(), "lib", Collections.emptyMap()); client.addSerDe(serDeInfo); - client.mapSchemaVersionToSerde(DEFAULT_DATABASE_NAME, schema.getName(), schemaVersion.getVersion(), serDeInfo.getName()); - schemaVersion = client.getSchemaVersion(DEFAULT_DATABASE_NAME, schema.getName(), schemaVersion.getVersion()); + client.mapSchemaVersionToSerde(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), schemaVersion.getVersion(), serDeInfo.getName()); + schemaVersion = client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), schemaVersion.getVersion()); Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName()); // Create schema with a serde, then remap it @@ -713,27 +768,34 @@ public class TestHiveMetaStoreSchemaMethods { .build(); client.addSchemaVersion(schemaVersion); - schemaVersion = client.getSchemaVersion(DEFAULT_DATABASE_NAME, schema.getName(), 2); + schemaVersion = client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), 2); Assert.assertEquals(serDeName, schemaVersion.getSerDe().getName()); serDeInfo = new SerDeInfo(uniqueSerdeName(), "y", Collections.emptyMap()); client.addSerDe(serDeInfo); - client.mapSchemaVersionToSerde(DEFAULT_DATABASE_NAME, schema.getName(), 2, serDeInfo.getName()); - schemaVersion = client.getSchemaVersion(DEFAULT_DATABASE_NAME, schema.getName(), 2); + client.mapSchemaVersionToSerde(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), 2, serDeInfo.getName()); + schemaVersion = client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), 2); Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName()); } @Test public void mapSerdeToSchemaVersionOtherDb() throws TException { + String catName = "other_cat_for_map_to"; + Catalog cat = new CatalogBuilder() + .setName(catName) + .setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)) + .build(); + client.createCatalog(cat); + String dbName = "map_other_db"; Database db = new DatabaseBuilder() .setName(dbName) - .build(); - client.createDatabase(db); + .setCatalogName(catName) + .create(client, conf); ISchema schema = new ISchemaBuilder() .setSchemaType(SchemaType.AVRO) - .setDbName(dbName) + .inDb(db) .setName(uniqueSchemaName()) .build(); client.createISchema(schema); @@ -749,8 +811,8 @@ public class TestHiveMetaStoreSchemaMethods { SerDeInfo serDeInfo = new SerDeInfo(uniqueSerdeName(), "lib", Collections.emptyMap()); client.addSerDe(serDeInfo); - client.mapSchemaVersionToSerde(dbName, schema.getName(), schemaVersion.getVersion(), serDeInfo.getName()); - schemaVersion = client.getSchemaVersion(dbName, schema.getName(), schemaVersion.getVersion()); + client.mapSchemaVersionToSerde(catName, dbName, schema.getName(), schemaVersion.getVersion(), serDeInfo.getName()); + schemaVersion = client.getSchemaVersion(catName, dbName, schema.getName(), schemaVersion.getVersion()); Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName()); // Create schema with a serde, then remap it @@ -764,13 +826,13 @@ public class TestHiveMetaStoreSchemaMethods { .build(); client.addSchemaVersion(schemaVersion); - schemaVersion = client.getSchemaVersion(dbName, schema.getName(), 2); + schemaVersion = client.getSchemaVersion(catName, dbName, schema.getName(), 2); Assert.assertEquals(serDeName, schemaVersion.getSerDe().getName()); serDeInfo = new SerDeInfo(uniqueSerdeName(), "y", Collections.emptyMap()); client.addSerDe(serDeInfo); - client.mapSchemaVersionToSerde(dbName, schema.getName(), 2, serDeInfo.getName()); - schemaVersion = client.getSchemaVersion(dbName, schema.getName(), 2); + client.mapSchemaVersionToSerde(catName, dbName, schema.getName(), 2, serDeInfo.getName()); + schemaVersion = client.getSchemaVersion(catName, dbName, schema.getName(), 2); Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName()); } @@ -811,7 +873,7 @@ public class TestHiveMetaStoreSchemaMethods { @Test(expected = NoSuchObjectException.class) public void setVersionStateNoSuchSchema() throws TException { - client.setSchemaVersionState(DEFAULT_DATABASE_NAME, "no.such.schema", 1, SchemaVersionState.INITIATED); + client.setSchemaVersionState(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, "no.such.schema", 1, SchemaVersionState.INITIATED); } @Test(expected = NoSuchObjectException.class) @@ -822,7 +884,7 @@ public class TestHiveMetaStoreSchemaMethods { .setName(schemaName) .build(); client.createISchema(schema); - client.setSchemaVersionState(DEFAULT_DATABASE_NAME, schemaName, 1, SchemaVersionState.INITIATED); + client.setSchemaVersionState(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, 1, SchemaVersionState.INITIATED); } @Test @@ -841,37 +903,44 @@ public class TestHiveMetaStoreSchemaMethods { .build(); client.addSchemaVersion(schemaVersion); - schemaVersion = client.getSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, 1); + schemaVersion = client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, 1); Assert.assertNull(schemaVersion.getState()); - client.setSchemaVersionState(DEFAULT_DATABASE_NAME, schemaName, 1, SchemaVersionState.INITIATED); + client.setSchemaVersionState(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, 1, SchemaVersionState.INITIATED); Assert.assertEquals(1, (int)preEvents.get(PreEventContext.PreEventType.ALTER_SCHEMA_VERSION)); Assert.assertEquals(1, (int)events.get(EventMessage.EventType.ALTER_SCHEMA_VERSION)); Assert.assertEquals(1, (int)transactionalEvents.get(EventMessage.EventType.ALTER_SCHEMA_VERSION)); - schemaVersion = client.getSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, 1); + schemaVersion = client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, 1); Assert.assertEquals(SchemaVersionState.INITIATED, schemaVersion.getState()); - client.setSchemaVersionState(DEFAULT_DATABASE_NAME, schemaName, 1, SchemaVersionState.REVIEWED); + client.setSchemaVersionState(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, 1, SchemaVersionState.REVIEWED); Assert.assertEquals(2, (int)preEvents.get(PreEventContext.PreEventType.ALTER_SCHEMA_VERSION)); Assert.assertEquals(2, (int)events.get(EventMessage.EventType.ALTER_SCHEMA_VERSION)); Assert.assertEquals(2, (int)transactionalEvents.get(EventMessage.EventType.ALTER_SCHEMA_VERSION)); - schemaVersion = client.getSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, 1); + schemaVersion = client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, 1); Assert.assertEquals(SchemaVersionState.REVIEWED, schemaVersion.getState()); } @Test public void setVersionStateOtherDb() throws TException { + String catName = "other_cat_for_set_version"; + Catalog cat = new CatalogBuilder() + .setName(catName) + .setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)) + .build(); + client.createCatalog(cat); + String dbName = "other_db_set_state"; Database db = new DatabaseBuilder() .setName(dbName) - .build(); - client.createDatabase(db); + .setCatalogName(catName) + .create(client, conf); String schemaName = uniqueSchemaName(); ISchema schema = new ISchemaBuilder() .setSchemaType(SchemaType.AVRO) .setName(schemaName) - .setDbName(dbName) + .inDb(db) .build(); client.createISchema(schema); @@ -882,27 +951,27 @@ public class TestHiveMetaStoreSchemaMethods { .build(); client.addSchemaVersion(schemaVersion); - schemaVersion = client.getSchemaVersion(dbName, schemaName, 1); + schemaVersion = client.getSchemaVersion(catName, dbName, schemaName, 1); Assert.assertNull(schemaVersion.getState()); - client.setSchemaVersionState(dbName, schemaName, 1, SchemaVersionState.INITIATED); + client.setSchemaVersionState(catName, dbName, schemaName, 1, SchemaVersionState.INITIATED); Assert.assertEquals(1, (int)preEvents.get(PreEventContext.PreEventType.ALTER_SCHEMA_VERSION)); Assert.assertEquals(1, (int)events.get(EventMessage.EventType.ALTER_SCHEMA_VERSION)); Assert.assertEquals(1, (int)transactionalEvents.get(EventMessage.EventType.ALTER_SCHEMA_VERSION)); - schemaVersion = client.getSchemaVersion(dbName, schemaName, 1); + schemaVersion = client.getSchemaVersion(catName, dbName, schemaName, 1); Assert.assertEquals(SchemaVersionState.INITIATED, schemaVersion.getState()); - client.setSchemaVersionState(dbName, schemaName, 1, SchemaVersionState.REVIEWED); + client.setSchemaVersionState(catName, dbName, schemaName, 1, SchemaVersionState.REVIEWED); Assert.assertEquals(2, (int)preEvents.get(PreEventContext.PreEventType.ALTER_SCHEMA_VERSION)); Assert.assertEquals(2, (int)events.get(EventMessage.EventType.ALTER_SCHEMA_VERSION)); Assert.assertEquals(2, (int)transactionalEvents.get(EventMessage.EventType.ALTER_SCHEMA_VERSION)); - schemaVersion = client.getSchemaVersion(dbName, schemaName, 1); + schemaVersion = client.getSchemaVersion(catName, dbName, schemaName, 1); Assert.assertEquals(SchemaVersionState.REVIEWED, schemaVersion.getState()); } @Test(expected = NoSuchObjectException.class) public void dropNonExistentSchemaVersion() throws TException { - client.dropSchemaVersion(DEFAULT_DATABASE_NAME, "ther is no schema named this", 23); + client.dropSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, "ther is no schema named this", 23); } @Test @@ -910,8 +979,7 @@ public class TestHiveMetaStoreSchemaMethods { String dbName = "schema_query_db"; Database db = new DatabaseBuilder() .setName(dbName) - .build(); - client.createDatabase(db); + .create(client, conf); String schemaName1 = uniqueSchemaName(); ISchema schema1 = new ISchemaBuilder() http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreTimeout.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreTimeout.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreTimeout.java index 42df9c2..1560d05 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreTimeout.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreTimeout.java @@ -24,6 +24,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest; import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder; import org.apache.hadoop.hive.metastore.conf.MetastoreConf; import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars; import org.apache.hadoop.util.StringUtils; @@ -75,13 +76,9 @@ public class TestHiveMetaStoreTimeout { String dbName = "db"; client.dropDatabase(dbName, true, true); - Database db = new Database(); - db.setName(dbName); - try { - client.createDatabase(db); - } catch (MetaException e) { - Assert.fail("should not throw timeout exception: " + e.getMessage()); - } + new DatabaseBuilder() + .setName(dbName) + .create(client, conf); client.dropDatabase(dbName, true, true); } @@ -93,8 +90,9 @@ public class TestHiveMetaStoreTimeout { String dbName = "db"; client.dropDatabase(dbName, true, true); - Database db = new Database(); - db.setName(dbName); + Database db = new DatabaseBuilder() + .setName(dbName) + .build(conf); try { client.createDatabase(db); Assert.fail("should throw timeout exception."); @@ -114,8 +112,9 @@ public class TestHiveMetaStoreTimeout { // no timeout before reset client.dropDatabase(dbName, true, true); - Database db = new Database(); - db.setName(dbName); + Database db = new DatabaseBuilder() + .setName(dbName) + .build(conf); try { client.createDatabase(db); } catch (MetaException e) { http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreWithEnvironmentContext.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreWithEnvironmentContext.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreWithEnvironmentContext.java index d53a606..38b3f6e 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreWithEnvironmentContext.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreWithEnvironmentContext.java @@ -46,6 +46,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; +import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_CATALOG_NAME; import static org.junit.Assert.assertEquals; /** @@ -85,6 +86,7 @@ public class TestHiveMetaStoreWithEnvironmentContext { envContext = new EnvironmentContext(envProperties); db.setName(dbName); + db.setCatalogName(DEFAULT_CATALOG_NAME); table = new TableBuilder() .setDbName(dbName) @@ -93,13 +95,13 @@ public class TestHiveMetaStoreWithEnvironmentContext { .addPartCol("b", "string") .addCol("a", "string") .addCol("b", "string") - .build(); + .build(conf); partition = new PartitionBuilder() - .fromTable(table) + .inTable(table) .addValue("2011") - .build(); + .build(conf); DummyListener.notifyList.clear(); } @@ -171,7 +173,7 @@ public class TestHiveMetaStoreWithEnvironmentContext { assert dropPartByNameEvent.getStatus(); assertEquals(envContext, dropPartByNameEvent.getEnvironmentContext()); - msc.dropTable(dbName, tblName, true, false, envContext); + msc.dropTable(DEFAULT_CATALOG_NAME, dbName, tblName, true, false, envContext); listSize++; assertEquals(notifyList.size(), listSize); DropTableEvent dropTblEvent = (DropTableEvent)notifyList.get(listSize-1); http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMarkPartition.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMarkPartition.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMarkPartition.java index b477088..00fae25 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMarkPartition.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMarkPartition.java @@ -63,8 +63,7 @@ public class TestMarkPartition { msc.dropDatabase(dbName, true, true, true); Database db = new DatabaseBuilder() .setName(dbName) - .build(); - msc.createDatabase(db); + .create(msc, conf); final String tableName = "tmptbl"; msc.dropTable(dbName, tableName, true, true); @@ -73,13 +72,12 @@ public class TestMarkPartition { .setTableName(tableName) .addCol("a", "string") .addPartCol("b", "string") - .build(); - msc.createTable(table); + .create(msc, conf); Partition part = new PartitionBuilder() - .fromTable(table) + .inTable(table) .addValue("2011") - .build(); + .build(conf); msc.add_partition(part); Map<String,String> kvs = new HashMap<>(); kvs.put("b", "'2011'"); http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEndFunctionListener.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEndFunctionListener.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEndFunctionListener.java index 1a720fb..b919eef 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEndFunctionListener.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEndFunctionListener.java @@ -72,8 +72,8 @@ public class TestMetaStoreEndFunctionListener { Database db = new DatabaseBuilder() .setName(dbName) - .build(); - msc.createDatabase(db); + .setCatalogName(Warehouse.DEFAULT_CATALOG_NAME) + .create(msc, conf); try { msc.getDatabase("UnknownDB"); @@ -91,13 +91,12 @@ public class TestMetaStoreEndFunctionListener { assertEquals(context.getInputTableName(), null); String unknownTable = "UnknownTable"; - Table table = new TableBuilder() - .setDbName(db) + new TableBuilder() + .inDb(db) .setTableName(tblName) .addCol("a", "string") .addPartCol("b", "string") - .build(); - msc.createTable(table); + .create(msc, conf); try { msc.getTable(dbName, unknownTable); } catch (Exception e1) { http://git-wip-us.apache.org/repos/asf/hive/blob/ba8a99e1/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java index fb7f940..fb4a761 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java @@ -201,13 +201,12 @@ public class TestMetaStoreEventListener { assertEquals(notifyList.size(), listSize); assertEquals(preNotifyList.size(), listSize); - Database db = new DatabaseBuilder() + new DatabaseBuilder() .setName(dbName) - .build(); - msc.createDatabase(db); + .create(msc, conf); listSize++; PreCreateDatabaseEvent preDbEvent = (PreCreateDatabaseEvent)(preNotifyList.get(preNotifyList.size() - 1)); - db = msc.getDatabase(dbName); + Database db = msc.getDatabase(dbName); assertEquals(listSize, notifyList.size()); assertEquals(listSize + 1, preNotifyList.size()); validateCreateDb(db, preDbEvent.getDatabase()); @@ -217,12 +216,11 @@ public class TestMetaStoreEventListener { validateCreateDb(db, dbEvent.getDatabase()); Table table = new TableBuilder() - .setDbName(db) + .inDb(db) .setTableName(tblName) .addCol("a", "string") .addPartCol("b", "string") - .build(); - msc.createTable(table); + .create(msc, conf); PreCreateTableEvent preTblEvent = (PreCreateTableEvent)(preNotifyList.get(preNotifyList.size() - 1)); listSize++; Table tbl = msc.getTable(dbName, tblName); @@ -234,18 +232,17 @@ public class TestMetaStoreEventListener { validateCreateTable(tbl, tblEvent.getTable()); - Partition part = new PartitionBuilder() - .fromTable(table) + new PartitionBuilder() + .inTable(table) .addValue("2011") - .build(); - msc.add_partition(part); + .addToTable(msc, conf); listSize++; assertEquals(notifyList.size(), listSize); PreAddPartitionEvent prePartEvent = (PreAddPartitionEvent)(preNotifyList.get(preNotifyList.size() - 1)); AddPartitionEvent partEvent = (AddPartitionEvent)(notifyList.get(listSize-1)); Assert.assertTrue(partEvent.getStatus()); - part = msc.getPartition("hive2038", "tmptbl", "b=2011"); + Partition part = msc.getPartition("hive2038", "tmptbl", "b=2011"); Partition partAdded = partEvent.getPartitionIterator().next(); validateAddPartition(part, partAdded); validateTableInAddPartition(tbl, partEvent.getTable());
