use of org.apache.hadoop.hive.metastore.RawStore in project hive by apache.
the class TestHBaseImport method importOneTablePartitioned.
@Test
public void importOneTablePartitioned() throws Exception {
RawStore rdbms;
rdbms = new ObjectStore();
rdbms.setConf(conf);
String[] dbNames = new String[] { "onetabpartdb1", "onetabpartodb2" };
String[] roles = new String[] { "onetabpartorole1", "onetabpartorole2" };
String[] tokenIds = new String[] { "onetabpartotokenid1", "onetabpartotokenid2" };
String[] tokens = new String[] { "onetabpartotoken1", "onetabpartotoken2" };
String[] masterKeys = new String[] { "onetabpartomk1", "onetabpartomk2" };
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;
// 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("-t", dbNames[0] + "." + tableNames[1]);
importer.setConnections(rdbms, store);
importer.run();
// Make sure there aren't any extra roles
Assert.assertEquals(baseNumRoles, store.listRoleNames().size());
Database db = store.getDatabase(dbNames[0]);
Assert.assertNotNull(db);
Table table = store.getTable(db.getName(), tableNames[1]);
Assert.assertNotNull(table);
Assert.assertEquals(1, store.getAllTables(db.getName()).size());
for (int j = 0; j < partVals.length; j++) {
Partition part = store.getPartition(dbNames[0], tableNames[1], Arrays.asList(partVals[j]));
Assert.assertNotNull(part);
Assert.assertEquals("file:/tmp/region=" + partVals[j], part.getSd().getLocation());
}
Assert.assertEquals(4, store.getPartitions(dbNames[0], tableNames[1], -1).size());
Assert.assertNull(store.getTable(db.getName(), tableNames[0]));
List<Index> indexes = store.getIndexes(db.getName(), tableNames[1], -1);
Assert.assertEquals(0, indexes.size());
Assert.assertEquals(0, store.getFunctions(dbNames[0], "*").size());
Assert.assertEquals(baseNumDbs + 1, store.getAllDatabases().size());
Assert.assertEquals(baseNumToks, store.getAllTokenIdentifiers().size());
String[] hbaseKeys = store.getMasterKeys();
Assert.assertEquals(baseNumKeys, hbaseKeys.length);
}
use of org.apache.hadoop.hive.metastore.RawStore in project hive by apache.
the class TestHBaseImport method startup.
@BeforeClass
public static void startup() throws Exception {
HBaseIntegrationTests.startMiniCluster();
RawStore rdbms;
rdbms = new ObjectStore();
rdbms.setConf(conf);
TestObjectStore.dropAllStoreObjects(rdbms);
}
use of org.apache.hadoop.hive.metastore.RawStore in project hive by apache.
the class TestHBaseImport method shutdown.
@AfterClass
public static void shutdown() throws Exception {
RawStore rdbms;
rdbms = new ObjectStore();
rdbms.setConf(conf);
TestObjectStore.dropAllStoreObjects(rdbms);
for (int seq : masterKeySeqs) {
rdbms.removeMasterKey(seq);
}
HBaseIntegrationTests.shutdownMiniCluster();
}
use of org.apache.hadoop.hive.metastore.RawStore in project hive by apache.
the class TestHBaseImport method importSecurity.
@Test
public void importSecurity() throws Exception {
RawStore rdbms;
rdbms = new ObjectStore();
rdbms.setConf(conf);
String[] dbNames = new String[] { "securitydb1", "securitydb2" };
String[] roles = new String[] { "securityrole1", "securityrole2" };
String[] tokenIds = new String[] { "securitytokenid1", "securitytokenid2" };
String[] tokens = new String[] { "securitytoken1", "securitytoken2" };
String[] masterKeys = new String[] { "securitymk1", "securitymk2" };
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();
HBaseImport importer = new HBaseImport("-k");
importer.setConnections(rdbms, store);
importer.run();
Assert.assertEquals(baseNumRoles, store.listRoleNames().size());
Assert.assertEquals(baseNumDbs, store.getAllDatabases().size());
// guarantee.
for (int i = 0; i < tokenIds.length; i++) {
Assert.assertEquals(tokens[i], store.getToken(tokenIds[i]));
}
String[] hbaseKeys = store.getMasterKeys();
Set<String> keys = new HashSet<>(Arrays.asList(hbaseKeys));
for (int i = 0; i < masterKeys.length; i++) {
Assert.assertTrue(keys.contains(masterKeys[i]));
}
}
use of org.apache.hadoop.hive.metastore.RawStore 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());
}
Aggregations