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