morningman commented on code in PR #58034:
URL: https://github.com/apache/doris/pull/58034#discussion_r2552596717


##########
fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java:
##########
@@ -1565,6 +1578,81 @@ private static TFetchSchemaTableDataResult 
tablePropertiesMetadataResult(TSchema
         return result;
     }
 
+    private static TFetchSchemaTableDataResult 
databasePropertiesMetadataResult(TSchemaTableRequestParams params) {
+        if (!params.isSetCurrentUserIdent()) {
+            return errorResult("current user ident is not set.");
+        }
+        if (!params.isSetDbId()) {
+            return errorResult("current db id is not set.");
+        }
+        if (!params.isSetCatalog()) {
+            return errorResult("current catalog is not set.");
+        }
+
+        TUserIdentity tcurrentUserIdentity = params.getCurrentUserIdent();
+        UserIdentity currentUserIdentity = 
UserIdentity.fromThrift(tcurrentUserIdentity);
+        TFetchSchemaTableDataResult result = new TFetchSchemaTableDataResult();
+        Long dbId = params.getDbId();
+        String clg = params.getCatalog();
+        List<TRow> dataBatch = Lists.newArrayList();
+        CatalogIf catalog = 
Env.getCurrentEnv().getCatalogMgr().getCatalog(clg);
+        if (catalog == null) {
+            result.setDataBatch(dataBatch);
+            result.setStatus(new TStatus(TStatusCode.OK));
+            return result;
+        }
+        DatabaseIf databaseIf = catalog.getDbNullable(dbId);
+        if (databaseIf == null) {
+            result.setDataBatch(dataBatch);
+            result.setStatus(new TStatus(TStatusCode.OK));
+            return result;
+        }
+
+        if (catalog instanceof InternalCatalog) {
+            if 
(!Env.getCurrentEnv().getAccessManager().checkDbPriv(currentUserIdentity, 
catalog.getName(),

Review Comment:
   We can move this auth check outside the `if` block.
   Same suggestion for `else` block



##########
fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java:
##########
@@ -1565,6 +1578,81 @@ private static TFetchSchemaTableDataResult 
tablePropertiesMetadataResult(TSchema
         return result;
     }
 
+    private static TFetchSchemaTableDataResult 
databasePropertiesMetadataResult(TSchemaTableRequestParams params) {
+        if (!params.isSetCurrentUserIdent()) {
+            return errorResult("current user ident is not set.");
+        }
+        if (!params.isSetDbId()) {
+            return errorResult("current db id is not set.");
+        }
+        if (!params.isSetCatalog()) {
+            return errorResult("current catalog is not set.");
+        }
+
+        TUserIdentity tcurrentUserIdentity = params.getCurrentUserIdent();
+        UserIdentity currentUserIdentity = 
UserIdentity.fromThrift(tcurrentUserIdentity);
+        TFetchSchemaTableDataResult result = new TFetchSchemaTableDataResult();
+        Long dbId = params.getDbId();
+        String clg = params.getCatalog();
+        List<TRow> dataBatch = Lists.newArrayList();
+        CatalogIf catalog = 
Env.getCurrentEnv().getCatalogMgr().getCatalog(clg);
+        if (catalog == null) {
+            result.setDataBatch(dataBatch);
+            result.setStatus(new TStatus(TStatusCode.OK));
+            return result;
+        }
+        DatabaseIf databaseIf = catalog.getDbNullable(dbId);
+        if (databaseIf == null) {
+            result.setDataBatch(dataBatch);
+            result.setStatus(new TStatus(TStatusCode.OK));
+            return result;
+        }
+
+        if (catalog instanceof InternalCatalog) {
+            if 
(!Env.getCurrentEnv().getAccessManager().checkDbPriv(currentUserIdentity, 
catalog.getName(),
+                    databaseIf.getFullName(), PrivPredicate.SHOW)) {
+                result.setDataBatch(dataBatch);
+                result.setStatus(new TStatus(TStatusCode.OK));
+                return result;
+            }
+            Database db = (Database) databaseIf;
+            Map<String, String> props = db.getDbProperties().getProperties();
+            if (props == null || props.isEmpty()) {
+                TRow trow = new TRow();
+                trow.addToColumnValue(new 
TCell().setStringVal(catalog.getName()));
+                trow.addToColumnValue(new 
TCell().setStringVal(databaseIf.getFullName()));
+                trow.addToColumnValue(new TCell().setStringVal(""));
+                trow.addToColumnValue(new TCell().setStringVal(""));
+                dataBatch.add(trow);
+            } else {
+                props.forEach((key, value) -> {
+                    TRow trow = new TRow();
+                    trow.addToColumnValue(new 
TCell().setStringVal(catalog.getName()));
+                    trow.addToColumnValue(new 
TCell().setStringVal(databaseIf.getFullName()));
+                    trow.addToColumnValue(new TCell().setStringVal(key));
+                    trow.addToColumnValue(new TCell().setStringVal(value));
+                    dataBatch.add(trow);
+                });
+            }
+        } else if (catalog instanceof ExternalCatalog) {
+            if 
(!Env.getCurrentEnv().getAccessManager().checkDbPriv(currentUserIdentity, 
catalog.getName(),
+                    databaseIf.getFullName(), PrivPredicate.SHOW)) {
+                result.setDataBatch(dataBatch);
+                result.setStatus(new TStatus(TStatusCode.OK));
+                return result;
+            }
+            TRow trow = new TRow();
+            trow.addToColumnValue(new TCell().setStringVal(catalog.getName()));
+            trow.addToColumnValue(new 
TCell().setStringVal(databaseIf.getFullName()));
+            trow.addToColumnValue(new TCell().setStringVal(""));

Review Comment:
   The ExternalDatabase also has a `databaseProperty` member. Although it is 
not used currenlty, but I think we should add it here now.



-- 
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: [email protected]

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