Search in sources :

Example 11 with ObjectStore

use of org.apache.hadoop.hive.metastore.ObjectStore in project hive by apache.

the class TestHBaseImport method importTablesWithConstraints.

@Test
public void importTablesWithConstraints() throws Exception {
    RawStore rdbms;
    rdbms = new ObjectStore();
    rdbms.setConf(conf);
    String[] dbNames = new String[] { "onetabwcdb1", "onetabwcdb2" };
    int now = (int) System.currentTimeMillis() / 1000;
    setupObjectStore(rdbms, dbNames, now, true);
    // Create the database so I can put the table in it.
    store.createDatabase(new Database(dbNames[0], "no description", "file:/tmp", emptyParameters));
    HBaseImport importer = new HBaseImport("-d", dbNames[0]);
    importer.setConnections(rdbms, store);
    importer.run();
    Database db = store.getDatabase(dbNames[0]);
    Assert.assertNotNull(db);
    Table table = store.getTable(db.getName(), tableNames[1]);
    Assert.assertNotNull(table);
    List<SQLPrimaryKey> pk = store.getPrimaryKeys(dbNames[0], tableNames[1]);
    Assert.assertNotNull(pk);
    Assert.assertEquals(1, pk.size());
    Assert.assertEquals(dbNames[0], pk.get(0).getTable_db());
    Assert.assertEquals(tableNames[1], pk.get(0).getTable_name());
    Assert.assertEquals(0, pk.get(0).getKey_seq());
    Assert.assertEquals("col1", pk.get(0).getColumn_name());
    Assert.assertEquals(dbNames[0] + "_" + pkNames[1], pk.get(0).getPk_name());
    Assert.assertTrue(pk.get(0).isEnable_cstr());
    Assert.assertFalse(pk.get(0).isValidate_cstr());
    Assert.assertTrue(pk.get(0).isRely_cstr());
    List<SQLForeignKey> fk = store.getForeignKeys(dbNames[0], tableNames[0], dbNames[0], tableNames[1]);
    Assert.assertNotNull(fk);
    Assert.assertEquals(1, fk.size());
    Assert.assertEquals(dbNames[0], fk.get(0).getPktable_db());
    Assert.assertEquals(tableNames[0], fk.get(0).getPktable_name());
    Assert.assertEquals("col1", fk.get(0).getPkcolumn_name());
    Assert.assertEquals(dbNames[0], fk.get(0).getFktable_db());
    Assert.assertEquals(tableNames[1], fk.get(0).getFktable_name());
    Assert.assertEquals("col1", fk.get(0).getFkcolumn_name());
    Assert.assertEquals(0, fk.get(0).getKey_seq());
    Assert.assertEquals(1, fk.get(0).getUpdate_rule());
    Assert.assertEquals(2, fk.get(0).getDelete_rule());
    Assert.assertEquals(dbNames[0] + "_" + fkNames[1], fk.get(0).getFk_name());
    Assert.assertTrue(pk.get(0).isEnable_cstr());
    Assert.assertFalse(pk.get(0).isValidate_cstr());
    Assert.assertTrue(pk.get(0).isRely_cstr());
}
Also used : TestObjectStore(org.apache.hadoop.hive.metastore.TestObjectStore) ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore) SQLPrimaryKey(org.apache.hadoop.hive.metastore.api.SQLPrimaryKey) Table(org.apache.hadoop.hive.metastore.api.Table) SQLForeignKey(org.apache.hadoop.hive.metastore.api.SQLForeignKey) Database(org.apache.hadoop.hive.metastore.api.Database) RawStore(org.apache.hadoop.hive.metastore.RawStore) Test(org.junit.Test)

Example 12 with ObjectStore

use of org.apache.hadoop.hive.metastore.ObjectStore in project hive by apache.

the class TestHBaseImport method importOneRole.

