From ca4f91da640fe20588b70fea3f5137b889c5a6b8 Mon Sep 17 00:00:00 2001 From: "liming.1018" Date: Mon, 20 Nov 2023 20:23:18 +0800 Subject: [PATCH] [common] MultiplePartitionPredicate uses all partition fields for filtering. --- .../paimon/partition/PartitionPredicate.java | 6 +-- .../partition/PartitionPredicateTest.java | 50 +++++++++++++------ 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/paimon-core/src/main/java/org/apache/paimon/partition/PartitionPredicate.java b/paimon-core/src/main/java/org/apache/paimon/partition/PartitionPredicate.java index 687eac1fc9e56..0a9b5df97ae55 100644 --- a/paimon-core/src/main/java/org/apache/paimon/partition/PartitionPredicate.java +++ b/paimon-core/src/main/java/org/apache/paimon/partition/PartitionPredicate.java @@ -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; } } } diff --git a/paimon-core/src/test/java/org/apache/paimon/partition/PartitionPredicateTest.java b/paimon-core/src/test/java/org/apache/paimon/partition/PartitionPredicateTest.java index 71c46fb3886f6..78ee1377f36b0 100644 --- a/paimon-core/src/test/java/org/apache/paimon/partition/PartitionPredicateTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/partition/PartitionPredicateTest.java @@ -62,27 +62,27 @@ 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) @@ -90,14 +90,14 @@ public void testPartition() { .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) @@ -105,14 +105,14 @@ public void testPartition() { .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) @@ -120,14 +120,36 @@ public void testPartition() { .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); }