maheshk114 commented on a change in pull request #847: HIVE-22512 : Use direct
SQL to fetch column privileges in refreshPrivileges.
URL: https://github.com/apache/hive/pull/847#discussion_r349098482
##########
File path:
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java
##########
@@ -1280,6 +1284,94 @@ public ColumnStatistics getTableStats(final String
catName, final String dbName,
return result;
}
+ public List<HiveObjectPrivilege> getTableAllColumnGrants(String catName,
String dbName,
+ String tableName,
String authorizer) throws MetaException {
+ Query query = null;
+
+ // These constants should match the SELECT clause of the query.
+ final int authorizerIndex = 0;
+ final int columnNameIndex = 1;
+ final int createTimeIndex = 2;
+ final int grantOptionIndex = 3;
+ final int grantorIndex = 4;
+ final int grantorTypeIndex = 5;
+ final int principalNameIndex = 6;
+ final int principalTypeIndex = 7;
+ final int privilegeIndex = 8;
+
+ // Retrieve the privileges from the object store. Just grab only the
required fields.
+ String queryText = "select " +
+ TBL_COL_PRIVS + ".\"AUTHORIZER\", " +
+ TBL_COL_PRIVS + ".\"COLUMN_NAME\", " +
+ TBL_COL_PRIVS + ".\"CREATE_TIME\", " +
+ TBL_COL_PRIVS + ".\"GRANT_OPTION\", " +
+ TBL_COL_PRIVS + ".\"GRANTOR\", " +
+ TBL_COL_PRIVS + ".\"GRANTOR_TYPE\", " +
+ TBL_COL_PRIVS + ".\"PRINCIPAL_NAME\", " +
+ TBL_COL_PRIVS + ".\"PRINCIPAL_TYPE\", " +
+ TBL_COL_PRIVS + ".\"TBL_COL_PRIV\", " +
+ TBL_COL_PRIVS + ".\"TBL_COLUMN_GRANT_ID\" " +
+ "FROM " + TBL_COL_PRIVS + " LEFT OUTER JOIN " + TBLS +
+ " ON " + TBL_COL_PRIVS + ".\"TBL_ID\" = " + TBLS + ".\"TBL_ID\"" +
+ " LEFT OUTER JOIN " + DBS + " ON " + TBLS + ".\"DB_ID\" = " + DBS
+ ".\"DB_ID\" " +
+ " WHERE " + TBLS + ".\"TBL_NAME\" = ?" +
+ " AND " + DBS + ".\"NAME\" = ?" +
+ " AND " + DBS + ".\"CTLG_NAME\" = ?";
+
+ // Build the parameters, they should match the WHERE clause of the query.
+ int numParams = authorizer != null ? 4 : 3;
+ Object[] params = new Object[numParams];
+ params[0] = tableName;
+ params[1] = dbName;
+ params[2] = catName;
+ if (authorizer != null) {
+ queryText = queryText + " AND " + TBL_COL_PRIVS + ".\"AUTHORIZER\" = ?";
+ params[3] = authorizer;
+ }
+
+ // Collect the results into a list that the caller can consume.
+ List<HiveObjectPrivilege> result = new ArrayList<>();
+ try {
+ final boolean doTrace = LOG.isDebugEnabled();
+ long start = doTrace ? System.nanoTime() : 0;
+ query = pm.newQuery("javax.jdo.query.SQL", queryText);
Review comment:
these 3 statements can be moved outside try and then there will be no need
of null check in finally
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]