// TODO test for bogus function name
// TODO test for bogus table name
// TODO test for non-existent items
@Test
public void importOneRole() throws Exception {
    RawStore rdbms;
    rdbms = new ObjectStore();
    rdbms.setConf(conf);
    String[] dbNames = new String[] { "oneroledb1", "oneroledb2" };
    String[] roles = new String[] { "onerolerole1", "onerolerole2" };
    String[] tokenIds = new String[] { "oneroletokenid1", "oneroletokenid2" };
    String[] tokens = new String[] { "oneroletoken1", "oneroletoken2" };
    String[] masterKeys = new String[] { "onerolemk1", "onerolemk2" };
    int now = (int) System.currentTimeMillis() / 1000;
    setupObjectStore(rdbms, roles, dbNames, tokenIds, tokens, masterKeys, now);
    int baseNumRoles = store.listRoleNames() == null ? 0 : store.listRoleNames().size();
    int baseNumDbs = store.getAllDatabases() == null ? 0 : store.getAllDatabases().size();
    int baseNumToks = store.getAllTokenIdentifiers() == null ? 0 : store.getAllTokenIdentifiers().size();
    int baseNumKeys = store.getMasterKeys() == null ? 0 : store.getMasterKeys().length;
    HBaseImport importer = new HBaseImport("-r", roles[0]);
    importer.setConnections(rdbms, store);
    importer.run();
    Role role = store.getRole(roles[0]);
    Assert.assertNotNull(role);
    Assert.assertEquals(roles[0], role.getRoleName());
    // Make sure there aren't any extra roles
    Assert.assertEquals(baseNumRoles + 1, store.listRoleNames().size());
    Assert.assertEquals(baseNumDbs, store.getAllDatabases().size());
    Assert.assertEquals(baseNumToks, store.getAllTokenIdentifiers().size());
    String[] hbaseKeys = store.getMasterKeys();
    Assert.assertEquals(baseNumKeys, hbaseKeys.length);
    // Have to do this last as it will throw an exception
    thrown.expect(NoSuchObjectException.class);
    store.getRole(roles[1]);
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) TestObjectStore(org.apache.hadoop.hive.metastore.TestObjectStore) ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore) RawStore(org.apache.hadoop.hive.metastore.RawStore) Test(org.junit.Test)

Example 13 with ObjectStore

use of org.apache.hadoop.hive.metastore.ObjectStore in project hive by apache.

the class HiveMetaTool method initObjectStore.

private void initObjectStore(HiveConf hiveConf) {
    if (!isObjStoreInitialized) {
        objStore = new ObjectStore();
        objStore.setConf(hiveConf);
        isObjStoreInitialized = true;
    }
}
Also used : ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore)

Example 14 with ObjectStore

use of org.apache.hadoop.hive.metastore.ObjectStore in project hive by apache.

the class TestMetastoreVersion method setMetaStoreVersion.

// Store the given version and comment in the metastore
public void setMetaStoreVersion(String newVersion, String comment) throws HiveMetaException {
    ObjectStore objStore = new ObjectStore();
    objStore.setConf(hiveConf);
    try {
        objStore.setMetaStoreSchemaVersion(newVersion, comment);
    } catch (MetaException e) {
        throw new HiveMetaException("Failed to set version", e);
    }
}
Also used : ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 15 with ObjectStore

use of org.apache.hadoop.hive.metastore.ObjectStore in project hive by apache.

the class TestMetastoreVersion method getMetaStoreVersion.

// Load the version stored in the metastore db
public String getMetaStoreVersion() throws HiveMetaException {
    ObjectStore objStore = new ObjectStore();
    objStore.setConf(hiveConf);
    try {
        return objStore.getMetaStoreSchemaVersion();
    } catch (MetaException e) {
        throw new HiveMetaException("Failed to get version", e);
    }
}
Also used : ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

ObjectStore (org.apache.hadoop.hive.metastore.ObjectStore)15 RawStore (org.apache.hadoop.hive.metastore.RawStore)12 TestObjectStore (org.apache.hadoop.hive.metastore.TestObjectStore)12 Test (org.junit.Test)10 Database (org.apache.hadoop.hive.metastore.api.Database)8 Table (org.apache.hadoop.hive.metastore.api.Table)7 Partition (org.apache.hadoop.hive.metastore.api.Partition)5 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)2 Index (org.apache.hadoop.hive.metastore.api.Index)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 Role (org.apache.hadoop.hive.metastore.api.Role)2 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)2 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)2 SQLForeignKey (org.apache.hadoop.hive.metastore.api.SQLForeignKey)1 SQLPrimaryKey (org.apache.hadoop.hive.metastore.api.SQLPrimaryKey)1 AfterClass (org.junit.AfterClass)1 BeforeClass (org.junit.BeforeClass)1