db.unsetCatalogName(); client.createDatabase(db);
@Test public void getTableMeta() throws TException { String dbName = "db9"; // 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 = {"table_in_other_catalog_1", "table_in_other_catalog_2", "random_name"}; List<TableMeta> expected = new ArrayList<>(tableNames.length); for (int i = 0; i < tableNames.length; i++) { Table table = new TableBuilder() .inDb(db) .setTableName(tableNames[i]) .addCol("id", "int") .addCol("name", "string") .build(conf); table.unsetCatName(); client.createTable(table); TableMeta tableMeta = new TableMeta(dbName, tableNames[i], TableType.MANAGED_TABLE.name()); tableMeta.setCatName(expectedCatalog()); expected.add(tableMeta); } List<String> types = Collections.singletonList(TableType.MANAGED_TABLE.name()); List<TableMeta> actual = client.getTableMeta(dbName, "*", types); Assert.assertEquals(new TreeSet<>(expected), new TreeSet<>(actual)); actual = client.getTableMeta("*", "table_*", types); Assert.assertEquals(expected.subList(0, 2), actual.subList(0, 2)); }
db.unsetCatalogName(); Table tbl = new TableBuilder().setDbName(dbName).setTableName(tblName) .addCol("id", "int").addCol("name", "string")
.setName(dbName) .build(conf); db.unsetCatalogName(); client.createDatabase(db);
.setName(dbName) .build(conf); db.unsetCatalogName(); client.createDatabase(db);
@Test public void testTxNWithKeyWrongPrefix() throws Exception { String dbName = "mydbKeyValueWrongPrefix"; String tblName = "mytable"; List<Long> tids = client.openTxns("me", 1).getTxn_ids(); Assert.assertEquals(1L, (long) tids.get(0)); try { Database db = new DatabaseBuilder().setName(dbName).build(conf); db.unsetCatalogName(); client.createDatabase(db); Table tbl = new TableBuilder().setDbName(dbName).setTableName(tblName) .addCol("id", "int").addCol("name", "string") .setType(TableType.MANAGED_TABLE.name()).build(conf); client.createTable(tbl); tbl = client.getTable(dbName, tblName); client.commitTxnWithKeyValue(1, tbl.getId(), "mykey", "myvalue"); Assert.fail("Should have raised exception"); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().contains("key=mykey")); Assert.assertTrue(e.getMessage().contains("value=myvalue")); Assert.assertTrue(e.getMessage().contains("key should start with")); } finally { client.dropTable(dbName, tblName); client.dropDatabase(dbName); } ValidTxnList validTxns = client.getValidTxns(1); Assert.assertTrue(validTxns.isTxnValid(1)); }
@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")); }
.setName(dbName) .build(conf); db.unsetCatalogName(); client.createDatabase(db);
@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)); }
unsetCatalogName(); } else { setCatalogName((String)value);
.setName(dbName) .build(conf); db.unsetCatalogName(); client.createDatabase(db);
.setName(dbName) .build(conf); db.unsetCatalogName(); client.createDatabase(db);
.setName(dbName) .build(conf); db.unsetCatalogName(); client.createDatabase(db);
.setName(dbName) .build(conf); db.unsetCatalogName(); client.createDatabase(db);
db.unsetCatalogName(); client.createDatabase(db);