Skip to content

Commit

Permalink
fix logical join uniform properties problem
Browse files Browse the repository at this point in the history
  • Loading branch information
feiniaofeiafei committed Nov 13, 2024
1 parent 2b6fcdd commit 892b7ec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,10 @@ public void replace(Map<Slot, Slot> replaceMap) {
slotUniformValue = newSlotUniformValue;
}

// The current implementation logic is: if a slot key exists in map slotUniformValue,
// its value is present and is not nullable,
// or if a slot key exists in map slotUniformValue and the slot is not nullable
// it indicates that this slot is uniform and not null.
public boolean isUniformAndNotNull(Slot slot) {
return slotUniformValue.containsKey(slot)
&& (!slot.nullable() || slotUniformValue.get(slot).isPresent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,13 @@ public void computeUniform(Builder builder) {
// TODO disable function dependence calculation for mark join, but need re-think this in future.
return;
}
if (!joinType.isLeftSemiOrAntiJoin()) {
// outer join cant have nullable side uniform properties
// (e.g. left join may produce null in right side, the uniform value is present and not null
// cannot deduce the slot is uniform and not null)
if (!joinType.isLeftJoin()) {
builder.addUniformSlot(right().getLogicalProperties().getTrait());
}
if (!joinType.isRightSemiOrAntiJoin()) {
if (!joinType.isRightJoin()) {
builder.addUniformSlot(left().getLogicalProperties().getTrait());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void testProjectAlias() {
.rewrite()
.printlnTree()
.matches(logicalAggregate().when(agg ->
agg.getGroupByExpressions().size() == 2));
agg.getGroupByExpressions().size() == 1));
PlanChecker.from(connectContext)
.analyze("select id as c, name as n from t1 group by name, id")
.rewrite()
Expand All @@ -123,7 +123,7 @@ void testProjectAlias() {
.rewrite()
.printlnTree()
.matches(logicalAggregate().when(agg ->
agg.getGroupByExpressions().size() == 2));
agg.getGroupByExpressions().size() == 1));
}

@Test
Expand Down

0 comments on commit 892b7ec

Please sign in to comment.