jackwener commented on code in PR #13756: URL: https://github.com/apache/doris/pull/13756#discussion_r1009336239
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTransposeProject.java: ########## @@ -0,0 +1,99 @@ +// 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.exploration.join; + +import org.apache.doris.common.Pair; +import org.apache.doris.nereids.rules.Rule; +import org.apache.doris.nereids.rules.RuleType; +import org.apache.doris.nereids.rules.exploration.OneExplorationRuleFactory; +import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.Slot; +import org.apache.doris.nereids.trees.plans.GroupPlan; +import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; +import org.apache.doris.nereids.trees.plans.logical.LogicalProject; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * rule for semi-semi transpose + */ +public class SemiJoinSemiJoinTransposeProject extends OneExplorationRuleFactory { + public static final SemiJoinSemiJoinTransposeProject INSTANCE = new SemiJoinSemiJoinTransposeProject(); + + /* + * topSemi newTopSemi + * / \ / \ + * abProject C acProject B + * / ──► / + * bottomSemi newBottomSemi + * / \ / \ + * A B A C + */ + @Override + public Rule build() { + return logicalJoin(logicalProject(logicalJoin()), group()) + .when(this::typeChecker) + .when(topSemi -> InnerJoinLAsscom.checkReorder(topSemi, topSemi.left().child())) + .then(topSemi -> { + LogicalJoin<GroupPlan, GroupPlan> bottomSemi = topSemi.left().child(); + LogicalProject abProject = topSemi.left(); + GroupPlan a = bottomSemi.left(); + GroupPlan b = bottomSemi.right(); + GroupPlan c = topSemi.right(); + Set<Slot> aOutputSet = a.getOutputSet(); + Set<NamedExpression> acProjects = new HashSet<NamedExpression>(abProject.getProjects()); + + bottomSemi.getHashJoinConjuncts().stream().forEach( + expression -> { + expression.getInputSlots().stream().forEach( + slot -> { + if (aOutputSet.contains(slot)) { + acProjects.add(slot); + } + }); + } + ); + LogicalJoin newBottomSemi = new LogicalJoin(topSemi.getJoinType(), topSemi.getHashJoinConjuncts(), + topSemi.getOtherJoinConjuncts(), a, c, + bottomSemi.getJoinReorderContext()); + newBottomSemi.getJoinReorderContext().setHasCommute(false); + newBottomSemi.getJoinReorderContext().setHasLAsscom(false); Review Comment: mask check don't need set. -- 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