use of org.apache.hadoop.hive.metastore.api.Database in project hive by apache.
the class TestDatabases method testDropDatabaseWithTable.
@Test(expected = InvalidOperationException.class)
public void testDropDatabaseWithTable() throws Exception {
Database database = testDatabases[0];
Table testTable = new TableBuilder().setDbName(database.getName()).setTableName("test_table").addCol("test_col", "int").build();
client.createTable(testTable);
client.dropDatabase(database.getName(), true, true, false);
}
use of org.apache.hadoop.hive.metastore.api.Database in project hive by apache.
the class TestDatabases method testDropDatabaseCaseInsensitive.
@Test
public void testDropDatabaseCaseInsensitive() throws Exception {
Database database = testDatabases[0];
// Test in upper case
client.dropDatabase(database.getName().toUpperCase());
List<String> allDatabases = client.getAllDatabases();
Assert.assertEquals("All databases size", 4, allDatabases.size());
// Test in mixed case
client.createDatabase(database);
client.dropDatabase("TesT_DatABaSe_1");
allDatabases = client.getAllDatabases();
Assert.assertEquals("All databases size", 4, allDatabases.size());
}
use of org.apache.hadoop.hive.metastore.api.Database 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.Database in project hive by apache.
the class TestDatabases method testCreateDatabaseInvalidName.
@Test(expected = InvalidObjectException.class)
public void testCreateDatabaseInvalidName() throws Exception {
Database database = testDatabases[0];
// Invalid character in new database name
database.setName("test_database_1;");
client.createDatabase(database);
}
use of org.apache.hadoop.hive.metastore.api.Database in project hive by apache.
the class TestDatabases method testDropDatabaseWithFunctionCascade.
@Test
public void testDropDatabaseWithFunctionCascade() throws Exception {
Database database = testDatabases[0];
Function testFunction = new FunctionBuilder().setDbName(database.getName()).setName("test_function").setClass("org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper").build();
client.createFunction(testFunction);
client.dropDatabase(database.getName(), true, true, true);
Assert.assertFalse("The directory should be removed", metaStore.isPathExists(new Path(database.getLocationUri())));
}
Aggregations