Search in sources :

Example 21 with SerDeInfo

use of org.apache.hadoop.hive.metastore.api.SerDeInfo in project hive by apache.

the class TestHBaseStoreIntegration method addPartitions.

@Test
public void addPartitions() throws Exception {
    String dbName = "default";
    String tableName = "addParts";
    int startTime = (int) (System.currentTimeMillis() / 1000);
    List<FieldSchema> cols = new ArrayList<FieldSchema>();
    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<FieldSchema>();
    partCols.add(new FieldSchema("pc", "string", ""));
    Table table = new Table(tableName, dbName, "me", startTime, startTime, 0, sd, partCols, emptyParameters, null, null, null);
    store.createTable(table);
    List<String> partVals = Arrays.asList("alan", "bob", "carl", "doug", "ethan");
    List<Partition> partitions = new ArrayList<Partition>();
    for (String val : partVals) {
        List<String> vals = new ArrayList<String>();
        vals.add(val);
        StorageDescriptor psd = new StorageDescriptor(sd);
        psd.setLocation("file:/tmp/pc=" + val);
        Partition part = new Partition(vals, dbName, tableName, startTime, startTime, psd, emptyParameters);
        partitions.add(part);
    }
    store.addPartitions(dbName, tableName, partitions);
    List<String> partNames = store.listPartitionNames(dbName, tableName, (short) -1);
    Assert.assertEquals(5, partNames.size());
    String[] names = partNames.toArray(new String[partNames.size()]);
    Arrays.sort(names);
    String[] canonicalNames = partVals.toArray(new String[partVals.size()]);
    for (int i = 0; i < canonicalNames.length; i++) canonicalNames[i] = "pc=" + canonicalNames[i];
    Assert.assertArrayEquals(canonicalNames, names);
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) 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) Test(org.junit.Test)

Example 22 with SerDeInfo

use of org.apache.hadoop.hive.metastore.api.SerDeInfo in project hive by apache.

the class TestHBaseStoreIntegration method listTableGrants.

