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());
}
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]);
}
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;
}
}
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);
}
}
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);
}
}
Aggregations