return mClient.getAllDatabases(); } catch (MetaException e) { throw e; return mClient.getAllDatabases();
/** * Get all existing database names. * * @return List of database names. * @throws HiveException */ public List<String> getAllDatabases() throws HiveException { try { return getMSC().getAllDatabases(); } catch (Exception e) { throw new HiveException(e); } }
/** * Get all existing database names. * * @return List of database names. * @throws HiveException */ public List<String> getAllDatabases() throws HiveException { try { return getMSC().getAllDatabases(); } catch (Exception e) { throw new HiveException(e); } }
for (String dbName : getMSC().getAllDatabases()) {
/** * Get all tables in db with given table pattern. */ public Collection<DbAndTable> getTables() throws IOException { List<DbAndTable> tables = Lists.newArrayList(); try (AutoReturnableObject<IMetaStoreClient> client = this.clientPool.getClient()) { Iterable<String> databases = Iterables.filter(client.get().getAllDatabases(), new Predicate<String>() { @Override public boolean apply(String db) { return HiveDatasetFinder.this.whitelistBlacklist.acceptDb(db); } }); for (final String db : databases) { Iterable<String> tableNames = Iterables.filter(client.get().getAllTables(db), new Predicate<String>() { @Override public boolean apply(String table) { return HiveDatasetFinder.this.whitelistBlacklist.acceptTable(db, table); } }); for (String tableName : tableNames) { tables.add(new DbAndTable(db, tableName)); } } } catch (Exception exc) { throw new IOException(exc); } return tables; }
IMetaStoreClient hms = getHMS(conf); LOG.debug("Looking for databases"); List<String> databases = hms.getAllDatabases();//TException LOG.debug("Found " + databases.size() + " databases to process"); List<String> convertToAcid = new ArrayList<>();
for (String dbName : getMSC().getAllDatabases()) {
/** * 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); } } }
/** * Tests {@link HiveMetaStoreClient#newSynchronizedClient}. Does not * actually test multithreading, but does verify that the proxy * at least works correctly. */ @Test public void testSynchronized() throws Exception { int currentNumberOfDbs = client.getAllDatabases().size(); IMetaStoreClient synchronizedClient = HiveMetaStoreClient.newSynchronizedClient(client); List<String> databases = synchronizedClient.getAllDatabases(); assertEquals(currentNumberOfDbs, databases.size()); }
@Test public void testDropDatabaseCaseInsensitive() throws Exception { Database database = testDatabases[0]; // Test in upper case client.dropDatabase(database.getName().toUpperCase()); List<String> allDatabases = client.getAllDatabases(); Assert.assertEquals("All databases size", 4, allDatabases.size()); // Test in mixed case client.createDatabase(database); client.dropDatabase("TesT_DatABaSe_1"); allDatabases = client.getAllDatabases(); Assert.assertEquals("All databases size", 4, allDatabases.size()); }
for (String dbName : hiveClient.getAllDatabases()) { numDb++; HiveObjectRef dbToRefresh = getObjToRefresh(HiveObjectType.DATABASE, dbName, null);
@Test public void testRetriableClientWithConnLifetime() throws Exception { Configuration newConf = MetastoreConf.newMetastoreConf(new Configuration(this.conf)); MetastoreConf.setTimeVar(newConf, ConfVars.CLIENT_SOCKET_LIFETIME, 4, TimeUnit.SECONDS); MetaStoreTestUtils.setConfForStandloneMode(newConf); long timeout = 5 * 1000; // Lets use a timeout more than the socket lifetime to simulate a reconnect // Test a normal retriable client IMetaStoreClient client = RetryingMetaStoreClient.getProxy(newConf, getHookLoader(), HiveMetaStoreClient.class.getName()); client.getAllDatabases(); client.close(); // Connect after the lifetime, there should not be any failures client = RetryingMetaStoreClient.getProxy(newConf, getHookLoader(), HiveMetaStoreClient.class.getName()); Thread.sleep(timeout); client.getAllDatabases(); client.close(); }
@After public void tearDown() throws TException { // Drop any left over catalogs List<String> catalogs = client.getCatalogs(); for (String catName : catalogs) { if (!catName.equalsIgnoreCase(DEFAULT_CATALOG_NAME)) { // First drop any databases in catalog List<String> databases = client.getAllDatabases(catName); for (String db : databases) { client.dropDatabase(catName, db, true, false, true); } client.dropCatalog(catName); } else { List<String> databases = client.getAllDatabases(catName); for (String db : databases) { if (!db.equalsIgnoreCase(Warehouse.DEFAULT_DATABASE_NAME)) { client.dropDatabase(catName, db, true, false, true); } } } } try { if (client != null) { client.close(); } } finally { client = null; } }
if (!catName.equalsIgnoreCase(DEFAULT_CATALOG_NAME)) { List<String> databases = client.getAllDatabases(catName); for (String db : databases) { client.dropDatabase(catName, db, true, false, true); List<String> databases = client.getAllDatabases(catName); for (String db : databases) { if (!db.equalsIgnoreCase(Warehouse.DEFAULT_DATABASE_NAME)) {
if (!catName.equalsIgnoreCase(Warehouse.DEFAULT_CATALOG_NAME)) { List<String> databases = client.getAllDatabases(catName); for (String db : databases) { client.dropDatabase(catName, db, true, false, true); List<String> databases = client.getAllDatabases(catName); for (String db : databases) { if (!db.equalsIgnoreCase(DEFAULT_DATABASE_NAME)) {
@Test public void testGetAllDatabases() throws Exception { List<String> allDatabases = client.getAllDatabases(); Assert.assertEquals("All databases size", 5, allDatabases.size()); for(Database database : testDatabases) { Assert.assertTrue("Checking database names", allDatabases.contains(database.getName())); } Assert.assertTrue("Checnking that default database is returned", allDatabases.contains(DEFAULT_DATABASE)); // Drop one database, see what remains client.dropDatabase(testDatabases[1].getName()); allDatabases = client.getAllDatabases(); Assert.assertEquals("All databases size", 4, allDatabases.size()); for(Database database : testDatabases) { if (!database.getName().equals(testDatabases[1].getName())) { Assert.assertTrue("Checking database names", allDatabases.contains(database.getName())); } } Assert.assertTrue("Checnking that default database is returned", allDatabases.contains(DEFAULT_DATABASE)); Assert.assertFalse("Checking that the deleted database is not returned", allDatabases.contains(testDatabases[1].getName())); }
private HiveMetastoreClientPool getTestPool(List<HiveDatasetFinder.DbAndTable> dbAndTables) throws Exception { SetMultimap<String, String> entities = HashMultimap.create(); for (HiveDatasetFinder.DbAndTable dbAndTable : dbAndTables) { entities.put(dbAndTable.getDb(), dbAndTable.getTable()); } HiveMetastoreClientPool pool = Mockito.mock(HiveMetastoreClientPool.class); IMetaStoreClient client = Mockito.mock(IMetaStoreClient.class); Mockito.when(client.getAllDatabases()).thenReturn(Lists.newArrayList(entities.keySet())); for (String db : entities.keySet()) { Mockito.doReturn(Lists.newArrayList(entities.get(db))).when(client).getAllTables(db); } for (HiveDatasetFinder.DbAndTable dbAndTable : dbAndTables) { Table table = new Table(); table.setDbName(dbAndTable.getDb()); table.setTableName(dbAndTable.getTable()); StorageDescriptor sd = new StorageDescriptor(); sd.setLocation("/tmp/test"); table.setSd(sd); Mockito.doReturn(table).when(client).getTable(dbAndTable.getDb(), dbAndTable.getTable()); } @SuppressWarnings("unchecked") AutoReturnableObject<IMetaStoreClient> aro = Mockito.mock(AutoReturnableObject.class); Mockito.when(aro.get()).thenReturn(client); Mockito.when(pool.getHiveRegProps()).thenReturn(null); Mockito.when(pool.getClient()).thenReturn(aro); return pool; }
Assert.assertEquals(expectedCatalog(), fetched.getCatalogName()); Set<String> fetchedDbs = new HashSet<>(client.getAllDatabases()); for (String dbName : dbNames) Assert.assertTrue(fetchedDbs.contains(dbName)); Assert.assertFalse(dir.exists()); fetchedDbs = new HashSet<>(client.getAllDatabases()); for (String dbName : dbNames) Assert.assertFalse(fetchedDbs.contains(dbName));
@Before public void setUp() throws Exception { // Get new client client = metaStore.getClient(); // Clean up the databases for(String databaseName : client.getAllDatabases()) { if (!databaseName.equals(DEFAULT_DATABASE)) { client.dropDatabase(databaseName, true, true, true); } } testDatabases[0] = new DatabaseBuilder().setName("test_database_1").create(client, metaStore.getConf()); testDatabases[1] = new DatabaseBuilder().setName("test_database_to_find_1").create(client, metaStore.getConf()); testDatabases[2] = new DatabaseBuilder().setName("test_database_to_find_2").create(client, metaStore.getConf()); testDatabases[3] = new DatabaseBuilder().setName("test_database_hidden_1").create(client, metaStore.getConf()); // Create the databases, and reload them from the MetaStore for (int i=0; i < testDatabases.length; i++) { testDatabases[i] = client.getDatabase(testDatabases[i].getName()); } }
List<String> databases = client.getAllDatabases(); for (String db : databases) { if (!DEFAULT_DATABASE_NAME.equals(db)) {