@Test
public void listTableGrants() throws Exception {
    String dbName = "ltg_db";
    String[] tableNames = new String[] { "ltg_t1", "ltg_t2" };
    try {
        Database db = new Database(dbName, "no description", "file:///tmp", emptyParameters);
        store.createDatabase(db);
        int startTime = (int) (System.currentTimeMillis() / 1000);
        List<FieldSchema> cols = new ArrayList<FieldSchema>();
        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);
        Table table = new Table(tableNames[0], dbName, "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
        store.createTable(table);
        table = new Table(tableNames[1], dbName, "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
        store.createTable(table);
        String[] roleNames = new String[] { "ltg_role1", "ltg_role2" };
        String[] userNames = new String[] { "gandalf", "radagast" };
        store.addRole(roleNames[0], "me");
        store.addRole(roleNames[1], "me");
        int now = (int) (System.currentTimeMillis() / 1000);
        Role role1 = store.getRole(roleNames[0]);
        Role role2 = store.getRole(roleNames[1]);
        store.grantRole(role1, userNames[0], PrincipalType.USER, "bob", PrincipalType.USER, false);
        store.grantRole(role1, roleNames[1], PrincipalType.ROLE, "admin", PrincipalType.ROLE, true);
        store.grantRole(role2, userNames[1], PrincipalType.USER, "bob", PrincipalType.USER, false);
        List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
        HiveObjectRef hiveObjRef = new HiveObjectRef(HiveObjectType.TABLE, dbName, tableNames[0], null, null);
        PrivilegeGrantInfo grantInfo = new PrivilegeGrantInfo("read", now, "me", PrincipalType.USER, false);
        HiveObjectPrivilege hop = new HiveObjectPrivilege(hiveObjRef, userNames[0], PrincipalType.USER, grantInfo);
        privileges.add(hop);
        grantInfo = new PrivilegeGrantInfo("write", now, "me", PrincipalType.USER, true);
        hop = new HiveObjectPrivilege(hiveObjRef, roleNames[0], PrincipalType.ROLE, grantInfo);
        privileges.add(hop);
        PrivilegeBag pBag = new PrivilegeBag(privileges);
        store.grantPrivileges(pBag);
        List<HiveObjectPrivilege> hops = store.listAllTableGrants(roleNames[0], PrincipalType.ROLE, dbName, tableNames[0]);
        Assert.assertEquals(1, hops.size());
        Assert.assertEquals(PrincipalType.ROLE, hops.get(0).getPrincipalType());
        Assert.assertEquals(HiveObjectType.TABLE, hops.get(0).getHiveObject().getObjectType());
        Assert.assertEquals("write", hops.get(0).getGrantInfo().getPrivilege());
        hops = store.listAllTableGrants(userNames[0], PrincipalType.USER, dbName, tableNames[0]);
        Assert.assertEquals(1, hops.size());
        Assert.assertEquals(PrincipalType.USER, hops.get(0).getPrincipalType());
        Assert.assertEquals(HiveObjectType.TABLE, hops.get(0).getHiveObject().getObjectType());
        Assert.assertEquals("read", hops.get(0).getGrantInfo().getPrivilege());
        hops = store.listAllTableGrants(roleNames[1], PrincipalType.ROLE, dbName, tableNames[0]);
        Assert.assertEquals(0, hops.size());
        hops = store.listAllTableGrants(userNames[1], PrincipalType.USER, dbName, tableNames[0]);
        Assert.assertEquals(0, hops.size());
        hops = store.listAllTableGrants(roleNames[0], PrincipalType.ROLE, dbName, tableNames[1]);
        Assert.assertEquals(0, hops.size());
        hops = store.listAllTableGrants(userNames[0], PrincipalType.USER, dbName, tableNames[1]);
        Assert.assertEquals(0, hops.size());
        hops = store.listTableGrantsAll(dbName, tableNames[0]);
        Assert.assertEquals(2, hops.size());
        boolean sawUser = false, sawRole = false;
        for (HiveObjectPrivilege h : hops) {
            if (h.getPrincipalName().equals(userNames[0])) {
                Assert.assertEquals(PrincipalType.USER, h.getPrincipalType());
                Assert.assertEquals(HiveObjectType.TABLE, h.getHiveObject().getObjectType());
                Assert.assertEquals("read", h.getGrantInfo().getPrivilege());
                sawUser = true;
            } else if (h.getPrincipalName().equals(roleNames[0])) {
                Assert.assertEquals(PrincipalType.ROLE, h.getPrincipalType());
                Assert.assertEquals(HiveObjectType.TABLE, h.getHiveObject().getObjectType());
                Assert.assertEquals("write", h.getGrantInfo().getPrivilege());
                sawRole = true;
            }
        }
        Assert.assertTrue(sawUser && sawRole);
        hops = store.listPrincipalTableGrantsAll(roleNames[0], PrincipalType.ROLE);
        Assert.assertEquals(1, hops.size());
        Assert.assertEquals(PrincipalType.ROLE, hops.get(0).getPrincipalType());
        Assert.assertEquals(HiveObjectType.TABLE, hops.get(0).getHiveObject().getObjectType());
        Assert.assertEquals("write", hops.get(0).getGrantInfo().getPrivilege());
        hops = store.listPrincipalTableGrantsAll(userNames[0], PrincipalType.USER);
        Assert.assertEquals(1, hops.size());
        Assert.assertEquals(PrincipalType.USER, hops.get(0).getPrincipalType());
        Assert.assertEquals(HiveObjectType.TABLE, hops.get(0).getHiveObject().getObjectType());
        Assert.assertEquals("read", hops.get(0).getGrantInfo().getPrivilege());
        hops = store.listPrincipalDBGrantsAll(roleNames[1], PrincipalType.ROLE);
        Assert.assertEquals(0, hops.size());
        hops = store.listPrincipalDBGrantsAll(userNames[1], PrincipalType.USER);
        Assert.assertEquals(0, hops.size());
    } finally {
        store.dropTable(dbName, tableNames[0]);
        store.dropTable(dbName, tableNames[1]);
        store.dropDatabase(dbName);
    }
}
Also used : PrivilegeBag(org.apache.hadoop.hive.metastore.api.PrivilegeBag) Table(org.apache.hadoop.hive.metastore.api.Table) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) ArrayList(java.util.ArrayList) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) Role(org.apache.hadoop.hive.metastore.api.Role) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) Database(org.apache.hadoop.hive.metastore.api.Database) Test(org.junit.Test)

Example 23 with SerDeInfo

use of org.apache.hadoop.hive.metastore.api.SerDeInfo in project hive by apache.

the class TestHBaseImport method parallelOdd.

