924060929 commented on code in PR #12130: URL: https://github.com/apache/doris/pull/12130#discussion_r956860931
########## fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java: ########## @@ -363,32 +367,48 @@ public PlanFragment visitPhysicalHashJoin(PhysicalHashJoin<Plan, Plan> hashJoin, // NOTICE: We must visit from right to left, to ensure the last fragment is root fragment PlanFragment rightFragment = hashJoin.child(1).accept(this, context); PlanFragment leftFragment = hashJoin.child(0).accept(this, context); - PlanNode leftFragmentPlanRoot = leftFragment.getPlanRoot(); - PlanNode rightFragmentPlanRoot = rightFragment.getPlanRoot(); - JoinType joinType = hashJoin.getJoinType(); if (JoinUtils.shouldNestedLoopJoin(hashJoin)) { throw new RuntimeException("Physical hash join could not execute without equal join condition."); } - List<Expr> execEqConjunctList = hashJoin.getHashJoinConjuncts().stream() + PlanNode leftPlanRoot = leftFragment.getPlanRoot(); + PlanNode rightPlanRoot = rightFragment.getPlanRoot(); + JoinType joinType = hashJoin.getJoinType(); + + List<Expr> execEqConjuncts = hashJoin.getHashJoinConjuncts().stream() .map(EqualTo.class::cast) .map(e -> swapEqualToForChildrenOrder(e, hashJoin.left().getOutput())) .map(e -> ExpressionTranslator.translate(e, context)) .collect(Collectors.toList()); + + // in Nereids, all node only has one TupleDescriptor, so we can use the first one. + TupleDescriptor leftTuple = context.getTupleDesc(leftPlanRoot.getTupleIds().get(0)); + TupleDescriptor rightTuple = context.getTupleDesc(rightPlanRoot.getTupleIds().get(0)); + + // Nereids does not care about output order of join, + // but BE need left child's output must be before right child's output. + // So we need to swap the output order of left and right child if necessary. + // TODO: revert this after Nereids could ensure the output order is correct. TupleDescriptor outputDescriptor = context.generateTupleDesc(); - List<Expr> srcToOutput = hashJoin.getOutput().stream() + Map<ExprId, SlotReference> slotReferenceMap = Maps.newHashMap(); + hashJoin.getOutput().stream() .map(SlotReference.class::cast) + .forEach(s -> slotReferenceMap.put(s.getExprId(), s)); + List<Expr> srcToOutput = Stream.concat(leftTuple.getSlots().stream(), rightTuple.getSlots().stream()) Review Comment: if there is only one TupleDescriptor, you no need to concat slots ########## fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java: ########## @@ -363,32 +367,48 @@ public PlanFragment visitPhysicalHashJoin(PhysicalHashJoin<Plan, Plan> hashJoin, // NOTICE: We must visit from right to left, to ensure the last fragment is root fragment PlanFragment rightFragment = hashJoin.child(1).accept(this, context); PlanFragment leftFragment = hashJoin.child(0).accept(this, context); - PlanNode leftFragmentPlanRoot = leftFragment.getPlanRoot(); - PlanNode rightFragmentPlanRoot = rightFragment.getPlanRoot(); - JoinType joinType = hashJoin.getJoinType(); if (JoinUtils.shouldNestedLoopJoin(hashJoin)) { throw new RuntimeException("Physical hash join could not execute without equal join condition."); } - List<Expr> execEqConjunctList = hashJoin.getHashJoinConjuncts().stream() + PlanNode leftPlanRoot = leftFragment.getPlanRoot(); + PlanNode rightPlanRoot = rightFragment.getPlanRoot(); + JoinType joinType = hashJoin.getJoinType(); + + List<Expr> execEqConjuncts = hashJoin.getHashJoinConjuncts().stream() .map(EqualTo.class::cast) .map(e -> swapEqualToForChildrenOrder(e, hashJoin.left().getOutput())) .map(e -> ExpressionTranslator.translate(e, context)) .collect(Collectors.toList()); + + // in Nereids, all node only has one TupleDescriptor, so we can use the first one. + TupleDescriptor leftTuple = context.getTupleDesc(leftPlanRoot.getTupleIds().get(0)); + TupleDescriptor rightTuple = context.getTupleDesc(rightPlanRoot.getTupleIds().get(0)); Review Comment: If Nereids only has one TupleDescriptor, we should hide the tupleId in the context, or else people who add new translate method maybe misuse? So I suggest ```java TupleDescriptor joinTuple = context.getTupleDesc(); ``` -- 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