@Override public List<Table> getTableObjectsByName(String dbName, List<String> tableNames) throws TException { return getTableObjectsByName(getDefaultCatalog(conf), dbName, tableNames); }
/** * Help method which gets hive tables for a given schema|DB name and a list of table names. * Retries once if the first call fails with TExcption other than connection-lost problems. * @param mClient * @param schemaName * @param tableNames * @return list of hive table instances. **/ public static List<Table> getTableObjectsByNameHelper(final HiveMetaStoreClient mClient, final String schemaName, final List<String> tableNames) throws TException { try { return mClient.getTableObjectsByName(schemaName, tableNames); } catch (MetaException | InvalidOperationException | UnknownDBException e) { throw e; } catch (TException e) { logger.warn("Failure while attempting to get tables by names. Retries once. ", e); try { mClient.close(); } catch (Exception ex) { logger.warn("Failure while attempting to close existing hive metastore connection. May leak connection.", ex); } mClient.reconnect(); return mClient.getTableObjectsByName(schemaName, tableNames); } }
@Override public List<org.apache.hadoop.hive.metastore.api.Table> getTableObjectsByName(String dbName, List<String> tableNames) throws MetaException, InvalidOperationException, UnknownDBException, TException { dbName = dbName.toLowerCase(); if (SessionState.get().getTempTables().size() == 0) { // No temp tables, just call underlying client return super.getTableObjectsByName(dbName, tableNames); } List<org.apache.hadoop.hive.metastore.api.Table> tables = new ArrayList<org.apache.hadoop.hive.metastore.api.Table>(); for (String tableName : tableNames) { try { org.apache.hadoop.hive.metastore.api.Table table = getTable(dbName, tableName); if (table != null) { tables.add(table); } } catch (NoSuchObjectException err) { // Ignore error, just return the valid tables that are found. } } return tables; }
@Override public List<org.apache.hadoop.hive.metastore.api.Table> getTableObjectsByName(String dbName, List<String> tableNames) throws MetaException, InvalidOperationException, UnknownDBException, TException { dbName = dbName.toLowerCase(); if (SessionState.get() == null || SessionState.get().getTempTables().size() == 0) { // No temp tables, just call underlying client return super.getTableObjectsByName(dbName, tableNames); } List<org.apache.hadoop.hive.metastore.api.Table> tables = new ArrayList<org.apache.hadoop.hive.metastore.api.Table>(); for (String tableName : tableNames) { try { org.apache.hadoop.hive.metastore.api.Table table = getTable(dbName, tableName); if (table != null) { tables.add(table); } } catch (NoSuchObjectException err) { // Ignore error, just return the valid tables that are found. } } return tables; }
@Test public void testNumReturned() throws MetaException, InvalidOperationException, UnknownDBException, TException { HiveMetaStoreClient msc = mock(HiveMetaStoreClient.class); // create a mocked metastore client that returns 3 table objects every time it is called // will use same size for TableIterable batch fetch size List<Table> threeTables = Arrays.asList(new Table(), new Table(), new Table()); when(msc.getTableObjectsByName(anyString(), anyListOf(String.class))).thenReturn(threeTables); List<String> tableNames = Arrays.asList("a", "b", "c", "d", "e", "f"); TableIterable tIterable = new TableIterable(msc, "dummy", tableNames, threeTables.size()); tIterable.iterator(); Iterator<Table> tIter = tIterable.iterator(); int size = 0; while(tIter.hasNext()) { size++; tIter.next(); } assertEquals("Number of table objects returned", size, tableNames.size()); verify(msc).getTableObjectsByName("dummy", Arrays.asList("a", "b", "c")); verify(msc).getTableObjectsByName("dummy", Arrays.asList("d", "e", "f")); } }
/** * Test table objects can be retrieved in batches */ @Test public void testGetTableObjects() throws Exception { String dbName = "db"; List<String> tableNames = Arrays.asList("table1", "table2", "table3", "table4", "table5"); // Setup silentDropDatabase(dbName); new DatabaseBuilder() .setName(dbName) .create(client, conf); for (String tableName : tableNames) { createTable(dbName, tableName); } createMaterializedView(dbName, "mv1", Sets.newHashSet("db.table1", "db.table2")); // Test List<Table> tableObjs = client.getTableObjectsByName(dbName, tableNames); // Verify assertEquals(tableNames.size(), tableObjs.size()); for(Table table : tableObjs) { assertTrue(tableNames.contains(table.getTableName().toLowerCase())); } // Cleanup client.dropDatabase(dbName, true, true, true); }
boolean deleteData) throws TException { String dbNameWithCatalog = prependCatalogToDbName(catName, dbName, conf); List<Table> tables = getTableObjectsByName(catName, dbName, tableList); boolean success = false; try {
tableNames.add(tblName); tableNames.add(tblName2); List<Table> foundTables = client.getTableObjectsByName(dbName, tableNames); foundTables = client.getTableObjectsByName(dbName, tableNames); assertEquals(foundTables.size(), 2); foundTables = client.getTableObjectsByName(dbName, null); } catch (InvalidOperationException e) { ioe = e; foundTables = client.getTableObjectsByName("db_that_doesnt_exist", tableNames); } catch (UnknownDBException e) { udbe = e; foundTables = client.getTableObjectsByName("", tableNames); } catch (UnknownDBException e) { udbe = e;
@Override public List<org.apache.hadoop.hive.metastore.api.Table> getTableObjectsByName(String dbName, List<String> tableNames) throws MetaException, InvalidOperationException, UnknownDBException, TException { dbName = dbName.toLowerCase(); if (SessionState.get().getTempTables().size() == 0) { // No temp tables, just call underlying client return super.getTableObjectsByName(dbName, tableNames); } List<org.apache.hadoop.hive.metastore.api.Table> tables = new ArrayList<org.apache.hadoop.hive.metastore.api.Table>(); for (String tableName : tableNames) { try { org.apache.hadoop.hive.metastore.api.Table table = getTable(dbName, tableName); if (table != null) { tables.add(table); } } catch (NoSuchObjectException err) { // Ignore error, just return the valid tables that are found. } } return tables; }
try (HMSClient client = clientFactory.connect()) { c = client; List<Table> tables = client.getClient().getTableObjectsByName(dbName, tableNames);
tableNames.add(tableName); Table mockTable = makeTable(dbName, tableName); Mockito.when(client.getTableObjectsByName(dbName, Lists.newArrayList(tableName))) .thenReturn(Lists.newArrayList(mockTable));
tableNames.add(tableName); Table mockTable = makeTable(dbName, tableName); Mockito.when(client.getTableObjectsByName(dbName, Lists.newArrayList(tableName))) .thenReturn(Lists.newArrayList(mockTable));
Mockito.when(tab12.getSd()).thenReturn(sd21); Mockito.when(client.getTableObjectsByName("db1", Lists.newArrayList("tab1"))).thenReturn(Lists.newArrayList(tab1)); Mockito.when(client.getTableObjectsByName("db1", Lists.newArrayList("tab12"))).thenReturn(Lists.newArrayList(tab12)); Mockito.when(client.getAllTables("db1")).