924060929 commented on code in PR #54405:
URL: https://github.com/apache/doris/pull/54405#discussion_r2272765895


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/FrontendConjunctsUtils.java:
##########
@@ -0,0 +1,157 @@
+// 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.util;
+
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.nereids.analyzer.UnboundSlot;
+import org.apache.doris.nereids.parser.NereidsParser;
+import org.apache.doris.nereids.rules.expression.rules.FoldConstantRuleOnFE;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
+import org.apache.doris.persist.gson.GsonUtils;
+
+import com.google.common.collect.Lists;
+import com.google.gson.reflect.TypeToken;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+import java.util.TreeMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+
+/**
+ * FrontendConjunctsUtils
+ */
+public class FrontendConjunctsUtils {
+    private static final Logger LOG = 
LogManager.getLogger(FrontendConjunctsUtils.class);
+    private static List<String> nameParts;
+
+    public static List<Expression> convertToExpression(String conjuncts) {
+        List<Expr> exprs = GsonUtils.GSON.fromJson(conjuncts, new 
TypeToken<List<Expr>>() {
+        }.getType());
+        return exprs.stream()
+                .map(expr -> exprToExpression(expr))
+                .collect(Collectors.toList());
+    }
+
+    public static Expression exprToExpression(Expr expr) {
+        NereidsParser nereidsParser = new NereidsParser();
+        return nereidsParser.parseExpression(expr.toSql());
+    }
+
+    /**
+     * Filter out the conjuncts that contain the current slotName.
+     *
+     * @param expressions expressions
+     * @param slotName slotName
+     * @return filterBySlotName
+     */
+    public static List<Expression> filterBySlotName(List<Expression> 
expressions, String slotName) {
+        List<Expression> res = Lists.newArrayList();
+        for (Expression expression : expressions) {
+            if (containSlotName(expression, slotName)) {
+                res.add(expression);
+            }
+        }
+        return res;
+    }
+
+    private static boolean containSlotName(Expression expression, String 
slotName) {
+        return expression.anyMatch(c -> {
+            if (c instanceof UnboundSlot) {
+                List<String> nameParts = ((UnboundSlot) c).getNameParts();
+                if (!CollectionUtils.isEmpty(nameParts)) {
+                    String name = nameParts.get(nameParts.size() - 
1).toLowerCase();
+                    return name.equalsIgnoreCase(slotName);
+                }
+            }
+            return false;
+        });
+    }
+
+    public static boolean isFiltered(List<Expression> expressions, String 
columnName, Object value) {
+        TreeMap<String, Object> values = new 
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+        values.put(columnName, value);
+        return isFiltered(expressions, values);
+    }
+
+    /**
+     * isFiltered
+     *
+     * @param expressions expressions
+     * @param values case insensitive map
+     * @return isFiltered
+     */
+    public static boolean isFiltered(List<Expression> expressions, 
TreeMap<String, Object> values) {
+        for (Expression expression : expressions) {
+            if (isFiltered(expression, values)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * isFiltered
+     *
+     * @param expression expression
+     * @param values case insensitive map
+     * @return isFiltered
+     */
+    public static boolean isFiltered(Expression expression, TreeMap<String, 
Object> values) {
+        try {
+            AtomicBoolean containsAllColumn = new AtomicBoolean(true);
+            Expression rewrittenExpr = expression.rewriteUp(expr -> {
+                if (expr instanceof UnboundSlot) {
+                    List<String> nameParts = ((UnboundSlot) 
expr).getNameParts();
+                    if (!CollectionUtils.isEmpty(nameParts)) {
+                        String name = nameParts.get(nameParts.size() - 
1).toLowerCase();
+                        if (values.containsKey(name)) {
+                            return Literal.of(values.get(name));
+                        } else {
+                            containsAllColumn.set(false);
+                        }

Review Comment:
   should find map once
   ```java
   String name = nameParts.get(nameParts.size() - 1).toLowerCase();
   Object value = values.get(name);
   if (value != null) {
       return Literal.of(value);
   } else {
       containsAllColumn.set(false);
   }
   ```



##########
regression-test/suites/query_p0/schema_table/test_view_dependency.groovy:
##########
@@ -97,5 +97,40 @@ suite("test_view_dependency") {
     sql "create view stu_view_5 as select * from (select sid from mv_b) a join 
grade using(sid);"
 
     qt_sql "select * from information_schema.view_dependency where view_schema 
= 'test_view_dependency_db' order by view_catalog,view_schema,view_name"
+
+    order_qt_filter_1 "select * from information_schema.view_dependency where 
view_schema = 'test_view_dependency_db' and VIEW_NAME = 'mv_c'"
+    order_qt_filter_2 "select * from information_schema.view_dependency where 
view_schema = 'test_view_dependency_db' and VIEW_NAME like 'mv_%'"
+    order_qt_filter_3 "select * from information_schema.view_dependency where 
view_schema = 'test_view_dependency_db' and VIEW_NAME in('mv_c','mv_a')"
+    order_qt_filter_4 "select * from information_schema.view_dependency where 
view_schema = 'test_view_dependency_db' and VIEW_TYPE = 'MATERIALIZED_VIEW'"
+    order_qt_filter_5 "select * from information_schema.view_dependency where 
view_schema = 'test_view_dependency_db' and VIEW_TYPE = 'MATERIALIZED_VIEW' and 
VIEW_NAME not in('mv_c','mv_a')"
+    order_qt_filter_6 "select * from information_schema.view_dependency where 
view_schema = 'test_view_dependency_db' and VIEW_TYPE = 'MATERIALIZED_VIEW' or 
VIEW_NAME = 'stu_view_1'"
+
+    // support eq
+    def explain = sql """explain select * from 
information_schema.view_dependency where view_schema = 
'test_view_dependency_db'"""
+    assertTrue(explain.toString().contains("FRONTEND PREDICATES"))
+    // support in
+    explain = sql """explain select * from information_schema.view_dependency 
where view_schema in ('test_view_dependency_db','test_view_dependency_db1')"""
+    assertTrue(explain.toString().contains("FRONTEND PREDICATES"))
+    // support not in
+    explain = sql """explain select * from information_schema.view_dependency 
where view_schema not in 
('test_view_dependency_db','test_view_dependency_db1')"""
+    assertTrue(explain.toString().contains("FRONTEND PREDICATES"))
+    // support or
+    explain = sql """explain select * from information_schema.view_dependency 
where view_schema = 'test_view_dependency_db' or VIEW_NAME='stu_view_5'"""
+    assertTrue(explain.toString().contains("FRONTEND PREDICATES"))
+    // support >
+    explain = sql """explain select * from information_schema.view_dependency 
where view_schema > 'test_view_dependency_db'"""
+    assertTrue(explain.toString().contains("FRONTEND PREDICATES"))
+    // support >=
+    explain = sql """explain select * from information_schema.view_dependency 
where view_schema >= 'test_view_dependency_db'"""
+    assertTrue(explain.toString().contains("FRONTEND PREDICATES"))
+    // support <
+    explain = sql """explain select * from information_schema.view_dependency 
where view_schema < 'test_view_dependency_db'"""
+    assertTrue(explain.toString().contains("FRONTEND PREDICATES"))
+    // support <=
+    explain = sql """explain select * from information_schema.view_dependency 
where view_schema <= 'test_view_dependency_db'"""
+    assertTrue(explain.toString().contains("FRONTEND PREDICATES"))
+    // not support like
+    explain = sql """explain select * from information_schema.view_dependency 
where view_schema like '%test_view_dependency_db%'"""
+    assertFalse(explain.toString().contains("FRONTEND PREDICATES"))
 }

Review Comment:
   can these tests push down?
   1. `where catalog.db.table.column='xxx'`
   2. `where (db='xxx' or db='yyy') and (table='zzz' or table='aaa')`
   3. `where (db='xxx' and table='yyy') or (db='zzz' and table='aaa')`



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