Vallishp commented on code in PR #33264:
URL: https://github.com/apache/doris/pull/33264#discussion_r1579922459


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ExpressionConverter.java:
##########
@@ -0,0 +1,92 @@
+// 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.trees.expressions.visitor;
+
+import org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.nereids.trees.expressions.ComparisonPredicate;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.InPredicate;
+import org.apache.doris.nereids.trees.expressions.IsNull;
+import org.apache.doris.nereids.trees.expressions.Like;
+import org.apache.doris.nereids.trees.expressions.Not;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.StringRegexPredicate;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.planner.PartitionColumnFilter;
+
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * expression converter
+ */
+public class ExpressionConverter
+        extends ExpressionColumnFilterConverter {
+
+    public ExpressionConverter(Map<String, PartitionColumnFilter> filterMap) {
+        super(filterMap);
+    }
+
+    /**
+     * check and maybe commute for predications except not pred.
+     */
+    public static Optional<Expression> checkAndMaybeCommute(Expression 
expression) {
+        if (expression instanceof Not) {
+            return Optional.empty();
+        }
+        if (expression instanceof InPredicate) {
+            InPredicate predicate = ((InPredicate) expression);
+            if (!predicate.getCompareExpr().isSlot()) {
+                return Optional.empty();
+            }
+            return Optional.ofNullable(predicate.getOptions().stream()
+                    .allMatch(Expression::isLiteral) ? expression : null);
+        } else if (expression instanceof ComparisonPredicate) {
+            ComparisonPredicate predicate = ((ComparisonPredicate) expression);
+            if (predicate.left() instanceof Literal) {
+                predicate = predicate.commute();
+            }
+            return Optional.ofNullable(predicate.left().isSlot() && 
predicate.right().isLiteral() ? predicate : null);
+        } else if (expression instanceof IsNull) {
+            return Optional.ofNullable(((IsNull) expression).child().isSlot() 
? expression : null);
+        } else if (expression instanceof StringRegexPredicate) {
+            return Optional.ofNullable(expression);
+        }
+        return Optional.empty();
+    }
+
+    @Override
+    public void convert(Expression expr) {
+        expr.accept(this, null);
+    }
+
+    @Override
+    public Expression visitLike(Like like, Void unused) {
+        String columnName = "Name";

Review Comment:
   > u add this class only want to get like right child? u could get it easily 
by
   > 
   > ```
   > Collection<Experssion> patterns = 
whereExpr.stream().filter(Like.class::isInstance).map(e -> 
e.child(1)).collect(....);
   > ```
   
   Thank you very much for your valuable comments. I have refactored code as 
per your suggestion. It looks simpler now. Thanks again. pls help to review 
again.



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