nrg4878 commented on code in PR #4601:
URL: https://github.com/apache/hive/pull/4601#discussion_r1293477967


##########
ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/HivePrivilegeObjectUtils.java:
##########
@@ -59,7 +59,74 @@ public static List<HivePrivilegeObject> 
getHivePrivDcObjects(List<String> dcList
       objs.add(new HivePrivilegeObject(HivePrivilegeObjectType.DATACONNECTOR, 
null, dcname));
     }
     return objs;
+  }
+
+
+  /**
+   * An index on a table list by dbName, tableName.
+   */
+  public abstract static class TableIndex<T> {
+    private final T[] index;
+    protected abstract String getDbName(T item);
+    protected abstract String getTableName(T item);
+    protected TableIndex(List<T> tables) {
+      if (tables != null) {
+        index = tables.toArray((T[]) new Object[0]);
+        // sort them by dbname, tblname
+        Arrays.sort(index, (left, right)->{
+          int cmp = getDbName(left).compareTo(getDbName(right));
+          return cmp != 0
+              ? cmp
+              : getTableName(left).compareTo(getTableName(right));
+        });
+      } else {
+        index = (T[]) new Object[0];
+      }
+    }
 
+    /**
+     * Lookup using dichotomy using order described by Name, tblName
+     * @param dbName the database name
+     * @param tableName the table name
+     * @return the table if found in the index, null otherwise
+     */
+    public T lookup(String dbName, String tableName) {
+      int low = 0;
+      int high = index.length - 1;
+      while (low <= high) {
+        int mid = (low + high) >>> 1;
+        T item = index[mid];
+        int cmp = getDbName(item).compareTo(dbName);
+        if (cmp == 0) {
+          cmp = getTableName(item).compareTo(tableName);
+        }
+        if (cmp < 0)
+          low = mid + 1;
+        else if (cmp > 0)
+          high = mid - 1;
+        else
+          return item; // key found
+      }
+      return null;  // key not found.
+    }
   }
 
+  /**
+   * Specialized index for HivePrivilegeObject.
+   */
+  public static class PrivilegeIndex extends TableIndex<HivePrivilegeObject> {

Review Comment:
   nit: the name PrivilegeIndex may cause some confusion as we have 
table/column privileges stored in HMS, and we we have a PrivilegeSynchronizer 
class that periodically refreshes these. So just a suggestion that we use 
something like HivePrivilegeObjectIndex or something like that.



##########
ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/HivePrivilegeObjectUtils.java:
##########
@@ -59,7 +59,74 @@ public static List<HivePrivilegeObject> 
getHivePrivDcObjects(List<String> dcList
       objs.add(new HivePrivilegeObject(HivePrivilegeObjectType.DATACONNECTOR, 
null, dcname));
     }
     return objs;
+  }
+
+
+  /**
+   * An index on a table list by dbName, tableName.

Review Comment:
   nit: Can you please add a bit more context to this and what it is used for. 
git history can always point back to the jira but better if the class had 
comments on its purpose.



-- 
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.

To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to