englefly commented on code in PR #11805: URL: https://github.com/apache/doris/pull/11805#discussion_r949871644
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/PushDownNotSlotReferenceExpressionOfOnClause.java: ########## @@ -0,0 +1,200 @@ +// 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.logical; + +import org.apache.doris.nereids.rules.Rule; +import org.apache.doris.nereids.rules.RuleType; +import org.apache.doris.nereids.rules.rewrite.OneRewriteRuleFactory; +import org.apache.doris.nereids.trees.expressions.Alias; +import org.apache.doris.nereids.trees.expressions.Arithmetic; +import org.apache.doris.nereids.trees.expressions.ComparisonPredicate; +import org.apache.doris.nereids.trees.expressions.CompoundPredicate; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.Literal; +import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.SlotReference; +import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; +import org.apache.doris.nereids.trees.plans.GroupPlan; +import org.apache.doris.nereids.trees.plans.Plan; +import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; +import org.apache.doris.nereids.trees.plans.logical.LogicalProject; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * push down expression which is not slot reference + */ +public class PushDownNotSlotReferenceExpressionOfOnClause extends OneRewriteRuleFactory { + + private static class ListBuilder<T> { + List<T> list; + + public ListBuilder(List<T> list) { + this.list = Lists.newArrayList(list); + } + + public ListBuilder<T> addAll(List<T> element) { + list.addAll(Lists.newArrayList(element)); + return this; + } + + public List<T> get() { + return list; + } + } + + private final Map<SlotReference, Map<Expression, Expression>> exprMap = new HashMap<>(); + + /** + * rewrite example: + *join(t1.a + 1 = t2.b + 2 and t1.a > 2) join(c = d and c > 2) + * │ │ + * ├─olapScan(t1) ├────project(t1.a + 1 as c) + * │ ====> │ │ + * └─olapScan(t2) │ └─olapScan(t1) + * │ + * └────project(t2.b + 2 as d) + * │ + * └─olapScan(t2) + */ + @Override + public Rule build() { + return logicalJoin() + .when(join -> join.getCondition().isPresent() Review Comment: This rule is not applicable to all join types. for example, we cannot push on predicate of left outer join down. So we have to take join type into consideration. ########## fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/batch/PushDownNotSlotReferenceExpressionOfOnClauseJob.java: ########## @@ -0,0 +1,41 @@ +// 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.jobs.batch; + +import org.apache.doris.nereids.CascadesContext; +import org.apache.doris.nereids.rules.rewrite.logical.PushDownNotSlotReferenceExpressionOfOnClause; + +import com.google.common.collect.ImmutableList; + +/** + * push down not slot reference expression job + */ +public class PushDownNotSlotReferenceExpressionOfOnClauseJob extends BatchRulesJob { Review Comment: The class name is not quite meaningful. Here we want to push predicates like `t1.A=1`, but there is a SlotReference `t1.A`. How about "SingleSidePredicate" since all slots comes from one side of this join. -- 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