Gabriel39 commented on code in PR #68299:
URL: https://github.com/apache/doris/pull/68299#discussion_r4059141412


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCatalogCommand.java:
##########
@@ -65,6 +84,26 @@ public ShowResultSet doRun(ConnectContext ctx, StmtExecutor 
executor) throws Exc
                 .showCatalogs(catalogName, pattern, ctx.getCurrentCatalog() != 
null
                     ? ctx.getCurrentCatalog().getName() : null);
 
+        if (whereClause == null || rows.isEmpty()) {
+            return new ShowResultSet(getMetaData(), rows);
+        }
+
+        // Apply WHERE only after the existing catalog privilege filter has 
produced the rows.
+        List<List<NamedExpression>> values = new ArrayList<>(rows.size());
+        for (List<String> row : rows) {
+            values.add(ImmutableList.of(
+                    new Alias(new BigIntLiteral(Long.parseLong(row.get(0))), 
"CatalogId"),
+                    new Alias(new StringLiteral(row.get(1)), "CatalogName"),
+                    new Alias(new StringLiteral(row.get(2)), "Type"),
+                    new Alias(new StringLiteral(row.get(3)), "IsCurrent"),
+                    new Alias(new StringLiteral(row.get(4)), "CreateTime"),
+                    new Alias(new StringLiteral(row.get(5)), "LastUpdateTime"),
+                    new Alias(new StringLiteral(row.get(6)), "Comment"),
+                    new Alias(new StringLiteral(row.get(7)), "ErrorMsg")));
+        }
+        LogicalPlan plan = new LogicalFilter<>(ImmutableSet.of(whereClause), 
new UnboundInlineTable(values));
+        plan = new LogicalSort<>(ImmutableList.of(new OrderKey(new 
UnboundSlot("CatalogName"), true, true)), plan);

Review Comment:
   Fixed in 1af2a0af77. The SQL sort was removed. Rows are filtered in the 
CatalogMgr-provided order and matching FE results are appended in that same 
order. The regression test covers the supplementary-plane/BMP ordering case.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCatalogCommand.java:
##########
@@ -65,6 +84,26 @@ public ShowResultSet doRun(ConnectContext ctx, StmtExecutor 
executor) throws Exc
                 .showCatalogs(catalogName, pattern, ctx.getCurrentCatalog() != 
null
                     ? ctx.getCurrentCatalog().getName() : null);
 
+        if (whereClause == null || rows.isEmpty()) {

Review Comment:
   Fixed in 1af2a0af77. Empty visible rows now use a typed dummy relation under 
LIMIT 0, which binds and type-checks the WHERE expression while still returning 
no rows. A regression test verifies that an unknown column is rejected for an 
empty catalog result.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCatalogCommand.java:
##########
@@ -65,6 +84,26 @@ public ShowResultSet doRun(ConnectContext ctx, StmtExecutor 
executor) throws Exc
                 .showCatalogs(catalogName, pattern, ctx.getCurrentCatalog() != 
null
                     ? ctx.getCurrentCatalog().getName() : null);
 
+        if (whereClause == null || rows.isEmpty()) {
+            return new ShowResultSet(getMetaData(), rows);
+        }
+
+        // Apply WHERE only after the existing catalog privilege filter has 
produced the rows.
+        List<List<NamedExpression>> values = new ArrayList<>(rows.size());
+        for (List<String> row : rows) {
+            values.add(ImmutableList.of(
+                    new Alias(new BigIntLiteral(Long.parseLong(row.get(0))), 
"CatalogId"),
+                    new Alias(new StringLiteral(row.get(1)), "CatalogName"),
+                    new Alias(new StringLiteral(row.get(2)), "Type"),
+                    new Alias(new StringLiteral(row.get(3)), "IsCurrent"),
+                    new Alias(new StringLiteral(row.get(4)), "CreateTime"),
+                    new Alias(new StringLiteral(row.get(5)), "LastUpdateTime"),
+                    new Alias(new StringLiteral(row.get(6)), "Comment"),
+                    new Alias(new StringLiteral(row.get(7)), "ErrorMsg")));
+        }
+        LogicalPlan plan = new LogicalFilter<>(ImmutableSet.of(whereClause), 
new UnboundInlineTable(values));
+        plan = new LogicalSort<>(ImmutableList.of(new OrderKey(new 
UnboundSlot("CatalogName"), true, true)), plan);
+        rows = Utils.executePlan(ctx, executor, new UnboundResultSink<>(plan));

Review Comment:
   Fixed in 1af2a0af77. The predicate now runs through a cloned, auto-restored 
ConnectContext and a direct FE Nereids plan, so it no longer invokes 
StmtExecutor's internal-query lifecycle or mutates the caller's parsed 
statement, query id, state, or audit lifecycle. The regression test asserts the 
outer query id, internal flag, and parsed statement remain unchanged.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCatalogCommand.java:
##########
@@ -65,6 +84,26 @@ public ShowResultSet doRun(ConnectContext ctx, StmtExecutor 
executor) throws Exc
                 .showCatalogs(catalogName, pattern, ctx.getCurrentCatalog() != 
null
                     ? ctx.getCurrentCatalog().getName() : null);
 
+        if (whereClause == null || rows.isEmpty()) {
+            return new ShowResultSet(getMetaData(), rows);
+        }
+
+        // Apply WHERE only after the existing catalog privilege filter has 
produced the rows.
+        List<List<NamedExpression>> values = new ArrayList<>(rows.size());
+        for (List<String> row : rows) {
+            values.add(ImmutableList.of(
+                    new Alias(new BigIntLiteral(Long.parseLong(row.get(0))), 
"CatalogId"),
+                    new Alias(new StringLiteral(row.get(1)), "CatalogName"),
+                    new Alias(new StringLiteral(row.get(2)), "Type"),
+                    new Alias(new StringLiteral(row.get(3)), "IsCurrent"),
+                    new Alias(new StringLiteral(row.get(4)), "CreateTime"),

Review Comment:
   Fixed in 1af2a0af77. Java null and FeConstants.null_string are now 
represented as typed NullLiteral values instead of StringLiteral values. Tests 
cover the internal catalog's null timestamps and a restored catalog row with a 
null comment.



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