use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.
the class TestObjectStore method dropAllStoreObjects.
private static void dropAllStoreObjects(RawStore store) throws MetaException, InvalidObjectException, InvalidInputException {
try {
Deadline.registerIfNot(100000);
List<Function> functions = store.getAllFunctions();
for (Function func : functions) {
store.dropFunction(func.getDbName(), func.getFunctionName());
}
List<String> dbs = store.getAllDatabases();
for (String db : dbs) {
List<String> tbls = store.getAllTables(db);
for (String tbl : tbls) {
Deadline.startTimer("getPartition");
List<Partition> parts = store.getPartitions(db, tbl, 100);
for (Partition part : parts) {
store.dropPartition(db, tbl, part.getValues());
}
// Find any constraints and drop them
Set<String> constraints = new HashSet<>();
List<SQLPrimaryKey> pk = store.getPrimaryKeys(db, tbl);
if (pk != null) {
for (SQLPrimaryKey pkcol : pk) {
constraints.add(pkcol.getPk_name());
}
}
List<SQLForeignKey> fks = store.getForeignKeys(null, null, db, tbl);
if (fks != null) {
for (SQLForeignKey fkcol : fks) {
constraints.add(fkcol.getFk_name());
}
}
for (String constraint : constraints) {
store.dropConstraint(db, tbl, constraint);
}
store.dropTable(db, tbl);
}
store.dropDatabase(db);
}
List<String> roles = store.listRoleNames();
for (String role : roles) {
store.removeRole(role);
}
} catch (NoSuchObjectException e) {
}
}
use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.
the class TestOldSchema method dropAllStoreObjects.
private static void dropAllStoreObjects(RawStore store) throws MetaException, InvalidObjectException, InvalidInputException {
try {
Deadline.registerIfNot(100000);
Deadline.startTimer("getPartition");
List<String> dbs = store.getAllDatabases();
for (int i = 0; i < dbs.size(); i++) {
String db = dbs.get(i);
List<String> tbls = store.getAllTables(db);
for (String tbl : tbls) {
List<Partition> parts = store.getPartitions(db, tbl, 100);
for (Partition part : parts) {
store.dropPartition(db, tbl, part.getValues());
}
store.dropTable(db, tbl);
}
store.dropDatabase(db);
}
} catch (NoSuchObjectException e) {
}
}
use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.
the class TestTablesCreateDropAlterTruncate method testDropTableCaseInsensitive.
@Test
public void testDropTableCaseInsensitive() throws Exception {
Table table = testTables[0];
// Test in upper case
client.dropTable(table.getDbName().toUpperCase(), table.getTableName().toUpperCase());
try {
client.getTable(table.getDbName(), table.getTableName());
Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {
// Expected exception
}
// Test in mixed case
client.createTable(table);
client.dropTable("DeFaUlt", "TeST_tAbLE");
try {
client.getTable(table.getDbName(), table.getTableName());
Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {
// Expected exception
}
}
use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.
the class TestDatabases method testCreateGetDeleteDatabase.
/**
* This test creates and queries a database and then drops it. Good for testing the happy path.
* @throws Exception
*/
@Test
public void testCreateGetDeleteDatabase() throws Exception {
Database database = getDatabaseWithAllParametersSet();
client.createDatabase(database);
Database createdDatabase = client.getDatabase(database.getName());
// The createTime will be set on the server side, so the comparison should skip it
Assert.assertEquals("Comparing databases", database, createdDatabase);
Assert.assertTrue("The directory should be created", metaStore.isPathExists(new Path(database.getLocationUri())));
client.dropDatabase(database.getName());
Assert.assertFalse("The directory should be removed", metaStore.isPathExists(new Path(database.getLocationUri())));
try {
client.getDatabase(database.getName());
Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {
// Expected exception
}
}
use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.
the class TestExchangePartitions method checkRemainingPartitions.
private void checkRemainingPartitions(Table sourceTable, Table destTable, List<Partition> partitions) throws Exception {
for (Partition partition : partitions) {
// Check if the partitions exist in the sourceTable
Partition resultPart = client.getPartition(sourceTable.getDbName(), sourceTable.getTableName(), partition.getValues());
Assert.assertNotNull(resultPart);
Assert.assertEquals(partition, resultPart);
Assert.assertTrue(metaStore.isPathExists(new Path(partition.getSd().getLocation())));
// Check if the partitions don't exist in the destTable
try {
client.getPartition(destTable.getDbName(), destTable.getTableName(), partition.getValues());
Assert.fail("The partition '" + partition.getValues().toString() + "'should not exists, therefore NoSuchObjectException should have been thrown.");
} catch (NoSuchObjectException e) {
// Expected exception
}
String partName = Warehouse.makePartName(sourceTable.getPartitionKeys(), partition.getValues());
Assert.assertFalse(metaStore.isPathExists(new Path(destTable.getSd().getLocation() + "/" + partName)));
}
}
Aggregations