// Same as the test above except we create 9 of everything instead of 10.  This is important
// because in using a batch size of 2 the previous test guarantees 10 /2 =5 , meaning we'll
// have 5 writes on the partition queue with exactly 2 entries.  In this test we'll handle the
// case where the last entry in the queue has fewer partitions.
@Test
public void parallelOdd() throws Exception {
    int parallelFactor = 9;
    RawStore rdbms;
    rdbms = new ObjectStore();
    rdbms.setConf(conf);
    String[] dbNames = new String[] { "oddparalleldb1" };
    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 24 with SerDeInfo

use of org.apache.hadoop.hive.metastore.api.SerDeInfo in project hive by apache.

the class TestHBaseStore method dropTable.

@Test
public void dropTable() throws Exception {
    String tableName = "dtable";
    int startTime = (int) (System.currentTimeMillis() / 1000);
    List<FieldSchema> cols = new ArrayList<FieldSchema>();
    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);
    Table table = new Table(tableName, "default", "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
    store.createTable(table);
    Table t = store.getTable("default", tableName);
    Assert.assertNotNull(t);
    store.dropTable("default", tableName);
    Assert.assertNull(store.getTable("default", tableName));
}
Also used : 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) Test(org.junit.Test)

Example 25 with SerDeInfo

use of org.apache.hadoop.hive.metastore.api.SerDeInfo in project hive by apache.

the class TestHBaseStore method createPartition.

@Test
public void createPartition() throws Exception {
    String tableName = "myparttable";
    int startTime = (int) (System.currentTimeMillis() / 1000);
    List<FieldSchema> cols = new ArrayList<FieldSchema>();
    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<FieldSchema>();
    partCols.add(new FieldSchema("pc", "string", ""));
    Table table = new Table(tableName, DB, "me", startTime, startTime, 0, sd, partCols, emptyParameters, null, null, null);
    store.createTable(table);
    List<String> vals = Arrays.asList("fred");
    StorageDescriptor psd = new StorageDescriptor(sd);
    psd.setLocation("file:/tmp/pc=fred");
    Partition part = new Partition(vals, DB, tableName, startTime, startTime, psd, emptyParameters);
    store.addPartition(part);
    Partition p = store.getPartition(DB, tableName, vals);
    Assert.assertEquals(1, p.getSd().getColsSize());
    Assert.assertEquals("col1", p.getSd().getCols().get(0).getName());
    Assert.assertEquals("int", p.getSd().getCols().get(0).getType());
    Assert.assertEquals("nocomment", p.getSd().getCols().get(0).getComment());
    Assert.assertEquals("serde", p.getSd().getSerdeInfo().getName());
    Assert.assertEquals("seriallib", p.getSd().getSerdeInfo().getSerializationLib());
    Assert.assertEquals("file:/tmp/pc=fred", p.getSd().getLocation());
    Assert.assertEquals("input", p.getSd().getInputFormat());
    Assert.assertEquals("output", p.getSd().getOutputFormat());
    Assert.assertEquals(DB, p.getDbName());
    Assert.assertEquals(tableName, p.getTableName());
    Assert.assertEquals(1, p.getValuesSize());
    Assert.assertEquals("fred", p.getValues().get(0));
    Assert.assertTrue(store.doesPartitionExist(DB, tableName, vals));
    Assert.assertFalse(store.doesPartitionExist(DB, tableName, Arrays.asList("bob")));
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) 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) Test(org.junit.Test)

Aggregations

SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)185 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)162 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)126 Table (org.apache.hadoop.hive.metastore.api.Table)124 ArrayList (java.util.ArrayList)121 Test (org.junit.Test)110 Partition (org.apache.hadoop.hive.metastore.api.Partition)65 HashMap (java.util.HashMap)51 Order (org.apache.hadoop.hive.metastore.api.Order)32 List (java.util.List)30 ColumnStatistics (org.apache.hadoop.hive.metastore.api.ColumnStatistics)28 ColumnStatisticsData (org.apache.hadoop.hive.metastore.api.ColumnStatisticsData)28 ColumnStatisticsDesc (org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc)28 ColumnStatisticsObj (org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj)28 AggrStats (org.apache.hadoop.hive.metastore.api.AggrStats)27 Database (org.apache.hadoop.hive.metastore.api.Database)22 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)22 SkewedInfo (org.apache.hadoop.hive.metastore.api.SkewedInfo)17 LongColumnStatsData (org.apache.hadoop.hive.metastore.api.LongColumnStatsData)13 Path (org.apache.hadoop.fs.Path)12