Search in sources :

Example 61 with Database

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();
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) Database(org.apache.hadoop.hive.metastore.api.Database) ArrayList(java.util.ArrayList) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 62 with Database

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);
}
Also used : DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) Database(org.apache.hadoop.hive.metastore.api.Database) Before(org.junit.Before)

Example 63 with Database

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);
}
Also used : DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) Database(org.apache.hadoop.hive.metastore.api.Database) Before(org.junit.Before)

Example 64 with Database

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);
}
Also used : DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) Database(org.apache.hadoop.hive.metastore.api.Database)

Example 65 with Database

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());
}
Also used : Database(org.apache.hadoop.hive.metastore.api.Database) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

Database (org.apache.hadoop.hive.metastore.api.Database)236 Test (org.junit.Test)107 Table (org.apache.hadoop.hive.metastore.api.Table)70 ArrayList (java.util.ArrayList)51 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)39 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)39 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)37 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)36 Partition (org.apache.hadoop.hive.metastore.api.Partition)35 Path (org.apache.hadoop.fs.Path)34 IOException (java.io.IOException)29 HashMap (java.util.HashMap)27 DatabaseBuilder (org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder)26 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)24 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)23 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)22 TableBuilder (org.apache.hadoop.hive.metastore.client.builder.TableBuilder)22 TException (org.apache.thrift.TException)21 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)20 FileSystem (org.apache.hadoop.fs.FileSystem)17