Search in sources :

Example 6 with ObjectStore

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

the class TestHBaseImport method parallel.

@Test
public void parallel() throws Exception {
    int parallelFactor = 10;
    RawStore rdbms;
    rdbms = new ObjectStore();
    rdbms.setConf(conf);
    String[] dbNames = new String[] { "paralleldb1" };
    int now = (int) System.currentTimeMillis() / 1000;
    for (int i = 0; i < dbNames.length; i++) {
        rdbms.createDatabase(new Database(dbNames[i], "no description", "file:/tmp", emptyParameters));
        List<FieldSchema> cols = new ArrayList<>();
        cols.add(new FieldSchema("col1", "int", "nocomment"));
        SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
        StorageDescriptor sd = new StorageDescriptor(cols, "file:/tmp", "input", "output", false, 0, serde, null, null, emptyParameters);
        List<FieldSchema> partCols = new ArrayList<>();
        partCols.add(new FieldSchema("region", "string", ""));
        for (int j = 0; j < parallelFactor; j++) {
            rdbms.createTable(new Table("t" + j, dbNames[i], "me", now, now, 0, sd, partCols, emptyParameters, null, null, null));
            for (int k = 0; k < parallelFactor; k++) {
                StorageDescriptor psd = new StorageDescriptor(sd);
                psd.setLocation("file:/tmp/region=" + k);
                Partition part = new Partition(Arrays.asList("p" + k), dbNames[i], "t" + j, now, now, psd, emptyParameters);
                rdbms.addPartition(part);
            }
        }
    }
    HBaseImport importer = new HBaseImport("-p", "2", "-b", "2", "-d", dbNames[0]);
    importer.setConnections(rdbms, store);
    importer.run();
    for (int i = 0; i < dbNames.length; i++) {
        Database db = store.getDatabase(dbNames[i]);
        Assert.assertNotNull(db);
        for (int j = 0; j < parallelFactor; j++) {
            Table table = store.getTable(db.getName(), "t" + j);
            Assert.assertNotNull(table);
            Assert.assertEquals(now, table.getLastAccessTime());
            Assert.assertEquals("input", table.getSd().getInputFormat());
            for (int k = 0; k < parallelFactor; k++) {
                Partition part = store.getPartition(dbNames[i], "t" + j, Arrays.asList("p" + k));
                Assert.assertNotNull(part);
                Assert.assertEquals("file:/tmp/region=" + k, part.getSd().getLocation());
            }
            Assert.assertEquals(parallelFactor, store.getPartitions(dbNames[i], "t" + j, -1).size());
        }
        Assert.assertEquals(parallelFactor, store.getAllTables(dbNames[i]).size());
    }
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) TestObjectStore(org.apache.hadoop.hive.metastore.TestObjectStore) ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore) Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) ArrayList(java.util.ArrayList) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) RawStore(org.apache.hadoop.hive.metastore.RawStore) Database(org.apache.hadoop.hive.metastore.api.Database) Test(org.junit.Test)

Example 7 with ObjectStore

use of org.apache.hadoop.hive.metastore.ObjectStore 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);
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) TestObjectStore(org.apache.hadoop.hive.metastore.TestObjectStore) ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore) Table(org.apache.hadoop.hive.metastore.api.Table) Database(org.apache.hadoop.hive.metastore.api.Database) Index(org.apache.hadoop.hive.metastore.api.Index) RawStore(org.apache.hadoop.hive.metastore.RawStore) Test(org.junit.Test)

Example 8 with ObjectStore

use of org.apache.hadoop.hive.metastore.ObjectStore 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);
}
Also used : TestObjectStore(org.apache.hadoop.hive.metastore.TestObjectStore) ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore) RawStore(org.apache.hadoop.hive.metastore.RawStore) BeforeClass(org.junit.BeforeClass)

Example 9 with ObjectStore

use of org.apache.hadoop.hive.metastore.ObjectStore 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();
}
Also used : TestObjectStore(org.apache.hadoop.hive.metastore.TestObjectStore) ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore) RawStore(org.apache.hadoop.hive.metastore.RawStore) AfterClass(org.junit.AfterClass)

Example 10 with ObjectStore

use of org.apache.hadoop.hive.metastore.ObjectStore 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]));
    }
}
Also used : TestObjectStore(org.apache.hadoop.hive.metastore.TestObjectStore) ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore) RawStore(org.apache.hadoop.hive.metastore.RawStore) HashSet(java.util.HashSet) Test(org.junit.Test)

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