EmmyMiao87 commented on a change in pull request #4899:
URL: https://github.com/apache/incubator-doris/pull/4899#discussion_r522836663



##########
File path: fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java
##########
@@ -104,11 +104,32 @@ public static Builder builder() {
                             TableType.SCHEMA,
                             builder()
                                     .column("GRANTEE", 
ScalarType.createVarchar(NAME_CHAR_LEN))
-                                    .column("TABLE_CATALOG", 
ScalarType.createVarchar(NAME_CHAR_LEN))
+                                    .column("TABLE_CATALOG", 
ScalarType.createVarchar(FN_REFLEN))
                                     .column("TABLE_SCHEMA", 
ScalarType.createVarchar(NAME_CHAR_LEN))
                                     .column("TABLE_NAME", 
ScalarType.createVarchar(NAME_CHAR_LEN))
-                                    .column("PRIVILEGE_TYPE", 
ScalarType.createVarchar(NAME_CHAR_LEN))
-                                    .column("IS_GRANTABLE", 
ScalarType.createVarchar(NAME_CHAR_LEN))
+                                    .column("PRIVILEGE_TYPE", 
ScalarType.createVarchar(64))
+                                    .column("IS_GRANTABLE", 
ScalarType.createVarchar(3))
+                                    .build()))
+                    .put("schema_privileges", new SchemaTable(
+                            SystemIdGenerator.getNextId(),
+                            "schema_privileges",
+                            TableType.SCHEMA,
+                            builder()
+                                    .column("GRANTEE", 
ScalarType.createVarchar(NAME_CHAR_LEN))
+                                    .column("TABLE_CATALOG", 
ScalarType.createVarchar(FN_REFLEN))
+                                    .column("TABLE_SCHEMA", 
ScalarType.createVarchar(NAME_CHAR_LEN))
+                                    .column("PRIVILEGE_TYPE", 
ScalarType.createVarchar(64))

Review comment:
       Maybe add a constant variables like 'PRIVILEGE_TYPE_LEN' is better.

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/PaloAuth.java
##########
@@ -1300,6 +1301,120 @@ public TFetchResourceResult toResourceThrift() {
         }
     }
 
+    // Used for transforming privileges in palo to mysql.
+    private final String[] privilegesInMysql = new String[]{"", "", "", 
"SELECT", "INSERT", "ALTER",
+            "CREATE", "DROP", "USAGE"};
+
+    // Used for creating table_privileges table in information_schema.
+    public void getTablePrivStatus(List<TPrivilegeStatus> tblPrivResult, 
UserIdentity currentUser) {
+        readLock();
+        try {
+            for (PrivEntry entry : tablePrivTable.getEntries()) {
+                TablePrivEntry tblPrivEntry = (TablePrivEntry) entry;
+                String dbName = 
ClusterNamespace.getNameFromFullName(tblPrivEntry.getOrigDb());
+                String tblName = tblPrivEntry.getOrigTbl();
+
+                if (dbName.equals("information_schema" /* Don't show 
privileges in information_schema */)
+                        || !checkTblPriv(currentUser, 
tblPrivEntry.getOrigDb(), tblName, PrivPredicate.SHOW)) {
+                    continue;
+                }
+
+                String grantee = new 
String("\'").concat(ClusterNamespace.getNameFromFullName(tblPrivEntry.getOrigUser()))
+                        
.concat("\'@\'").concat(tblPrivEntry.getOrigHost()).concat("\'");
+                String isGrantable = tblPrivEntry.getPrivSet().get(2) ? "yes" 
: "no"; //Grant_priv

Review comment:
       Are word of `yes` or `no` case sensitive ?

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/PaloAuth.java
##########
@@ -1300,6 +1301,120 @@ public TFetchResourceResult toResourceThrift() {
         }
     }
 
+    // Used for transforming privileges in palo to mysql.
+    private final String[] privilegesInMysql = new String[]{"", "", "", 
"SELECT", "INSERT", "ALTER",
+            "CREATE", "DROP", "USAGE"};
+
+    // Used for creating table_privileges table in information_schema.
+    public void getTablePrivStatus(List<TPrivilegeStatus> tblPrivResult, 
UserIdentity currentUser) {
+        readLock();
+        try {
+            for (PrivEntry entry : tablePrivTable.getEntries()) {
+                TablePrivEntry tblPrivEntry = (TablePrivEntry) entry;
+                String dbName = 
ClusterNamespace.getNameFromFullName(tblPrivEntry.getOrigDb());
+                String tblName = tblPrivEntry.getOrigTbl();
+
+                if (dbName.equals("information_schema" /* Don't show 
privileges in information_schema */)
+                        || !checkTblPriv(currentUser, 
tblPrivEntry.getOrigDb(), tblName, PrivPredicate.SHOW)) {
+                    continue;
+                }
+
+                String grantee = new 
String("\'").concat(ClusterNamespace.getNameFromFullName(tblPrivEntry.getOrigUser()))
+                        
.concat("\'@\'").concat(tblPrivEntry.getOrigHost()).concat("\'");
+                String isGrantable = tblPrivEntry.getPrivSet().get(2) ? "yes" 
: "no"; //Grant_priv
+                for (PaloPrivilege paloPriv : 
tblPrivEntry.getPrivSet().toPrivilegeList()) {
+                    if (paloPriv == PaloPrivilege.GRANT_PRIV) {
+                        continue;
+                    }
+                    TPrivilegeStatus status = new TPrivilegeStatus();
+                    status.setTableName(tblName);
+                    
status.setPrivilegeType(privilegesInMysql[paloPriv.getIdx()]);

Review comment:
       Maybe a map is better? such as <PaloPrivilege, String> ?




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to