Skip to content

Commit

Permalink
[common] MultiplePartitionPredicate uses all partition fields for fil…
Browse files Browse the repository at this point in the history
…tering.
  • Loading branch information
liming30 committed Nov 20, 2023
1 parent 7eda88c commit ca4f91d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ public boolean test(long rowCount, FieldStats[] fieldStats) {
}

for (int i = 0; i < fieldStats.length; i++) {
if (min[i].test(rowCount, fieldStats) && max[i].test(rowCount, fieldStats)) {
return true;
if (!min[i].test(rowCount, fieldStats) || !max[i].test(rowCount, fieldStats)) {
return false;
}
}
return false;
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,72 +62,94 @@ public void testPartition() {
PartitionPredicate.fromMultiple(
type, Arrays.asList(createPart(3, 5), createPart(4, 6)));

assertThat(vailidate(p1, p2, createPart(3, 4))).isFalse();
assertThat(vailidate(p1, p2, createPart(3, 5))).isTrue();
assertThat(vailidate(p1, p2, createPart(4, 6))).isTrue();
assertThat(vailidate(p1, p2, createPart(4, 5))).isFalse();
assertThat(validate(p1, p2, createPart(3, 4))).isFalse();
assertThat(validate(p1, p2, createPart(3, 5))).isTrue();
assertThat(validate(p1, p2, createPart(4, 6))).isTrue();
assertThat(validate(p1, p2, createPart(4, 5))).isFalse();

assertThat(
vailidate(
validate(
p1,
new FieldStats[] {
new FieldStats(4, 8, 0L), new FieldStats(10, 12, 0L)
}))
.isFalse();
assertThat(
vailidate(
validate(
p2,
new FieldStats[] {
new FieldStats(4, 8, 0L), new FieldStats(10, 12, 0L)
}))
.isTrue();
.isFalse();
assertThat(
vailidate(
validate(
p2,
new FieldStats[] {
new FieldStats(6, 8, 0L), new FieldStats(10, 12, 0L)
}))
.isFalse();

assertThat(
vailidate(
validate(
p1,
new FieldStats[] {
new FieldStats(4, 8, 0L), new FieldStats(5, 12, 0L)
}))
.isTrue();
assertThat(
vailidate(
validate(
p2,
new FieldStats[] {
new FieldStats(4, 8, 0L), new FieldStats(5, 12, 0L)
}))
.isTrue();

assertThat(
vailidate(
validate(
p1,
new FieldStats[] {
new FieldStats(1, 2, 0L), new FieldStats(2, 3, 0L)
}))
.isFalse();
assertThat(
vailidate(
validate(
p2,
new FieldStats[] {
new FieldStats(1, 2, 0L), new FieldStats(2, 3, 0L)
}))
.isFalse();
}

private boolean vailidate(
@Test
public void testPartitionWithMultiFields() {
RowType type = DataTypes.ROW(DataTypes.INT(), DataTypes.INT());
PartitionPredicate predicate =
PartitionPredicate.fromMultiple(type, Collections.singletonList(createPart(3, 4)));

assertThat(
validate(
predicate,
new FieldStats[] {
new FieldStats(2, 2, 0L), new FieldStats(4, 4, 0L)
}))
.isFalse();
assertThat(
validate(
predicate,
new FieldStats[] {
new FieldStats(2, 4, 0L), new FieldStats(4, 4, 0L)
}))
.isTrue();
}

private boolean validate(
PartitionPredicate predicate1, PartitionPredicate predicate2, BinaryRow part) {
boolean ret = predicate1.test(part);
assertThat(predicate2.test(part)).isEqualTo(ret);
return ret;
}

private boolean vailidate(PartitionPredicate predicate, FieldStats[] fieldStats) {
private boolean validate(PartitionPredicate predicate, FieldStats[] fieldStats) {
return predicate.test(3, fieldStats);
}

Expand Down

0 comments on commit ca4f91d

Please sign in to comment.