Skip to content

Commit

Permalink
handle not
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Nov 15, 2023
1 parent cdc5626 commit b219bf3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,13 @@ public EvaluateRangeResult visitEqualTo(EqualTo equalTo, EvaluateRangeInput cont
if (!(result.result instanceof EqualTo)) {
return result;
}
equalTo = (EqualTo) result.result;

boolean changed = false;
if (!equalTo.equals(result.result)) {
changed = true;
}

equalTo = (EqualTo) result.result;
if (equalTo.left() instanceof Slot && equalTo.right() instanceof Literal) {
Slot slot = (Slot) equalTo.left();
if (isPartitionSlot(slot)) {
Expand All @@ -361,6 +367,11 @@ public EvaluateRangeResult visitEqualTo(EqualTo equalTo, EvaluateRangeInput cont
ColumnRange atMostRange = ColumnRange.singleton((Literal) equalTo.left());
result = intersectSlotRange(result, rightColumnRanges, slot, atMostRange);
}
} else {
result.setDetermined(false);
}
if (changed) {
result.setDetermined(false);
}
return result;
}
Expand All @@ -383,6 +394,7 @@ public EvaluateRangeResult visitInPredicate(InPredicate inPredicate, EvaluateRan
Map<Slot, ColumnRange> slotRanges = result.childrenResult.get(0).columnRanges;
result = intersectSlotRange(result, slotRanges, slot, unionLiteralRange);
}
result.setDetermined(false);
return result;
}

Expand All @@ -392,7 +404,7 @@ public EvaluateRangeResult visitIsNull(IsNull isNull, EvaluateRangeInput context
if (!(result.result instanceof IsNull)) {
return result;
}

result.setDetermined(false);
Expression child = isNull.child();
if (!(child instanceof Slot) || !isPartitionSlot((Slot) child)) {
return result;
Expand Down Expand Up @@ -434,12 +446,13 @@ public EvaluateRangeResult visitOr(Or or, EvaluateRangeInput context) {
@Override
public EvaluateRangeResult visitNot(Not not, EvaluateRangeInput context) {
EvaluateRangeResult result = evaluateChildrenThenThis(not, context);

Map<Slot, ColumnRange> newRanges = result.childrenResult.get(0).columnRanges.entrySet()
.stream()
.map(slotToRange -> Pair.of(slotToRange.getKey(), slotToRange.getValue().complete()))
.collect(ImmutableMap.toImmutableMap(Pair::key, Pair::value));
result = new EvaluateRangeResult(result.result, newRanges, result.childrenResult);
if (result.isDetermined()) {
Map<Slot, ColumnRange> newRanges = result.childrenResult.get(0).columnRanges.entrySet()
.stream()
.map(slotToRange -> Pair.of(slotToRange.getKey(), slotToRange.getValue().complete()))
.collect(ImmutableMap.toImmutableMap(Pair::key, Pair::value));
result = new EvaluateRangeResult(result.result, newRanges, result.childrenResult);
}
return returnFalseIfExistEmptyRange(result);
}

Expand Down Expand Up @@ -662,11 +675,22 @@ public static class EvaluateRangeResult {
private final Map<Slot, ColumnRange> columnRanges;
private final List<EvaluateRangeResult> childrenResult;

public boolean isDetermined() {
return isDetermined;
}

private final boolean isDetermined;

public EvaluateRangeResult(Expression result, Map<Slot, ColumnRange> columnRanges,
List<EvaluateRangeResult> childrenResult) {
this.result = result;
this.columnRanges = columnRanges;
this.childrenResult = childrenResult;
this.isDetermined = childrenResult.stream().allMatch(r -> r.isDetermined());
}

public EvaluateRangeResult withDetermined(boolean determined) {

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ suite("test_multi_range_partition") {
contains "artitions=3/3 (p1,p2,p3)"
}

// BUG: p1 missed
// fix BUG: p1 missed
explain{
sql "select * from pt where sin(k1)<>0"
contains "partitions=2/3 (p2,p3)"
contains "partitions=3/3 (p1,p2,p3)"
}

// ============= in predicate ======================
Expand All @@ -98,10 +98,10 @@ suite("test_multi_range_partition") {
contains "partitions=1/3 (p1)"
}

// BUG: p1 missed
// fix BUG: p1 missed
explain{
sql "select * from pt where k1 is not null"
contains "partitions=2/3 (p2,p3)"
contains "partitions=3/3 (p1,p2,p3)"
}

//======== the second partition key =========
Expand All @@ -126,10 +126,10 @@ suite("test_multi_range_partition") {
contains "partitions=1/3 (p2)"
}

//BUG: p2 missed
//fix BUG: p2 missed
explain {
sql "select * from pt where k1=7 and k1<>k2"
contains "partitions=1/3 (p3)"
contains "partitions=2/3 (p2,p3)"
}

//p3 NOT pruned
Expand All @@ -138,10 +138,10 @@ suite("test_multi_range_partition") {
contains "partitions=2/3 (p2,p3)"
}

//BUG: p2 missed
//fix BUG: p2 missed
explain {
sql "select * from pt where k1=7 and not (k2 is null);"
contains "VEMPTYSET"
contains "partitions=2/3 (p2,p3)"
}

//p3 NOT pruned
Expand All @@ -150,21 +150,21 @@ suite("test_multi_range_partition") {
contains "partitions=2/3 (p2,p3)"
}

//BUG: p2 missed
//fix BUG: p2 missed
explain {
sql "select * from pt where k1=7 and k2 not in (1, 2);"
contains "partitions=1/3 (p3)"
contains "partitions=2/3 (p2,p3)"
}

explain {
sql "select * from pt where k1=7 and k2 in (1, 12);"
contains "partitions=2/3 (p2,p3)"
}

//BUG: p2,p3 pruned
//fix BUG: p2,p3 pruned
explain {
sql "select * from pt where k1=7 and k2 not in (1, 12)"
contains "VEMPTYSET"
contains "partitions=2/3 (p2,p3)"
}

explain {
Expand Down

0 comments on commit b219bf3

Please sign in to comment.