HiveTableManager { public void grantPublicSelect(String tableName, String grantor) { HiveObjectRef hiveObject = new HiveObjectRef(TABLE, databaseName, tableName, null, null); PrivilegeGrantInfo grantInfo = new PrivilegeGrantInfo("SELECT", 0, grantor, ROLE, false); HiveObjectPrivilege privilege = new HiveObjectPrivilege(hiveObject, "public", ROLE, grantInfo); PrivilegeBag privilegeBag = new PrivilegeBag(singletonList(privilege)); try { metaStoreClient.grant_privileges(privilegeBag); } catch (TException e) { throw new MetaStoreException(e); } }  boolean tableExists(String tableName); Table createTable(String tableName, String partitionColumnName, Schema schema, int version, String owner); void grantPublicSelect(String tableName, String grantor); void alterTable(String tableName, Schema schema, int version); int getSchemaVersion(String tableName);  }
@Test public void grantPublicSelect() throws Exception { underTest.grantPublicSelect(TABLE, "grantor"); ArgumentCaptor<PrivilegeBag> privilegeBagCaptor = ArgumentCaptor.forClass(PrivilegeBag.class); verify(metaStoreClient).grant_privileges(privilegeBagCaptor.capture()); PrivilegeBag privilegeBag = privilegeBagCaptor.getValue(); assertThat(privilegeBag.getPrivilegesSize(), is(1)); HiveObjectPrivilege privilege = privilegeBag.getPrivileges().get(0); HiveObjectRef hiveObject = privilege.getHiveObject(); assertThat(hiveObject.getObjectType(), is(HiveObjectType.TABLE)); assertThat(hiveObject.getDbName(), is(DATABASE)); assertThat(hiveObject.getObjectName(), is(TABLE)); assertThat(hiveObject.getPartValues(), is(nullValue())); assertThat(hiveObject.getColumnName(), is(nullValue())); assertThat(privilege.getPrincipalName(), is("public")); assertThat(privilege.getPrincipalType(), is(ROLE)); PrivilegeGrantInfo grantInfo = privilege.getGrantInfo(); assertThat(grantInfo.getPrivilege(), is("SELECT")); assertThat(grantInfo.getCreateTime(), is(0)); assertThat(grantInfo.getGrantor(), is("grantor")); assertThat(grantInfo.getGrantorType(), is(ROLE)); assertThat(grantInfo.isGrantOption(), is(false)); }