Skip to content

Commit

Permalink
[Fix](nereids) fix partition_prune or expression evaluate wrongly (#3…
Browse files Browse the repository at this point in the history
…8897)

introduced by #38025
Or expression evaluate wrongly in #38025. For example, partition column
is a, b, predicate is a=a or b>1 , partition column range is min<a<5, b
is infinite. The evaluate result of or expression should be b is
infinite(because when a is not null, a=a is true, there is no restrict
for b, e.g. a=1, b=0 satisfy a=a or b>1). #38025 pr has wrongly evaluate
result b >1
  • Loading branch information
feiniaofeiafei authored Aug 6, 2024
1 parent 6dfd543 commit 556c2fb
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,8 @@ public EvaluateRangeResult visitIsNull(IsNull isNull, EvaluateRangeInput context
@Override
public EvaluateRangeResult visitAnd(And and, EvaluateRangeInput context) {
EvaluateRangeResult result = evaluateChildrenThenThis(and, context);

result = mergeRanges(result.result, result.childrenResult.get(0), result.childrenResult.get(1),
(leftRange, rightRange) -> {
if (leftRange == null) {
return rightRange;
}
if (rightRange == null) {
return leftRange;
}
return leftRange.intersect(rightRange);
});
(leftRange, rightRange) -> leftRange.intersect(rightRange));

result = returnFalseIfExistEmptyRange(result);
if (result.result.equals(BooleanLiteral.FALSE)) {
Expand All @@ -435,18 +426,20 @@ public EvaluateRangeResult visitAnd(And and, EvaluateRangeInput context) {
@Override
public EvaluateRangeResult visitOr(Or or, EvaluateRangeInput context) {
EvaluateRangeResult result = evaluateChildrenThenThis(or, context);

if (result.result.equals(BooleanLiteral.FALSE)) {
return result;
} else if (result.childrenResult.get(0).result.equals(BooleanLiteral.FALSE)) {
// false or a<1 -> return range a<1
return new EvaluateRangeResult(result.result, result.childrenResult.get(1).columnRanges,
result.childrenResult);
} else if (result.childrenResult.get(1).result.equals(BooleanLiteral.FALSE)) {
// a<1 or false -> return range a<1
return new EvaluateRangeResult(result.result, result.childrenResult.get(0).columnRanges,
result.childrenResult);
}
result = mergeRanges(result.result, result.childrenResult.get(0), result.childrenResult.get(1),
(leftRange, rightRange) -> {
if (leftRange == null) {
return rightRange;
}
if (rightRange == null) {
return leftRange;
}
return leftRange.union(rightRange);
});
return removeEmptyRange(result);
(leftRange, rightRange) -> leftRange.union(rightRange));
return returnFalseIfExistEmptyRange(result);
}

@Override
Expand Down Expand Up @@ -596,7 +589,9 @@ private EvaluateRangeResult mergeRanges(
.build();

Map<Expression, ColumnRange> mergedRange = exprs.stream()
.map(expr -> Pair.of(expr, mergeFunction.apply(leftRanges.get(expr), rightRanges.get(expr))))
.map(expr -> Pair.of(expr, mergeFunction.apply(
leftRanges.containsKey(expr) ? leftRanges.get(expr) : rangeMap.get(expr),
rightRanges.containsKey(expr) ? rightRanges.get(expr) : rangeMap.get(expr))))
.collect(ImmutableMap.toImmutableMap(Pair::key, Pair::value));
return new EvaluateRangeResult(originResult, mergedRange, ImmutableList.of(left, right));
}
Expand Down Expand Up @@ -821,17 +816,6 @@ private List<Map<Slot, PartitionSlotInput>> commonComputeOnePartitionInputs() {
return onePartitionInputs;
}

private EvaluateRangeResult removeEmptyRange(EvaluateRangeResult result) {
ImmutableMap.Builder<Expression, ColumnRange> builder = ImmutableMap.builder();
for (Map.Entry<Expression, ColumnRange> entry : result.columnRanges.entrySet()) {
if (entry.getValue().isEmptyRange()) {
continue;
}
builder.put(entry);
}
return new EvaluateRangeResult(result.result, builder.build(), result.childrenResult);
}

private EvaluateRangeResult computeMonotonicFunctionRange(EvaluateRangeResult result) {
Monotonic func = (Monotonic) result.result;
if (rangeMap.containsKey(func)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !or_evaluate --
0
3
5
6
7
8
9

Loading

0 comments on commit 556c2fb

Please sign in to comment.