Skip to content

Commit

Permalink
[BugFix] Fix union isnullable error (#32426)
Browse files Browse the repository at this point in the history
Signed-off-by: Seaven <[email protected]>
(cherry picked from commit c39da42)
  • Loading branch information
Seaven authored and wanpengfei-git committed Oct 11, 2023
1 parent 6a13b59 commit 92bd7cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2578,9 +2578,16 @@ private PlanFragment buildSetOperation(OptExpression optExpr, ExecPlan context,
// reset column is nullable, for handle union select xx join select xxx...
setOperationNode.setHasNullableGenerateChild();
List<Expr> setOutputList = Lists.newArrayList();
for (ColumnRefOperator columnRefOperator : setOperation.getOutputColumnRefOp()) {
for (int index = 0; index < setOperation.getOutputColumnRefOp().size(); index++) {
ColumnRefOperator columnRefOperator = setOperation.getOutputColumnRefOp().get(index);
SlotDescriptor slotDesc = context.getDescTbl().getSlotDesc(new SlotId(columnRefOperator.getId()));
slotDesc.setIsNullable(slotDesc.getIsNullable() | setOperationNode.isHasNullableGenerateChild());
boolean isNullable = slotDesc.getIsNullable() | setOperationNode.isHasNullableGenerateChild();
for (List<ColumnRefOperator> childOutputColumn : setOperation.getChildOutputColumns()) {
ColumnRefOperator childRef = childOutputColumn.get(index);
Expr childExpr = ScalarOperatorToExpr.buildExecExpression(childRef, formatterContext);
isNullable |= childExpr.isNullable();
}
slotDesc.setIsNullable(isNullable);
setOutputList.add(new SlotRef(String.valueOf(columnRefOperator.getId()), slotDesc));
}
setOperationTuple.computeMemLayout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,20 @@ public void testOther() throws Exception {
" | \n" +
" 1:EMPTYSET");
}

@Test
public void testUnionSlot() throws Exception {
String sql = "select L_ORDERKEY " +
"from t0 left outer join lineitem_partition on L_ORDERKEY = t0.v2 and L_SHIPDATE = '2000-01-01' " +
"union all " +
"select L_ORDERKEY " +
"from t0 left outer join lineitem_partition on L_ORDERKEY = t0.v2 and L_SHIPDATE = '2000-01-01' ";
String plan = getVerboseExplain(sql);
assertContains(plan, " 0:UNION\n" +
" | output exprs:\n" +
" | [41, INT, true]\n" +
" | child exprs:\n" +
" | [4: L_ORDERKEY, INT, true]\n" +
" | [24: L_ORDERKEY, INT, true]");
}
}

0 comments on commit 92bd7cd

Please sign in to comment.