Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix](nereids) fix partition_prune or expression evaluate wrongly #38897

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading