use of org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder in project hive by apache.
the class TestSchemaToolCatalogOps method moveDatabase.
@Test
public void moveDatabase() throws HiveMetaException, TException {
String toCatName = "moveDbCat";
String dbName = "moveDbDb";
String tableName = "moveDbTable";
String funcName = "movedbfunc";
String partVal = "moveDbKey";
new CatalogBuilder().setName(toCatName).setLocation("file:///tmp").create(client);
Database db = new DatabaseBuilder().setCatalogName(DEFAULT_CATALOG_NAME).setName(dbName).create(client, conf);
new FunctionBuilder().inDb(db).setName(funcName).setClass("org.apache.hive.myudf").create(client, conf);
Table table = new TableBuilder().inDb(db).setTableName(tableName).addCol("a", "int").addPartCol("p", "string").create(client, conf);
new PartitionBuilder().inTable(table).addValue(partVal).addToTable(client, conf);
String argsMoveDB = String.format("-moveDatabase %s -fromCatalog %s -toCatalog %s", dbName, DEFAULT_CATALOG_NAME, toCatName);
execute(new SchemaToolTaskMoveDatabase(), argsMoveDB);
Database fetchedDb = client.getDatabase(toCatName, dbName);
Assert.assertNotNull(fetchedDb);
Assert.assertEquals(toCatName.toLowerCase(), fetchedDb.getCatalogName());
Function fetchedFunction = client.getFunction(toCatName, dbName, funcName);
Assert.assertNotNull(fetchedFunction);
Assert.assertEquals(toCatName.toLowerCase(), fetchedFunction.getCatName());
Assert.assertEquals(dbName.toLowerCase(), fetchedFunction.getDbName());
Table fetchedTable = client.getTable(toCatName, dbName, tableName);
Assert.assertNotNull(fetchedTable);
Assert.assertEquals(toCatName.toLowerCase(), fetchedTable.getCatName());
Assert.assertEquals(dbName.toLowerCase(), fetchedTable.getDbName());
Partition fetchedPart = client.getPartition(toCatName, dbName, tableName, Collections.singletonList(partVal));
Assert.assertNotNull(fetchedPart);
Assert.assertEquals(toCatName.toLowerCase(), fetchedPart.getCatName());
Assert.assertEquals(dbName.toLowerCase(), fetchedPart.getDbName());
Assert.assertEquals(tableName.toLowerCase(), fetchedPart.getTableName());
}
use of org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder in project hive by apache.
the class TestSchemaToolCatalogOps method moveDatabaseWithExistingDbOfSameNameAlreadyInTargetCatalog.
@Test
public void moveDatabaseWithExistingDbOfSameNameAlreadyInTargetCatalog() throws TException, HiveMetaException {
String catName = "clobberCatalog";
new CatalogBuilder().setName(catName).setLocation("file:///tmp").create(client);
try {
String argsMoveDB = String.format("-moveDatabase %s -fromCatalog %s -toCatalog %s", DEFAULT_DATABASE_NAME, catName, DEFAULT_CATALOG_NAME);
execute(new SchemaToolTaskMoveDatabase(), argsMoveDB);
Assert.fail("Attempt to move default database should have failed.");
} catch (HiveMetaException e) {
// good
}
// Make sure nothing really moved
Set<String> dbNames = new HashSet<>(client.getAllDatabases(DEFAULT_CATALOG_NAME));
Assert.assertTrue(dbNames.contains(DEFAULT_DATABASE_NAME));
}
use of org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder in project hive by apache.
the class TestSchemaToolCatalogOps method moveNonExistentDatabase.
@Test(expected = HiveMetaException.class)
public void moveNonExistentDatabase() throws TException, HiveMetaException {
String catName = "moveNonExistentDb";
new CatalogBuilder().setName(catName).setLocation("file:///tmp").create(client);
String argsMoveDB = String.format("-moveDatabase nosuch -fromCatalog %s -toCatalog %s", catName, DEFAULT_CATALOG_NAME);
execute(new SchemaToolTaskMoveDatabase(), argsMoveDB);
}
use of org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder in project hive by apache.
the class TestTransactionalValidationListener method createCatalogs.
private void createCatalogs() throws Exception {
String[] catNames = { "spark", "myapp" };
String[] location = { MetaStoreTestUtils.getTestWarehouseDir("spark"), MetaStoreTestUtils.getTestWarehouseDir("myapp") };
for (int i = 0; i < catNames.length; i++) {
Catalog cat = new CatalogBuilder().setName(catNames[i]).setLocation(location[i]).build();
client.createCatalog(cat);
File dir = new File(cat.getLocationUri());
Assert.assertTrue(dir.exists() && dir.isDirectory());
}
}
use of org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder in project hive by apache.
the class TestTablesCreateDropAlterTruncate method moveTablesBetweenCatalogsOnAlter.
@Test(expected = InvalidOperationException.class)
public void moveTablesBetweenCatalogsOnAlter() throws TException {
String catName = "move_table_between_catalogs_on_alter";
Catalog cat = new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).build();
client.createCatalog(cat);
String dbName = "a_db";
// 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 tableName = "non_movable_table";
Table before = new TableBuilder().inDb(db).setTableName(tableName).addCol("col1", ColumnType.STRING_TYPE_NAME).addCol("col2", ColumnType.INT_TYPE_NAME).create(client, metaStore.getConf());
Table after = before.deepCopy();
after.setCatName(DEFAULT_CATALOG_NAME);
client.alter_table(catName, dbName, tableName, after);
}
Aggregations