@Test(expected = MetaException.class) public void testGetTablesNullDatabase() throws Exception { client.getTables(null, "*_tO_FiND*"); }
@Test public void getTablesBogusCatalog() throws TException { Assert.assertEquals(0, client.getTables("nosuch", DEFAULT_DATABASE_NAME, "*_to_find_*").size()); }
@Test public void testGetTablesCaseInsensitive() throws Exception { // Check case insensitive search List<String> tables = client.getTables(DEFAULT_DATABASE, "*_tO_FiND*"); Assert.assertEquals("Found tables size", 2, tables.size()); Assert.assertTrue("Comparing tablenames", tables.contains(testTables[2].getTableName())); Assert.assertTrue("Comparing tablenames", tables.contains(testTables[3].getTableName())); }
@Override public List<String> listTableNamesByPattern(String dbName, String tablePattern) throws HCatException { List<String> tableNames = null; try { tableNames = hmsClient.getTables(checkDB(dbName), tablePattern); } catch (MetaException e) { throw new HCatException("MetaException while fetching table names. " + e.getMessage(), e); } catch (UnknownDBException e) { throw new HCatException("UnknownDB " + dbName + " while fetching table names.", e); } catch (TException e) { throw new HCatException("Transport exception while fetching table names. " + e.getMessage(), e); } return tableNames; }
@Test public void testGetTables() throws Exception { // Find tables which name contains _to_find_ in the default database List<String> tables = client.getTables(DEFAULT_DATABASE, "*_to_find_*"); Assert.assertEquals("All tables size", 2, tables.size()); Assert.assertTrue("Comparing tablenames", tables.contains(testTables[2].getTableName())); Assert.assertTrue("Comparing tablenames", tables.contains(testTables[3].getTableName())); // Find tables which name contains _to_find_ or _hidden_ in the default database tables = client.getTables(DEFAULT_DATABASE, "*_to_find_*|*_hidden_*"); Assert.assertEquals("All tables size", 3, tables.size()); Assert.assertTrue("Comparing tablenames", tables.contains(testTables[2].getTableName())); Assert.assertTrue("Comparing tablenames", tables.contains(testTables[3].getTableName())); Assert.assertTrue("Comparing tablenames", tables.contains(testTables[4].getTableName())); // Find table which name contains _to_find_ in the dummy database tables = client.getTables(OTHER_DATABASE, "*_to_find_*"); Assert.assertEquals("Found functions size", 1, tables.size()); Assert.assertTrue("Comparing tablenames", tables.contains(testTables[6].getTableName())); // Look for tables but do not find any tables = client.getTables(DEFAULT_DATABASE, "*_not_such_function_*"); Assert.assertEquals("No such table size", 0, tables.size()); // Look for tables without pattern tables = client.getTables(DEFAULT_DATABASE, (String)null); Assert.assertEquals("No such functions size", 5, tables.size()); // Look for tables with empty pattern tables = client.getTables(DEFAULT_DATABASE, ""); Assert.assertEquals("No such functions size", 0, tables.size()); // No such database tables = client.getTables("no_such_database", OTHER_DATABASE); Assert.assertEquals("No such table size", 0, tables.size()); }
if (tableName == null || "".equals(tableName)) { List<String> tables = getMsc().getTables(catName, dbName, ".*"); for (String currentTableName : tables) { checkTable(catName, dbName, currentTableName, null, result);
List<String> tableNames = metastoreClient.getTables(dbName, tablePattern); Collections.sort(tableNames); db2Tabs.put(dbName, tableNames);
@Test public void tablesGetExists() throws TException { String dbName = "db_in_other_catalog"; // For this one don't specify a location to make sure it gets put in the catalog directory Database db = new DatabaseBuilder() .setName(dbName) .build(conf); db.unsetCatalogName(); client.createDatabase(db); String[] tableNames = new String[4]; for (int i = 0; i < tableNames.length; i++) { tableNames[i] = "table_in_other_catalog_" + i; Table table = new TableBuilder() .inDb(db) .setTableName(tableNames[i]) .addCol("col1_" + i, ColumnType.STRING_TYPE_NAME) .addCol("col2_" + i, ColumnType.INT_TYPE_NAME) .build(conf); table.unsetCatName(); client.createTable(table); } Set<String> tables = new HashSet<>(client.getTables(dbName, "*e_in_other_*")); Assert.assertEquals(4, tables.size()); for (String tableName : tableNames) Assert.assertTrue(tables.contains(tableName)); List<String> fetchedNames = client.getTables(dbName, "*_3"); Assert.assertEquals(1, fetchedNames.size()); Assert.assertEquals(tableNames[3], fetchedNames.get(0)); Assert.assertTrue("Table exists", client.tableExists(dbName, tableNames[0])); Assert.assertFalse("Table not exists", client.tableExists(dbName, "non_existing_table")); }
Set<String> tables = new HashSet<>(client.getTables(catName, dbName, "*e_in_other_*")); Assert.assertEquals(4, tables.size()); for (String tableName : tableNames) Assert.assertTrue(tables.contains(tableName)); List<String> fetchedNames = client.getTables(catName, dbName, "*_3"); Assert.assertEquals(1, fetchedNames.size()); Assert.assertEquals(tableNames[3], fetchedNames.get(0));
@Test public void testAlterTableExternalTable() throws Exception { Table originalTable = externalTable; String originalTableName = originalTable.getTableName(); String originalDatabase = originalTable.getDbName(); Table newTable = originalTable.deepCopy(); newTable.setTableName("new_external_table_for_test"); client.alter_table(originalDatabase, originalTableName, newTable); List<String> tableNames = client.getTables(originalDatabase, originalTableName); Assert.assertEquals("Original table should be removed", 0, tableNames.size()); Assert.assertTrue("Original table directory should be kept", metaStore.isPathExists(new Path(originalTable.getSd().getLocation()))); Table alteredTable = client.getTable(newTable.getDbName(), newTable.getTableName()); Assert.assertEquals("New location should be the same", originalTable.getSd().getLocation(), alteredTable.getSd().getLocation()); Path dataFile = new Path(alteredTable.getSd().getLocation() + "/dataFile"); Assert.assertTrue("The location should contain data", metaStore.isPathExists(dataFile)); // The extra parameters will be added on server side, so check that the required ones are // present for(String key: newTable.getParameters().keySet()) { Assert.assertEquals("parameters are present", newTable.getParameters().get(key), alteredTable.getParameters().get(key)); } // The parameters are checked manually, so do not check them newTable.setParameters(alteredTable.getParameters()); Assert.assertEquals("The table data should be the same", newTable, alteredTable); }
@Test public void testAlterTableRename() throws Exception { Table originalTable = testTables[2]; String originalTableName = originalTable.getTableName(); String originalDatabase = originalTable.getDbName(); Table newTable = originalTable.deepCopy(); // Do not change the location, so it is tested that the location will be changed even if the // location is not set to null, just remain the same newTable.setTableName("new_table"); client.alter_table(originalDatabase, originalTableName, newTable); List<String> tableNames = client.getTables(originalDatabase, originalTableName); Assert.assertEquals("Original table should be removed", 0, tableNames.size()); Assert.assertFalse("Original table directory should be removed", metaStore.isPathExists(new Path(originalTable.getSd().getLocation()))); Table alteredTable = client.getTable(newTable.getDbName(), newTable.getTableName()); Assert.assertTrue("New table directory should exist", metaStore.isPathExists(new Path(alteredTable.getSd().getLocation()))); Assert.assertEquals("New directory should be set", new Path(metaStore.getWarehouseRoot() + "/" + alteredTable.getTableName()), new Path(alteredTable.getSd().getLocation())); Path dataFile = new Path(alteredTable.getSd().getLocation() + "/dataFile"); Assert.assertTrue("New directory should contain data", metaStore.isPathExists(dataFile)); // The following data should be changed newTable.getSd().setLocation(alteredTable.getSd().getLocation()); Assert.assertEquals("The table data should be the same", newTable, alteredTable); }
@Test public void testAlterTableChangingDatabase() throws Exception { Table originalTable = testTables[2]; String originalTableName = originalTable.getTableName(); String originalDatabase = originalTable.getDbName(); Table newTable = originalTable.deepCopy(); newTable.setDbName(OTHER_DATABASE); client.alter_table(originalDatabase, originalTableName, newTable); List<String> tableNames = client.getTables(originalDatabase, originalTableName); Assert.assertEquals("Original table should be removed", 0, tableNames.size()); Assert.assertFalse("Original table directory should be removed", metaStore.isPathExists(new Path(originalTable.getSd().getLocation()))); Table alteredTable = client.getTable(newTable.getDbName(), newTable.getTableName()); Assert.assertTrue("New table directory should exist", metaStore.isPathExists(new Path(alteredTable.getSd().getLocation()))); Assert.assertEquals("New directory should be set", new Path(metaStore.getWarehouseRoot() + "/" + alteredTable.getDbName() + ".db/" + alteredTable.getTableName()), new Path(alteredTable.getSd().getLocation())); Path dataFile = new Path(alteredTable.getSd().getLocation() + "/dataFile"); Assert.assertTrue("New directory should contain data", metaStore.isPathExists(dataFile)); // The following data should be changed, other data should be the same newTable.getSd().setLocation(alteredTable.getSd().getLocation()); Assert.assertEquals("The table data should be the same", newTable, alteredTable); }
/** * Returns all existing tables from the specified database which match the given * pattern. The matching occurs as per Java regular expressions. * @param dbName * @param tablePattern * @return list of table names * @throws HiveException */ public List<String> getTablesByPattern(String dbName, String tablePattern) throws HiveException { try { return getMSC().getTables(dbName, tablePattern); } catch (Exception e) { throw new HiveException(e); } }
/** * Returns all existing tables from the specified database which match the given * pattern. The matching occurs as per Java regular expressions. * @param dbName * @param tablePattern * @return list of table names * @throws HiveException */ public List<String> getTablesByPattern(String dbName, String tablePattern) throws HiveException { try { return getMSC().getTables(dbName, tablePattern); } catch (Exception e) { throw new HiveException(e); } }
/** * Returns all existing tables from the given database which match the given * pattern. The matching occurs as per Java regular expressions * * @param database * the database name * @param tablePattern * java re pattern * @return list of table names * @throws HiveException */ public List<String> getTablesForDb(String database, String tablePattern) throws HiveException { try { return getMSC().getTables(database, tablePattern); } catch (Exception e) { throw new HiveException(e); } }
@Override public List<String> listTableNamesByPattern(String dbName, String tablePattern) throws HCatException { List<String> tableNames = null; try { tableNames = hmsClient.getTables(checkDB(dbName), tablePattern); } catch (MetaException e) { throw new HCatException("MetaException while fetching table names. " + e.getMessage(), e); } catch (UnknownDBException e) { throw new HCatException("UnknownDB " + dbName + " while fetching table names.", e); } catch (TException e) { throw new HCatException("Transport exception while fetching table names. " + e.getMessage(), e); } return tableNames; }
@Override public List<String> listTableNamesByPattern(String dbName, String tablePattern) throws HCatException { List<String> tableNames = null; try { tableNames = hmsClient.getTables(checkDB(dbName), tablePattern); } catch (MetaException e) { throw new HCatException("MetaException while fetching table names. " + e.getMessage(), e); } catch (UnknownDBException e) { throw new HCatException("UnknownDB " + dbName + " while fetching table names.", e); } catch (TException e) { throw new HCatException("Transport exception while fetching table names. " + e.getMessage(), e); } return tableNames; }
@Override public List<String> listTableNamesByPattern(String dbName, String tablePattern) throws HCatException { List<String> tableNames = null; try { tableNames = hmsClient.getTables(checkDB(dbName), tablePattern); } catch (MetaException e) { throw new HCatException("MetaException while fetching table names. " + e.getMessage(), e); } catch (UnknownDBException e) { throw new HCatException("UnknownDB " + dbName + " while fetching table names.", e); } catch (TException e) { throw new HCatException("Transport exception while fetching table names. " + e.getMessage(), e); } return tableNames; }