@Test(expected = UnknownDBException.class) public void testListTableNamesByFilterNullDatabase() throws Exception { client.listTableNamesByFilter(null, hive_metastoreConstants.HIVE_FILTER_FIELD_LAST_ACCESS + ">2000", (short)-1); }
@Test(expected = UnknownDBException.class) public void listTablesBogusCatalog() throws TException { String filter = hive_metastoreConstants.HIVE_FILTER_FIELD_PARAMS + "the_key=\"the_value\""; List<String> fetchedNames = client.listTableNamesByFilter("", DEFAULT_DATABASE_NAME, filter, (short)-1); } }
@Test(expected = InvalidOperationException.class) public void testListTableNamesByFilterNullFilter() throws Exception { client.listTableNamesByFilter(DEFAULT_DATABASE, null, (short) -1); }
@Test(expected = MetaException.class) public void testListTableNamesByFilterInvalidFilter() throws Exception { client.listTableNamesByFilter(DEFAULT_DATABASE, "invalid filter", (short)-1); }
@Test public void testListTableNamesByFilterCheckNoSuchDatabase() throws Exception { // No such database List<String> tableNames = client.listTableNamesByFilter("no_such_database", hive_metastoreConstants.HIVE_FILTER_FIELD_LAST_ACCESS + ">2000", (short)-1); Assert.assertEquals("Found tables", 0, tableNames.size()); }
public static void dropDB(IMetaStoreClient client, String databaseName) { try { for (String table : client.listTableNamesByFilter(databaseName, "", (short) -1)) { client.dropTable(databaseName, table, true, true); } client.dropDatabase(databaseName); } catch (TException e) { } }
public static void dropDB(IMetaStoreClient client, String databaseName) { try { for (String table : client.listTableNamesByFilter(databaseName, "", (short)-1)) { client.dropTable(databaseName, table, true, true); } client.dropDatabase(databaseName); } catch (TException e) { } }
public static void dropDB(IMetaStoreClient client, String databaseName) { try { for (String table : client.listTableNamesByFilter(databaseName, "", (short) -1)) { client.dropTable(databaseName, table, true, true); } client.dropDatabase(databaseName); } catch (TException e) { } }
@Test public void testListTableNamesByFilterCheckLimit() throws Exception { // Check the limit String filter = hive_metastoreConstants.HIVE_FILTER_FIELD_OWNER + " LIKE \"Owner.*\""; List<String> tableNames = client.listTableNamesByFilter(DEFAULT_DATABASE, filter, (short)1); Assert.assertEquals("Found tables", 1, tableNames.size()); Assert.assertTrue(tableNames.contains(testTables[0].getTableName()) || tableNames.contains(testTables[1].getTableName()) || tableNames.contains(testTables[2].getTableName()) || tableNames.contains(testTables[3].getTableName())); }
@Test public void testListTableNamesByFilterCheckOwner() throws Exception { String filter = hive_metastoreConstants.HIVE_FILTER_FIELD_OWNER + "=\"Owner1\""; List<String> tableNames = client.listTableNamesByFilter(DEFAULT_DATABASE, filter, (short) -1); Assert.assertEquals("Found tables", 2, tableNames.size()); Assert.assertTrue(tableNames.contains(testTables[0].getTableName())); Assert.assertTrue(tableNames.contains(testTables[1].getTableName())); }
@Test public void testListTableNamesByFilterCheckNotEquals() throws Exception { String filter = hive_metastoreConstants.HIVE_FILTER_FIELD_PARAMS + "param1<>\"value2\""; List<String> tableNames = client.listTableNamesByFilter(DEFAULT_DATABASE, filter, (short)-1); Assert.assertEquals("Found tables", 2, tableNames.size()); Assert.assertTrue(tableNames.contains(testTables[0].getTableName())); Assert.assertTrue(tableNames.contains(testTables[4].getTableName())); }
@Test public void testListTableNamesByFilterCheckLastAccess() throws Exception { String filter = hive_metastoreConstants.HIVE_FILTER_FIELD_LAST_ACCESS + "=1000"; List<String> tableNames = client.listTableNamesByFilter(DEFAULT_DATABASE, filter, (short)-1); Assert.assertEquals("Found tables", 2, tableNames.size()); Assert.assertTrue(tableNames.contains(testTables[0].getTableName())); Assert.assertTrue(tableNames.contains(testTables[2].getTableName())); }
public static void dropDB(HiveConf conf, String databaseName) throws HiveException, MetaException { IMetaStoreClient client = new HiveMetaStoreClient(conf); try { for (String table : client.listTableNamesByFilter(databaseName, "", (short) -1)) { client.dropTable(databaseName, table, true, true); } client.dropDatabase(databaseName); } catch (TException e) { client.close(); } }
@Test public void testListTableNamesByFilterCheckCombined() throws Exception { // Combined: last_access<=3000 and (Owner="Tester" or param1="param2") String filter = hive_metastoreConstants.HIVE_FILTER_FIELD_LAST_ACCESS + "<3000 and (" + hive_metastoreConstants.HIVE_FILTER_FIELD_OWNER + "=\"Tester\" or " + hive_metastoreConstants.HIVE_FILTER_FIELD_PARAMS + "param1=\"value2\")"; List<String> tableNames = client.listTableNamesByFilter(DEFAULT_DATABASE, filter, (short)-1); Assert.assertEquals("Found tables", 3, tableNames.size()); Assert.assertTrue(tableNames.contains(testTables[1].getTableName())); Assert.assertTrue(tableNames.contains(testTables[2].getTableName())); Assert.assertTrue(tableNames.contains(testTables[4].getTableName())); }
@Test public void testListTableNamesByFilterCheckParameter() throws Exception { String filter = hive_metastoreConstants.HIVE_FILTER_FIELD_PARAMS + "param1=\"value2\""; List<String> tableNames = client.listTableNamesByFilter(DEFAULT_DATABASE, filter, (short)-1); Assert.assertEquals("Found tables", 3, tableNames.size()); Assert.assertTrue(tableNames.contains(testTables[1].getTableName())); Assert.assertTrue(tableNames.contains(testTables[2].getTableName())); Assert.assertTrue(tableNames.contains(testTables[3].getTableName())); }
@Test public void testListTableNamesByFilterCheckLessOrEquals() throws Exception { String filter = hive_metastoreConstants.HIVE_FILTER_FIELD_LAST_ACCESS + "<=2000"; List<String> tableNames = client.listTableNamesByFilter(DEFAULT_DATABASE, filter, (short)-1); Assert.assertEquals("Found tables", 3, tableNames.size()); Assert.assertTrue(tableNames.contains(testTables[0].getTableName())); Assert.assertTrue(tableNames.contains(testTables[1].getTableName())); Assert.assertTrue(tableNames.contains(testTables[2].getTableName())); }
@Test public void testListTableNamesByFilterCheckLike() throws Exception { String filter = hive_metastoreConstants.HIVE_FILTER_FIELD_OWNER + " LIKE \"Owner.*\""; List<String> tableNames = client.listTableNamesByFilter(DEFAULT_DATABASE, filter, (short)-1); Assert.assertEquals("Found tables", 4, tableNames.size()); Assert.assertTrue(tableNames.contains(testTables[0].getTableName())); Assert.assertTrue(tableNames.contains(testTables[1].getTableName())); Assert.assertTrue(tableNames.contains(testTables[2].getTableName())); Assert.assertTrue(tableNames.contains(testTables[3].getTableName())); }
public Database dropAndCreate(IMetaStoreClient metaStoreClient) throws Exception { if (metaStoreClient == null) { throw new IllegalArgumentException(); } try { for (String table : metaStoreClient.listTableNamesByFilter(database.getName(), "", (short) -1)) { metaStoreClient.dropTable(database.getName(), table, true, true); } metaStoreClient.dropDatabase(database.getName()); } catch (TException e) { } metaStoreClient.createDatabase(database); return database; }
@Test public void tablesList() 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; TableBuilder builder = new TableBuilder() .inDb(db) .setTableName(tableNames[i]) .addCol("col1_" + i, ColumnType.STRING_TYPE_NAME) .addCol("col2_" + i, ColumnType.INT_TYPE_NAME); if (i == 0) builder.addTableParam("the_key", "the_value"); Table table = builder.build(conf); table.unsetCatName(); client.createTable(table); } String filter = hive_metastoreConstants.HIVE_FILTER_FIELD_PARAMS + "the_key=\"the_value\""; List<String> fetchedNames = client.listTableNamesByFilter(dbName, filter, (short)-1); Assert.assertEquals(1, fetchedNames.size()); Assert.assertEquals(tableNames[0], fetchedNames.get(0)); }
@Test public void otherCatalogs() throws TException { String catName = "list_tables_in_other_catalogs"; Catalog cat = new CatalogBuilder() .setName(catName) .setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)) .build(); client.createCatalog(cat); 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) .setCatalogName(catName) .create(client, metaStore.getConf()); String[] tableNames = new String[4]; for (int i = 0; i < tableNames.length; i++) { tableNames[i] = "table_in_other_catalog_" + i; TableBuilder builder = new TableBuilder() .inDb(db) .setTableName(tableNames[i]) .addCol("col1_" + i, ColumnType.STRING_TYPE_NAME) .addCol("col2_" + i, ColumnType.INT_TYPE_NAME); if (i == 0) builder.addTableParam("the_key", "the_value"); builder.create(client, metaStore.getConf()); } String filter = hive_metastoreConstants.HIVE_FILTER_FIELD_PARAMS + "the_key=\"the_value\""; List<String> fetchedNames = client.listTableNamesByFilter(catName, dbName, filter, (short)-1); Assert.assertEquals(1, fetchedNames.size()); Assert.assertEquals(tableNames[0], fetchedNames.get(0)); }