use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.
the class TestHiveMetaStore method testSimpleTypeApi.
public void testSimpleTypeApi() throws Exception {
try {
client.dropType(serdeConstants.INT_TYPE_NAME);
Type typ1 = new Type();
typ1.setName(serdeConstants.INT_TYPE_NAME);
boolean ret = client.createType(typ1);
assertTrue("Unable to create type", ret);
Type typ1_2 = client.getType(serdeConstants.INT_TYPE_NAME);
assertNotNull(typ1_2);
assertEquals(typ1.getName(), typ1_2.getName());
ret = client.dropType(serdeConstants.INT_TYPE_NAME);
assertTrue("unable to drop type integer", ret);
boolean exceptionThrown = false;
try {
client.getType(serdeConstants.INT_TYPE_NAME);
} catch (NoSuchObjectException e) {
exceptionThrown = true;
}
assertTrue("Expected NoSuchObjectException", exceptionThrown);
} catch (Exception e) {
System.err.println(StringUtils.stringifyException(e));
System.err.println("testSimpleTypeApi() failed.");
throw e;
}
}
use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.
the class TestMarkPartition method testMarkingPartitionSet.
public void testMarkingPartitionSet() throws CommandNeedRetryException, MetaException, TException, NoSuchObjectException, UnknownDBException, UnknownTableException, InvalidPartitionException, UnknownPartitionException, InterruptedException {
HiveMetaStoreClient msc = new HiveMetaStoreClient(hiveConf);
driver = new Driver(hiveConf);
driver.run("drop database if exists hive2215 cascade");
driver.run("create database hive2215");
driver.run("use hive2215");
driver.run("drop table if exists tmptbl");
driver.run("create table tmptbl (a string) partitioned by (b string)");
driver.run("alter table tmptbl add partition (b='2011')");
Map<String, String> kvs = new HashMap<String, String>();
kvs.put("b", "'2011'");
msc.markPartitionForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
assert msc.isPartitionMarkedForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
Thread.sleep(10000);
assert !msc.isPartitionMarkedForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
kvs.put("b", "'2012'");
assert !msc.isPartitionMarkedForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
try {
msc.markPartitionForEvent("hive2215", "tmptbl2", kvs, PartitionEventType.LOAD_DONE);
assert false;
} catch (Exception e) {
assert e instanceof UnknownTableException;
}
try {
msc.isPartitionMarkedForEvent("hive2215", "tmptbl2", kvs, PartitionEventType.LOAD_DONE);
assert false;
} catch (Exception e) {
assert e instanceof UnknownTableException;
}
kvs.put("a", "'2012'");
try {
msc.isPartitionMarkedForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
assert false;
} catch (Exception e) {
assert e instanceof InvalidPartitionException;
}
}
use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.
the class TestMetaStoreEndFunctionListener method testEndFunctionListener.
public void testEndFunctionListener() throws Exception {
/* Objective here is to ensure that when exceptions are thrown in HiveMetaStore in API methods
* they bubble up and are stored in the MetaStoreEndFunctionContext objects
*/
String dbName = "hive3524";
String tblName = "tmptbl";
int listSize = 0;
driver.run("create database " + dbName);
try {
msc.getDatabase("UnknownDB");
} catch (Exception e) {
}
listSize = DummyEndFunctionListener.funcNameList.size();
String func_name = DummyEndFunctionListener.funcNameList.get(listSize - 1);
MetaStoreEndFunctionContext context = DummyEndFunctionListener.contextList.get(listSize - 1);
assertEquals(func_name, "get_database");
assertFalse(context.isSuccess());
Exception e = context.getException();
assertTrue((e != null));
assertTrue((e instanceof NoSuchObjectException));
assertEquals(context.getInputTableName(), null);
driver.run("use " + dbName);
driver.run(String.format("create table %s (a string) partitioned by (b string)", tblName));
String tableName = "Unknown";
try {
msc.getTable(dbName, tableName);
} catch (Exception e1) {
}
listSize = DummyEndFunctionListener.funcNameList.size();
func_name = DummyEndFunctionListener.funcNameList.get(listSize - 1);
context = DummyEndFunctionListener.contextList.get(listSize - 1);
assertEquals(func_name, "get_table");
assertFalse(context.isSuccess());
e = context.getException();
assertTrue((e != null));
assertTrue((e instanceof NoSuchObjectException));
assertEquals(context.getInputTableName(), tableName);
try {
msc.getPartition("hive3524", tblName, "b=2012");
} catch (Exception e2) {
}
listSize = DummyEndFunctionListener.funcNameList.size();
func_name = DummyEndFunctionListener.funcNameList.get(listSize - 1);
context = DummyEndFunctionListener.contextList.get(listSize - 1);
assertEquals(func_name, "get_partition_by_name");
assertFalse(context.isSuccess());
e = context.getException();
assertTrue((e != null));
assertTrue((e instanceof NoSuchObjectException));
assertEquals(context.getInputTableName(), tblName);
try {
driver.run("drop table Unknown");
} catch (Exception e4) {
}
listSize = DummyEndFunctionListener.funcNameList.size();
func_name = DummyEndFunctionListener.funcNameList.get(listSize - 1);
context = DummyEndFunctionListener.contextList.get(listSize - 1);
assertEquals(func_name, "get_table");
assertFalse(context.isSuccess());
e = context.getException();
assertTrue((e != null));
assertTrue((e instanceof NoSuchObjectException));
assertEquals(context.getInputTableName(), "Unknown");
}
use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.
the class TestHiveMetaStore method testDatabaseLocation.
public void testDatabaseLocation() throws Throwable {
try {
// clear up any existing databases
silentDropDatabase(TEST_DB1_NAME);
Database db = new Database();
db.setName(TEST_DB1_NAME);
String dbLocation = HiveConf.getVar(hiveConf, HiveConf.ConfVars.METASTOREWAREHOUSE) + "/_testDB_create_";
db.setLocationUri(dbLocation);
client.createDatabase(db);
db = client.getDatabase(TEST_DB1_NAME);
assertEquals("name of returned db is different from that of inserted db", TEST_DB1_NAME, db.getName());
assertEquals("location of the returned db is different from that of inserted db", warehouse.getDnsPath(new Path(dbLocation)).toString(), db.getLocationUri());
client.dropDatabase(TEST_DB1_NAME);
silentDropDatabase(TEST_DB1_NAME);
boolean objectNotExist = false;
try {
client.getDatabase(TEST_DB1_NAME);
} catch (NoSuchObjectException e) {
objectNotExist = true;
}
assertTrue("Database " + TEST_DB1_NAME + " exists ", objectNotExist);
db = new Database();
db.setName(TEST_DB1_NAME);
dbLocation = HiveConf.getVar(hiveConf, HiveConf.ConfVars.METASTOREWAREHOUSE) + "/_testDB_file_";
FileSystem fs = FileSystem.get(new Path(dbLocation).toUri(), hiveConf);
fs.createNewFile(new Path(dbLocation));
fs.deleteOnExit(new Path(dbLocation));
db.setLocationUri(dbLocation);
boolean createFailed = false;
try {
client.createDatabase(db);
} catch (MetaException cantCreateDB) {
System.err.println(cantCreateDB.getMessage());
createFailed = true;
}
assertTrue("Database creation succeeded even location exists and is a file", createFailed);
objectNotExist = false;
try {
client.getDatabase(TEST_DB1_NAME);
} catch (NoSuchObjectException e) {
objectNotExist = true;
}
assertTrue("Database " + TEST_DB1_NAME + " exists when location is specified and is a file", objectNotExist);
} catch (Throwable e) {
System.err.println(StringUtils.stringifyException(e));
System.err.println("testDatabaseLocation() failed.");
throw e;
}
}
use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project presto by prestodb.
the class ThriftHiveMetastore method getAllTables.
@Override
public Optional<List<String>> getAllTables(String databaseName) {
Callable<List<String>> getAllTables = stats.getGetAllTables().wrap(() -> {
try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) {
return client.getAllTables(databaseName);
}
});
Callable<Void> getDatabase = stats.getGetDatabase().wrap(() -> {
try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) {
client.getDatabase(databaseName);
return null;
}
});
try {
return retry().stopOn(NoSuchObjectException.class).stopOnIllegalExceptions().run("getAllTables", () -> {
List<String> tables = getAllTables.call();
if (tables.isEmpty()) {
// Check to see if the database exists
getDatabase.call();
}
return Optional.of(tables);
});
} catch (NoSuchObjectException e) {
return Optional.empty();
} catch (TException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
Aggregations