morrySnow commented on code in PR #46864:
URL: https://github.com/apache/doris/pull/46864#discussion_r1914297560


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownFilterIntoSchemaScan.java:
##########
@@ -0,0 +1,77 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.rules.rewrite;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import org.apache.doris.nereids.trees.expressions.EqualTo;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
+import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
+import org.apache.doris.nereids.trees.plans.logical.LogicalSchemaScan;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.Optional;
+
+/**
+ * Used to push down catalog/db/table name to schema scan node.
+ */
+public class PushDownFilterIntoSchemaScan extends OneRewriteRuleFactory {
+
+    @Override
+    public Rule build() {
+        return logicalFilter(logicalSchemaScan()).when(p -> 
!p.child().isFilterPushed()).thenApply(ctx -> {
+            LogicalFilter<LogicalSchemaScan> filter = ctx.root;
+            LogicalSchemaScan scan = filter.child();
+            String schemaCatalog = null;
+            String schemaDatabase = null;
+            String schemaTable = null;
+            for (Expression expression : filter.getConjuncts()) {
+                if (!(expression instanceof EqualTo)) {
+                    continue;
+                }
+                Expression slot = expression.child(0);
+                if (!(slot instanceof SlotReference)) {
+                    continue;
+                }
+                Optional<Column> column = ((SlotReference) slot).getColumn();
+                if (!column.isPresent()) {
+                    continue;
+                }
+                String columnName = column.get().getName();
+                Expression slotValue = expression.child(1);
+                if (!(slotValue instanceof VarcharLiteral)) {
+                    continue;
+                }
+                String columnValue = ((VarcharLiteral) slotValue).getValue();
+                if ("TABLE_CATALOG".equals(columnName)) {
+                    schemaCatalog = columnValue;
+                } else if ("TABLE_SCHEMA".equals(columnName)) {
+                    schemaDatabase = columnValue;
+                } else if ("TABLE_NAME".equals(columnName)) {
+                    schemaTable = columnValue;

Review Comment:
   does all schema table with table info have the same column name aboult 
catalog, schema and table name?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalSchemaScan.java:
##########
@@ -27,20 +27,51 @@
 import org.apache.doris.nereids.util.Utils;
 
 import java.util.List;
+import java.util.Objects;
 import java.util.Optional;
 
 /**
  * LogicalSchemaScan.
  */
 public class LogicalSchemaScan extends LogicalCatalogRelation {
 
+    private final boolean filterPushed;
+    private final String schemaCatalog;
+    private final String schemaDatabase;
+    private final String schemaTable;
+
     public LogicalSchemaScan(RelationId id, TableIf table, List<String> 
qualifier) {
         super(id, PlanType.LOGICAL_SCHEMA_SCAN, table, qualifier);
+        this.filterPushed = false;
+        this.schemaCatalog = null;
+        this.schemaDatabase = null;
+        this.schemaTable = null;

Review Comment:
   use Optional to avoid NPE



##########
be/src/exec/schema_scanner/schema_tables_scanner.cpp:
##########
@@ -111,6 +111,8 @@ Status SchemaTablesScanner::_get_new_table() {
     _db_index++;
     if (nullptr != _param->common_param->wild) {
         table_params.__set_pattern(*(_param->common_param->wild));
+    } else if (nullptr != _param->common_param->table) {
+        table_params.__set_pattern(*(_param->common_param->table));

Review Comment:
   pattern is ok? it maybe use for pattern matching, such as `like`



-- 
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: commits-unsubscr...@doris.apache.org

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


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

Reply via email to