use of org.apache.hadoop.hive.metastore.api.Database in project hive by apache.
the class TestCachedStore method testTableOps.
@Test
public void testTableOps() throws Exception {
// Add a db via ObjectStore
String dbName = "testTableOps";
String dbOwner = "user1";
Database db = createTestDb(dbName, dbOwner);
objectStore.createDatabase(db);
db = objectStore.getDatabase(dbName);
// Add a table via ObjectStore
String tblName = "tbl";
String tblOwner = "user1";
FieldSchema col1 = new FieldSchema("col1", "int", "integer column");
FieldSchema col2 = new FieldSchema("col2", "string", "string column");
List<FieldSchema> cols = new ArrayList<FieldSchema>();
cols.add(col1);
cols.add(col2);
List<FieldSchema> ptnCols = new ArrayList<FieldSchema>();
Table tbl = createTestTbl(dbName, tblName, tblOwner, cols, ptnCols);
objectStore.createTable(tbl);
tbl = objectStore.getTable(dbName, tblName);
// Prewarm CachedStore
CachedStore.setCachePrewarmedState(false);
CachedStore.prewarm(objectStore);
// Read database, table via CachedStore
Database dbRead = cachedStore.getDatabase(dbName);
Assert.assertEquals(db, dbRead);
Table tblRead = cachedStore.getTable(dbName, tblName);
Assert.assertEquals(tbl, tblRead);
// Add a new table via CachedStore
String tblName1 = "tbl1";
Table tbl1 = new Table(tbl);
tbl1.setTableName(tblName1);
cachedStore.createTable(tbl1);
tbl1 = cachedStore.getTable(dbName, tblName1);
// Read via object store
tblRead = objectStore.getTable(dbName, tblName1);
Assert.assertEquals(tbl1, tblRead);
// Add a new table via ObjectStore
String tblName2 = "tbl2";
Table tbl2 = new Table(tbl);
tbl2.setTableName(tblName2);
objectStore.createTable(tbl2);
tbl2 = objectStore.getTable(dbName, tblName2);
// Alter table "tbl" via ObjectStore
tblOwner = "user2";
tbl.setOwner(tblOwner);
objectStore.alterTable(dbName, tblName, tbl);
tbl = objectStore.getTable(dbName, tblName);
// Drop table "tbl1" via ObjectStore
objectStore.dropTable(dbName, tblName1);
// We update twice to accurately detect if cache is dirty or not
updateCache(cachedStore);
updateCache(cachedStore);
// Read "tbl2" via CachedStore
tblRead = cachedStore.getTable(dbName, tblName2);
Assert.assertEquals(tbl2, tblRead);
// Read the altered "tbl" via CachedStore
tblRead = cachedStore.getTable(dbName, tblName);
Assert.assertEquals(tbl, tblRead);
// Try to read the dropped "tbl1" via CachedStore (should throw exception)
tblRead = cachedStore.getTable(dbName, tblName1);
Assert.assertNull(tblRead);
// Should return "tbl" and "tbl2"
List<String> tblNames = cachedStore.getTables(dbName, "*");
Assert.assertTrue(tblNames.contains(tblName));
Assert.assertTrue(!tblNames.contains(tblName1));
Assert.assertTrue(tblNames.contains(tblName2));
// Clean up
objectStore.dropTable(dbName, tblName);
objectStore.dropTable(dbName, tblName2);
objectStore.dropDatabase(dbName);
sharedCache.getDatabaseCache().clear();
sharedCache.getTableCache().clear();
sharedCache.getSdCache().clear();
}
use of org.apache.hadoop.hive.metastore.api.Database in project hive by apache.
the class TestAddPartitions method setUp.
@Before
public void setUp() throws Exception {
// Get new client
client = metaStore.getClient();
// Clean up the database
client.dropDatabase(DB_NAME, true, true, true);
metaStore.cleanWarehouseDirs();
Database db = new DatabaseBuilder().setName(DB_NAME).build();
client.createDatabase(db);
}
use of org.apache.hadoop.hive.metastore.api.Database in project hive by apache.
the class TestAddPartitionsFromPartSpec method setUp.
@Before
public void setUp() throws Exception {
// Get new client
client = metaStore.getClient();
// Clean up the database
client.dropDatabase(DB_NAME, true, true, true);
metaStore.cleanWarehouseDirs();
Database db = new DatabaseBuilder().setName(DB_NAME).build();
client.createDatabase(db);
}
use of org.apache.hadoop.hive.metastore.api.Database in project hive by apache.
the class TestAlterPartitions method createDB.
private void createDB(String dbName) throws TException {
Database db = new DatabaseBuilder().setName(dbName).build();
client.createDatabase(db);
}
use of org.apache.hadoop.hive.metastore.api.Database in project hive by apache.
the class TestDatabases method testAlterDatabaseNotNullableFields.
@Test
public void testAlterDatabaseNotNullableFields() throws Exception {
Database database = getDatabaseWithAllParametersSet();
client.createDatabase(database);
Database originalDatabase = client.getDatabase(database.getName());
Database newDatabase = new Database();
newDatabase.setName("new_name");
client.alterDatabase(originalDatabase.getName(), newDatabase);
// The name should not be changed, so reload the db with the original name
Database alteredDatabase = client.getDatabase(originalDatabase.getName());
Assert.assertEquals("Database name should not change", originalDatabase.getName(), alteredDatabase.getName());
Assert.assertEquals("Database description should not change", originalDatabase.getDescription(), alteredDatabase.getDescription());
Assert.assertEquals("Database location should not change", originalDatabase.getLocationUri(), alteredDatabase.getLocationUri());
Assert.assertEquals("Database parameters should be empty", new HashMap<String, String>(), alteredDatabase.getParameters());
Assert.assertNull("Database owner should be empty", alteredDatabase.getOwnerName());
Assert.assertEquals("Database owner type should not change", originalDatabase.getOwnerType(), alteredDatabase.getOwnerType());
Assert.assertNull("Database privileges should be empty", alteredDatabase.getPrivileges());
}
Aggregations