Search in sources :

Example 1 with PrivilegeGrantInfoBuilder

use of org.apache.hadoop.hive.metastore.client.builder.PrivilegeGrantInfoBuilder in project hive by apache.

the class TestObjectStore method createPartitionedTable.

/**
 * Creates DB1 database, TABLE1 table with 3 partitions.
 * @param withPrivileges Should we create privileges as well
 * @param withStatistics Should we create statitics as well
 */
private void createPartitionedTable(boolean withPrivileges, boolean withStatistics) throws Exception {
    Database db1 = new DatabaseBuilder().setName(DB1).setDescription("description").setLocation("locationurl").build(conf);
    try (AutoCloseable c = deadline()) {
        objectStore.createDatabase(db1);
    }
    Table tbl1 = new TableBuilder().setDbName(DB1).setTableName(TABLE1).addCol("test_col1", "int").addCol("test_col2", "int").addPartCol("test_part_col", "int").addCol("test_bucket_col", "int", "test bucket col comment").addCol("test_skewed_col", "int", "test skewed col comment").addCol("test_sort_col", "int", "test sort col comment").build(conf);
    try (AutoCloseable c = deadline()) {
        objectStore.createTable(tbl1);
    }
    PrivilegeBag privilegeBag = new PrivilegeBag();
    // Create partitions for the partitioned table
    for (int i = 0; i < 3; i++) {
        Partition part = new PartitionBuilder().inTable(tbl1).addValue("a" + i).addSerdeParam("serdeParam", "serdeParamValue").addStorageDescriptorParam("sdParam", "sdParamValue").addBucketCol("test_bucket_col").addSkewedColName("test_skewed_col").addSortCol("test_sort_col", 1).build(conf);
        try (AutoCloseable c = deadline()) {
            objectStore.addPartition(part);
        }
        if (withPrivileges) {
            HiveObjectRef partitionReference = new HiveObjectRefBuilder().buildPartitionReference(part);
            HiveObjectRef partitionColumnReference = new HiveObjectRefBuilder().buildPartitionColumnReference(tbl1, "test_part_col", part.getValues());
            PrivilegeGrantInfo privilegeGrantInfo = new PrivilegeGrantInfoBuilder().setPrivilege("a").build();
            HiveObjectPrivilege partitionPriv = new HiveObjectPrivilegeBuilder().setHiveObjectRef(partitionReference).setPrincipleName("a").setPrincipalType(PrincipalType.USER).setGrantInfo(privilegeGrantInfo).build();
            privilegeBag.addToPrivileges(partitionPriv);
            HiveObjectPrivilege partitionColPriv = new HiveObjectPrivilegeBuilder().setHiveObjectRef(partitionColumnReference).setPrincipleName("a").setPrincipalType(PrincipalType.USER).setGrantInfo(privilegeGrantInfo).build();
            privilegeBag.addToPrivileges(partitionColPriv);
        }
        if (withStatistics) {
            ColumnStatistics stats = new ColumnStatistics();
            ColumnStatisticsDesc desc = new ColumnStatisticsDesc();
            desc.setCatName(tbl1.getCatName());
            desc.setDbName(tbl1.getDbName());
            desc.setTableName(tbl1.getTableName());
            desc.setPartName("test_part_col=a" + i);
            stats.setStatsDesc(desc);
            List<ColumnStatisticsObj> statsObjList = new ArrayList<>(1);
            stats.setStatsObj(statsObjList);
            stats.setEngine(ENGINE);
            ColumnStatisticsData data = new ColumnStatisticsData();
            LongColumnStatsData longStats = new LongColumnStatsData();
            longStats.setNumNulls(1);
            longStats.setNumDVs(2);
            longStats.setLowValue(3);
            longStats.setHighValue(4);
            data.setLongStats(longStats);
            ColumnStatisticsObj partStats = new ColumnStatisticsObj("test_part_col", "int", data);
            statsObjList.add(partStats);
            try (AutoCloseable c = deadline()) {
                objectStore.updatePartitionColumnStatistics(stats, part.getValues(), null, -1);
            }
        }
    }
    if (withPrivileges) {
        try (AutoCloseable c = deadline()) {
            objectStore.grantPrivileges(privilegeBag);
        }
    }
}
Also used : ColumnStatistics(org.apache.hadoop.hive.metastore.api.ColumnStatistics) PrivilegeBag(org.apache.hadoop.hive.metastore.api.PrivilegeBag) Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) TestHiveMetaStore.createSourceTable(org.apache.hadoop.hive.metastore.TestHiveMetaStore.createSourceTable) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) HiveObjectPrivilegeBuilder(org.apache.hadoop.hive.metastore.client.builder.HiveObjectPrivilegeBuilder) ArrayList(java.util.ArrayList) LongColumnStatsData(org.apache.hadoop.hive.metastore.api.LongColumnStatsData) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) ColumnStatisticsObj(org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj) PartitionBuilder(org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder) HiveObjectRefBuilder(org.apache.hadoop.hive.metastore.client.builder.HiveObjectRefBuilder) ColumnStatisticsDesc(org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc) Database(org.apache.hadoop.hive.metastore.api.Database) PrivilegeGrantInfoBuilder(org.apache.hadoop.hive.metastore.client.builder.PrivilegeGrantInfoBuilder) ColumnStatisticsData(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData)

Aggregations

ArrayList (java.util.ArrayList)1 TestHiveMetaStore.createSourceTable (org.apache.hadoop.hive.metastore.TestHiveMetaStore.createSourceTable)1 ColumnStatistics (org.apache.hadoop.hive.metastore.api.ColumnStatistics)1 ColumnStatisticsData (org.apache.hadoop.hive.metastore.api.ColumnStatisticsData)1 ColumnStatisticsDesc (org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc)1 ColumnStatisticsObj (org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj)1 Database (org.apache.hadoop.hive.metastore.api.Database)1 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)1 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)1 LongColumnStatsData (org.apache.hadoop.hive.metastore.api.LongColumnStatsData)1 Partition (org.apache.hadoop.hive.metastore.api.Partition)1 PrivilegeBag (org.apache.hadoop.hive.metastore.api.PrivilegeBag)1 PrivilegeGrantInfo (org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo)1 SourceTable (org.apache.hadoop.hive.metastore.api.SourceTable)1 Table (org.apache.hadoop.hive.metastore.api.Table)1 DatabaseBuilder (org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder)1 HiveObjectPrivilegeBuilder (org.apache.hadoop.hive.metastore.client.builder.HiveObjectPrivilegeBuilder)1 HiveObjectRefBuilder (org.apache.hadoop.hive.metastore.client.builder.HiveObjectRefBuilder)1 PartitionBuilder (org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder)1 PrivilegeGrantInfoBuilder (org.apache.hadoop.hive.metastore.client.builder.PrivilegeGrantInfoBuilder)1