@@ -646,14 +646,10 @@ public PlanFragment visitAbstractPhysicalSort(
646646 outputList .forEach (k -> {
647647 sortTupleOutputList .add (ExpressionTranslator .translate (k , context ));
648648 });
649- // 2. Generate new Tuple
650- TupleDescriptor tupleDesc = generateTupleDesc (outputList , orderKeyList , context , null );
651- // 3. Get current slotRef
649+ // 2. Generate new Tuple and get current slotRef for newOrderingExprList
652650 List <Expr > newOrderingExprList = Lists .newArrayList ();
653- orderKeyList .forEach (k -> {
654- newOrderingExprList .add (ExpressionTranslator .translate (k .getExpr (), context ));
655- });
656- // 4. fill in SortInfo members
651+ TupleDescriptor tupleDesc = generateTupleDesc (outputList , orderKeyList , newOrderingExprList , context , null );
652+ // 3. fill in SortInfo members
657653 SortInfo sortInfo = new SortInfo (newOrderingExprList , ascOrderList , nullsFirstParamList , tupleDesc );
658654 PlanNode childNode = childFragment .getPlanRoot ();
659655 SortNode sortNode = new SortNode (context .nextPlanNodeId (), childNode , sortInfo , true );
@@ -1445,6 +1441,7 @@ private TupleDescriptor generateTupleDesc(List<Slot> slotList, TableIf table, Pl
14451441 }
14461442
14471443 private TupleDescriptor generateTupleDesc (List <Slot > slotList , List <OrderKey > orderKeyList ,
1444+ List <Expr > newOrderingExprList ,
14481445 PlanTranslatorContext context , Table table ) {
14491446 TupleDescriptor tupleDescriptor = context .generateTupleDesc ();
14501447 Set <ExprId > alreadyExists = Sets .newHashSet ();
@@ -1458,9 +1455,11 @@ private TupleDescriptor generateTupleDesc(List<Slot> slotList, List<OrderKey> or
14581455 }
14591456 // TODO: trick here, we need semanticEquals to remove redundant expression
14601457 if (alreadyExists .contains (slotReference .getExprId ())) {
1458+ newOrderingExprList .add (context .findSlotRef (slotReference .getExprId ()));
14611459 continue ;
14621460 }
14631461 context .createSlotDesc (tupleDescriptor , slotReference );
1462+ newOrderingExprList .add (context .findSlotRef (slotReference .getExprId ()));
14641463 alreadyExists .add (slotReference .getExprId ());
14651464 }
14661465 for (Slot slot : slotList ) {
0 commit comments