This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new c7d8a6d678 [common] Skip transform predicates when extracting system
table filters (#11004)
c7d8a6d678 is described below
commit c7d8a6d6782f5d9f1ee8bd0b7c7942378e2dd076
Author: chenjian2664 <[email protected]>
AuthorDate: Fri Nov 13 18:56:54 2026 +0800
[common] Skip transform predicates when extracting system table filters
(#11004)
---
.../paimon/predicate/LeafPredicateExtractor.java | 30 ++++++++++++---
.../apache/paimon/table/system/BucketsTable.java | 15 +++++++-
.../apache/paimon/table/system/ConsumersTable.java | 7 ++++
.../paimon/table/system/FileKeyRangesTable.java | 16 +-------
.../org/apache/paimon/table/system/FilesTable.java | 41 ++++++++++++++------
.../apache/paimon/table/system/ManifestsTable.java | 5 +++
.../apache/paimon/table/system/SchemasTable.java | 5 +++
.../apache/paimon/table/system/SnapshotsTable.java | 7 ++++
.../paimon/table/system/BucketsTableTest.java | 44 +++++++++++++++++++++-
.../paimon/table/system/ConsumersTableTest.java | 19 ++++++++++
.../table/system/FileKeyRangesTableTest.java | 19 ++++++++++
.../apache/paimon/table/system/FilesTableTest.java | 17 +++++++++
.../paimon/table/system/SnapshotsTableTest.java | 39 +++++++++++++++++++
.../apache/paimon/table/system/TagsTableTest.java | 21 +++++++++++
14 files changed, 250 insertions(+), 35 deletions(-)
diff --git
a/paimon-common/src/main/java/org/apache/paimon/predicate/LeafPredicateExtractor.java
b/paimon-common/src/main/java/org/apache/paimon/predicate/LeafPredicateExtractor.java
index 667c8f636c..54818b5e63 100644
---
a/paimon-common/src/main/java/org/apache/paimon/predicate/LeafPredicateExtractor.java
+++
b/paimon-common/src/main/java/org/apache/paimon/predicate/LeafPredicateExtractor.java
@@ -18,10 +18,11 @@
package org.apache.paimon.predicate;
+import javax.annotation.Nullable;
+
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.Optional;
/** Extract leaf predicate for field names. */
public class LeafPredicateExtractor implements PredicateVisitor<Map<String,
LeafPredicate>> {
@@ -30,11 +31,11 @@ public class LeafPredicateExtractor implements
PredicateVisitor<Map<String, Leaf
@Override
public Map<String, LeafPredicate> visit(LeafPredicate predicate) {
- Optional<FieldRef> fieldRefOptional = predicate.fieldRefOptional();
- if (!fieldRefOptional.isPresent()) {
- throw new UnsupportedOperationException();
- }
- return Collections.singletonMap(fieldRefOptional.get().name(),
predicate);
+ // A leaf on a transform such as UPPER(name) does not constrain the
field itself.
+ return predicate
+ .fieldRefOptional()
+ .map(fieldRef -> Collections.singletonMap(fieldRef.name(),
predicate))
+ .orElse(Collections.emptyMap());
}
@Override
@@ -46,4 +47,21 @@ public class LeafPredicateExtractor implements
PredicateVisitor<Map<String, Leaf
}
return Collections.emptyMap();
}
+
+ /**
+ * Returns the complete predicate when it contains a transform leaf, which
this extractor skips,
+ * so that callers evaluate every condition on rows; returns null
otherwise.
+ */
+ @Nullable
+ public static Predicate rowFilterForTransforms(@Nullable Predicate
predicate) {
+ return predicate != null && containsTransform(predicate) ? predicate :
null;
+ }
+
+ private static boolean containsTransform(Predicate predicate) {
+ if (predicate instanceof CompoundPredicate) {
+ return ((CompoundPredicate) predicate)
+
.children().stream().anyMatch(LeafPredicateExtractor::containsTransform);
+ }
+ return !((LeafPredicate) predicate).fieldRefOptional().isPresent();
+ }
}
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/system/BucketsTable.java
b/paimon-core/src/main/java/org/apache/paimon/table/system/BucketsTable.java
index e5c419f515..424e51a1e5 100644
--- a/paimon-core/src/main/java/org/apache/paimon/table/system/BucketsTable.java
+++ b/paimon-core/src/main/java/org/apache/paimon/table/system/BucketsTable.java
@@ -30,6 +30,7 @@ import org.apache.paimon.manifest.BucketEntry;
import org.apache.paimon.predicate.LeafPredicate;
import org.apache.paimon.predicate.LeafPredicateExtractor;
import org.apache.paimon.predicate.Predicate;
+import org.apache.paimon.predicate.PredicateBuilder;
import org.apache.paimon.reader.RecordReader;
import org.apache.paimon.table.FileStoreTable;
import org.apache.paimon.table.ReadonlyTable;
@@ -196,13 +197,21 @@ public class BucketsTable implements ReadonlyTable {
private RowType readType;
+ @Nullable private Predicate predicate;
+
public BucketsRead(FileStoreTable table) {
this.fileStoreTable = table;
}
@Override
public InnerTableRead withFilter(Predicate predicate) {
- // filter pushdown is handled at the Scan layer through
BucketsSplit
+ if (predicate == null) {
+ this.predicate = null;
+ return this;
+ }
+ // The scan applies plain partition and bucket leaves; evaluate
the rest on the rows.
+ List<Predicate> remaining =
FilesTable.scanResidualPredicates(predicate);
+ this.predicate = remaining.isEmpty() ? null :
PredicateBuilder.and(remaining);
return this;
}
@@ -262,6 +271,10 @@ public class BucketsTable implements ReadonlyTable {
.thenComparing(row ->
row.getInt(1)))
.iterator();
+ if (predicate != null) {
+ iterator = Iterators.filter(iterator, predicate::test);
+ }
+
if (readType != null) {
iterator =
Iterators.transform(
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/system/ConsumersTable.java
b/paimon-core/src/main/java/org/apache/paimon/table/system/ConsumersTable.java
index 7865ff37a3..f575e1606d 100644
---
a/paimon-core/src/main/java/org/apache/paimon/table/system/ConsumersTable.java
+++
b/paimon-core/src/main/java/org/apache/paimon/table/system/ConsumersTable.java
@@ -53,6 +53,8 @@ import org.apache.paimon.utils.SerializationUtils;
import org.apache.paimon.shade.guava30.com.google.common.collect.Iterators;
+import javax.annotation.Nullable;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -180,6 +182,7 @@ public class ConsumersTable implements ReadonlyTable {
private final FileIO fileIO;
private RowType readType;
+ @Nullable private Predicate rowFilter;
private final List<String> consumerIds = new ArrayList<>();
public ConsumersRead(FileIO fileIO) {
@@ -188,6 +191,7 @@ public class ConsumersTable implements ReadonlyTable {
@Override
public InnerTableRead withFilter(Predicate predicate) {
+ this.rowFilter =
LeafPredicateExtractor.rowFilterForTransforms(predicate);
if (predicate == null) {
return this;
}
@@ -255,6 +259,9 @@ public class ConsumersTable implements ReadonlyTable {
}
Iterator<InternalRow> rows =
Iterators.transform(consumers.entrySet().iterator(),
this::toRow);
+ if (rowFilter != null) {
+ rows = Iterators.filter(rows, rowFilter::test);
+ }
if (readType != null) {
rows =
Iterators.transform(
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/system/FileKeyRangesTable.java
b/paimon-core/src/main/java/org/apache/paimon/table/system/FileKeyRangesTable.java
index 39e88f6e9a..5d741f29f2 100644
---
a/paimon-core/src/main/java/org/apache/paimon/table/system/FileKeyRangesTable.java
+++
b/paimon-core/src/main/java/org/apache/paimon/table/system/FileKeyRangesTable.java
@@ -62,11 +62,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@@ -187,16 +185,6 @@ public class FileKeyRangesTable implements ReadonlyTable {
private static class FileKeyRangesRead implements InnerTableRead {
- private static final Set<String> SCAN_PUSHDOWN_FIELDS =
scanPushdownFields();
-
- private static Set<String> scanPushdownFields() {
- Set<String> fields = new HashSet<>();
- fields.add("partition");
- fields.add("bucket");
- fields.add("level");
- return Collections.unmodifiableSet(fields);
- }
-
private final SchemaManager schemaManager;
private final FileStoreTable storeTable;
@@ -216,9 +204,7 @@ public class FileKeyRangesTable implements ReadonlyTable {
this.postFilter = null;
return this;
}
- List<Predicate> remaining =
- PredicateBuilder.excludePredicateWithFields(
- PredicateBuilder.splitAnd(predicate),
SCAN_PUSHDOWN_FIELDS);
+ List<Predicate> remaining =
FilesTable.scanResidualPredicates(predicate);
this.postFilter = remaining.isEmpty() ? null :
PredicateBuilder.and(remaining);
return this;
}
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/system/FilesTable.java
b/paimon-core/src/main/java/org/apache/paimon/table/system/FilesTable.java
index 3602a62168..5c071f945a 100644
--- a/paimon-core/src/main/java/org/apache/paimon/table/system/FilesTable.java
+++ b/paimon-core/src/main/java/org/apache/paimon/table/system/FilesTable.java
@@ -281,17 +281,36 @@ public class FilesTable implements ReadonlyTable {
}
}
- private static class FilesRead implements InnerTableRead {
+ private static final Set<String> SCAN_PUSHDOWN_FIELDS =
scanPushdownFields();
+
+ private static Set<String> scanPushdownFields() {
+ Set<String> fields = new HashSet<>();
+ fields.add("partition");
+ fields.add("bucket");
+ fields.add("level");
+ return Collections.unmodifiableSet(fields);
+ }
- private static final Set<String> SCAN_PUSHDOWN_FIELDS =
scanPushdownFields();
+ /**
+ * Returns the conjuncts that the scan does not push down. The scan only
pushes top-level leaves
+ * on a plain partition, bucket or level field, so transforms and OR
predicates on these fields
+ * must still be evaluated on the rows.
+ */
+ static List<Predicate> scanResidualPredicates(Predicate predicate) {
+ return PredicateBuilder.splitAnd(predicate).stream()
+ .filter(p -> !isScanPushdown(p))
+ .collect(Collectors.toList());
+ }
- private static Set<String> scanPushdownFields() {
- Set<String> fields = new HashSet<>();
- fields.add("partition");
- fields.add("bucket");
- fields.add("level");
- return Collections.unmodifiableSet(fields);
- }
+ private static boolean isScanPushdown(Predicate predicate) {
+ return predicate instanceof LeafPredicate
+ && ((LeafPredicate) predicate)
+ .fieldRefOptional()
+ .filter(ref ->
SCAN_PUSHDOWN_FIELDS.contains(ref.name()))
+ .isPresent();
+ }
+
+ private static class FilesRead implements InnerTableRead {
private final SchemaManager schemaManager;
@@ -312,9 +331,7 @@ public class FilesTable implements ReadonlyTable {
this.predicate = null;
return this;
}
- List<Predicate> remaining =
- PredicateBuilder.excludePredicateWithFields(
- PredicateBuilder.splitAnd(predicate),
SCAN_PUSHDOWN_FIELDS);
+ List<Predicate> remaining = scanResidualPredicates(predicate);
this.predicate = remaining.isEmpty() ? null :
PredicateBuilder.and(remaining);
return this;
}
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/system/ManifestsTable.java
b/paimon-core/src/main/java/org/apache/paimon/table/system/ManifestsTable.java
index 7bc8f23b42..0aef309b6d 100644
---
a/paimon-core/src/main/java/org/apache/paimon/table/system/ManifestsTable.java
+++
b/paimon-core/src/main/java/org/apache/paimon/table/system/ManifestsTable.java
@@ -187,6 +187,7 @@ public class ManifestsTable implements ReadonlyTable {
private static final String LEAF_NAME = "schema_id";
private RowType readType;
+ @Nullable private Predicate rowFilter;
private final FileStoreTable dataTable;
@@ -200,6 +201,7 @@ public class ManifestsTable implements ReadonlyTable {
@Override
public InnerTableRead withFilter(Predicate predicate) {
+ this.rowFilter =
LeafPredicateExtractor.rowFilterForTransforms(predicate);
if (predicate == null) {
return this;
}
@@ -297,6 +299,9 @@ public class ManifestsTable implements ReadonlyTable {
Iterators.transform(
manifestFileMetas.iterator(),
meta -> toRow(meta, partitionCastExecutor));
+ if (rowFilter != null) {
+ rows = Iterators.filter(rows, rowFilter::test);
+ }
if (readType != null) {
rows =
Iterators.transform(
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/system/SchemasTable.java
b/paimon-core/src/main/java/org/apache/paimon/table/system/SchemasTable.java
index 7e09f55b80..f6280fb3b3 100644
--- a/paimon-core/src/main/java/org/apache/paimon/table/system/SchemasTable.java
+++ b/paimon-core/src/main/java/org/apache/paimon/table/system/SchemasTable.java
@@ -185,6 +185,7 @@ public class SchemasTable implements ReadonlyTable {
private class SchemasRead implements InnerTableRead {
private RowType readType;
+ @Nullable private Predicate rowFilter;
private @Nullable Long schemaIdMin = null;
private @Nullable Long schemaIdMax = null;
@@ -192,6 +193,7 @@ public class SchemasTable implements ReadonlyTable {
@Override
public InnerTableRead withFilter(Predicate predicate) {
+ this.rowFilter =
LeafPredicateExtractor.rowFilterForTransforms(predicate);
if (predicate == null) {
return this;
}
@@ -279,6 +281,9 @@ public class SchemasTable implements ReadonlyTable {
@SuppressWarnings("DataFlowIssue")
Iterator<InternalRow> rows =
Iterators.transform(tableSchemas.iterator(),
SchemasTable::toRow);
+ if (rowFilter != null) {
+ rows = Iterators.filter(rows, rowFilter::test);
+ }
if (readType != null) {
rows =
Iterators.transform(
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/system/SnapshotsTable.java
b/paimon-core/src/main/java/org/apache/paimon/table/system/SnapshotsTable.java
index 2b4ae3b99e..408cdd3f36 100644
---
a/paimon-core/src/main/java/org/apache/paimon/table/system/SnapshotsTable.java
+++
b/paimon-core/src/main/java/org/apache/paimon/table/system/SnapshotsTable.java
@@ -61,6 +61,8 @@ import org.apache.paimon.utils.SnapshotManager;
import org.apache.paimon.shade.guava30.com.google.common.collect.Iterators;
+import javax.annotation.Nullable;
+
import java.io.IOException;
import java.time.Instant;
import java.time.LocalDateTime;
@@ -219,6 +221,7 @@ public class SnapshotsTable implements ReadonlyTable {
private final FileIO fileIO;
private RowType readType;
+ @Nullable private Predicate rowFilter;
private Optional<Long> optionalFilterSnapshotIdMax = Optional.empty();
private Optional<Long> optionalFilterSnapshotIdMin = Optional.empty();
private final List<Long> snapshotIds = new ArrayList<>();
@@ -229,6 +232,7 @@ public class SnapshotsTable implements ReadonlyTable {
@Override
public InnerTableRead withFilter(Predicate predicate) {
+ this.rowFilter =
LeafPredicateExtractor.rowFilterForTransforms(predicate);
if (predicate == null) {
return this;
}
@@ -322,6 +326,9 @@ public class SnapshotsTable implements ReadonlyTable {
}
Iterator<InternalRow> rows = Iterators.transform(snapshots,
this::toRow);
+ if (rowFilter != null) {
+ rows = Iterators.filter(rows, rowFilter::test);
+ }
if (readType != null) {
rows =
Iterators.transform(
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/system/BucketsTableTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/system/BucketsTableTest.java
index 777f3e3c58..2bc1196892 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/system/BucketsTableTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/system/BucketsTableTest.java
@@ -25,8 +25,10 @@ import
org.apache.paimon.data.serializer.InternalRowSerializer;
import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;
import org.apache.paimon.fs.local.LocalFileIO;
+import org.apache.paimon.predicate.FieldRef;
import org.apache.paimon.predicate.Predicate;
import org.apache.paimon.predicate.PredicateBuilder;
+import org.apache.paimon.predicate.UpperTransform;
import org.apache.paimon.reader.RecordReader;
import org.apache.paimon.schema.FileSystemSchemaManager;
import org.apache.paimon.schema.Schema;
@@ -37,6 +39,7 @@ import org.apache.paimon.table.FileStoreTableFactory;
import org.apache.paimon.table.Table;
import org.apache.paimon.table.TableTestBase;
import org.apache.paimon.table.source.ReadBuilder;
+import org.apache.paimon.types.DataField;
import org.apache.paimon.types.DataTypes;
import org.apache.paimon.utils.Projection;
@@ -45,6 +48,7 @@ import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import static org.apache.paimon.catalog.Identifier.SYSTEM_TABLE_SPLITTER;
@@ -117,6 +121,44 @@ public class BucketsTableTest extends TableTestBase {
assertThat(readWithFilter(bucketsTable, filter, new int[] {0, 1, 2,
4})).isEmpty();
}
+ @Test
+ public void testBucketsTableWithPartitionTransformFilter() throws
Exception {
+ PredicateBuilder builder = new
PredicateBuilder(BucketsTable.TABLE_TYPE);
+ DataField partitionField = BucketsTable.TABLE_TYPE.getFields().get(0);
+ UpperTransform upperPartition =
+ new UpperTransform(
+ Collections.singletonList(
+ new FieldRef(0, partitionField.name(),
partitionField.type())));
+
+ Predicate filter = builder.equal(upperPartition,
BinaryString.fromString("{2}"));
+ assertThat(readWithFilter(bucketsTable, filter, new int[] {1, 2, 4}))
+ .containsExactlyInAnyOrder(GenericRow.of(0, 2L, 2L));
+ }
+
+ @Test
+ public void testBucketsTableWithPartitionRangeFilter() throws Exception {
+ Schema schema =
+ Schema.newBuilder()
+ .column("pk", DataTypes.INT())
+ .column("pt", DataTypes.INT())
+ .partitionKeys("pt")
+ .primaryKey("pk", "pt")
+ .option("bucket", "1")
+ .build();
+ catalog.createTable(identifier("RangeTable"), schema, false);
+ FileStoreTable table = (FileStoreTable)
catalog.getTable(identifier("RangeTable"));
+ write(table, GenericRow.of(1, 9), GenericRow.of(1, 10));
+ Table rangeBucketsTable =
+ catalog.getTable(identifier("RangeTable" +
SYSTEM_TABLE_SPLITTER + BUCKETS));
+
+ // The scan compares partition values as integers, so 10 > 9 although
'{10}' < '{9}'.
+ Predicate filter =
+ new PredicateBuilder(BucketsTable.TABLE_TYPE)
+ .greaterThan(0, BinaryString.fromString("{9}"));
+ assertThat(readWithFilter(rangeBucketsTable, filter, new int[] {0}))
+
.containsExactly(GenericRow.of(BinaryString.fromString("{10}")));
+ }
+
@Test
public void testBucketsTableWithBucketFilter() throws Exception {
PredicateBuilder builder = new
PredicateBuilder(BucketsTable.TABLE_TYPE);
@@ -155,7 +197,7 @@ public class BucketsTableTest extends TableTestBase {
readBuilder.withProjection(projection);
}
RecordReader<InternalRow> reader =
-
readBuilder.newRead().createReader(readBuilder.newScan().plan());
+
readBuilder.newRead().executeFilter().createReader(readBuilder.newScan().plan());
InternalRowSerializer serializer =
new InternalRowSerializer(
projection == null
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/system/ConsumersTableTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/system/ConsumersTableTest.java
index 249d570991..be9843c88c 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/system/ConsumersTableTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/system/ConsumersTableTest.java
@@ -26,14 +26,17 @@ import org.apache.paimon.data.BinaryString;
import org.apache.paimon.data.GenericRow;
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.data.serializer.InternalRowSerializer;
+import org.apache.paimon.predicate.FieldRef;
import org.apache.paimon.predicate.Predicate;
import org.apache.paimon.predicate.PredicateBuilder;
+import org.apache.paimon.predicate.UpperTransform;
import org.apache.paimon.reader.RecordReader;
import org.apache.paimon.schema.Schema;
import org.apache.paimon.table.FileStoreTable;
import org.apache.paimon.table.Table;
import org.apache.paimon.table.TableTestBase;
import org.apache.paimon.table.source.ReadBuilder;
+import org.apache.paimon.types.DataField;
import org.apache.paimon.types.DataTypes;
import org.junit.jupiter.api.BeforeEach;
@@ -42,6 +45,7 @@ import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -99,6 +103,21 @@ public class ConsumersTableTest extends TableTestBase {
assertThat(result).isEmpty();
}
+ @Test
+ public void testFilterByConsumerIdTransform() throws Exception {
+ PredicateBuilder builder = new
PredicateBuilder(ConsumersTable.TABLE_TYPE);
+ DataField consumerIdField =
ConsumersTable.TABLE_TYPE.getFields().get(0);
+ UpperTransform upperConsumerId =
+ new UpperTransform(
+ Collections.singletonList(
+ new FieldRef(0, consumerIdField.name(),
consumerIdField.type())));
+ Predicate predicate = builder.equal(upperConsumerId,
BinaryString.fromString("ID1"));
+ List<InternalRow> expectedRow =
+ Arrays.asList(GenericRow.of(BinaryString.fromString("id1"),
5L));
+ List<InternalRow> result = readWithFilter(consumersTable, predicate);
+ assertThat(result).containsExactlyElementsOf(expectedRow);
+ }
+
@Test
public void testFilterByConsumerIdIn() throws Exception {
PredicateBuilder builder = new
PredicateBuilder(ConsumersTable.TABLE_TYPE);
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/system/FileKeyRangesTableTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/system/FileKeyRangesTableTest.java
index de00e33b30..69dd91f2ce 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/system/FileKeyRangesTableTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/system/FileKeyRangesTableTest.java
@@ -21,10 +21,12 @@ package org.apache.paimon.table.system;
import org.apache.paimon.catalog.Identifier;
import org.apache.paimon.data.BinaryString;
import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.predicate.FieldRef;
import org.apache.paimon.predicate.In;
import org.apache.paimon.predicate.LeafPredicate;
import org.apache.paimon.predicate.Predicate;
import org.apache.paimon.predicate.PredicateBuilder;
+import org.apache.paimon.predicate.UpperTransform;
import org.apache.paimon.schema.Schema;
import org.apache.paimon.table.FileStoreTable;
import org.apache.paimon.table.TableTestBase;
@@ -38,6 +40,7 @@ import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import static org.apache.paimon.catalog.Identifier.SYSTEM_TABLE_SPLITTER;
@@ -106,6 +109,22 @@ public class FileKeyRangesTableTest extends TableTestBase {
}
}
+ @Test
+ public void testPartitionTransformFilter() throws Exception {
+ PredicateBuilder builder = new
PredicateBuilder(FileKeyRangesTable.TABLE_TYPE);
+ DataField partitionField =
FileKeyRangesTable.TABLE_TYPE.getFields().get(0);
+ UpperTransform upperPartition =
+ new UpperTransform(
+ Collections.singletonList(
+ new FieldRef(0, partitionField.name(),
partitionField.type())));
+ List<String> rows =
+ readPartBucketLevel(builder.equal(upperPartition,
BinaryString.fromString("{1}")));
+ assertThat(rows).isNotEmpty();
+ for (String row : rows) {
+ assertThat(row).startsWith("{1}-");
+ }
+ }
+
@Test
public void testBucketFilter() throws Exception {
PredicateBuilder builder = new
PredicateBuilder(FileKeyRangesTable.TABLE_TYPE);
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/system/FilesTableTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/system/FilesTableTest.java
index eccb3c0d70..cff9bfbc7e 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/system/FilesTableTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/system/FilesTableTest.java
@@ -31,10 +31,12 @@ import org.apache.paimon.io.DataFileMeta;
import org.apache.paimon.manifest.FileKind;
import org.apache.paimon.manifest.ManifestEntry;
import org.apache.paimon.operation.FileStoreScan;
+import org.apache.paimon.predicate.FieldRef;
import org.apache.paimon.predicate.In;
import org.apache.paimon.predicate.LeafPredicate;
import org.apache.paimon.predicate.Predicate;
import org.apache.paimon.predicate.PredicateBuilder;
+import org.apache.paimon.predicate.UpperTransform;
import org.apache.paimon.schema.FileSystemSchemaManager;
import org.apache.paimon.schema.Schema;
import org.apache.paimon.schema.SchemaChange;
@@ -247,6 +249,21 @@ public class FilesTableTest extends TableTestBase {
assertThat(readPartBucketLevel(combinedMiss)).isEmpty();
}
+ @Test
+ public void testReadWithPartitionTransformFilter() throws Exception {
+ PredicateBuilder builder = new PredicateBuilder(FilesTable.TABLE_TYPE);
+ DataField partitionField = FilesTable.TABLE_TYPE.getFields().get(0);
+ UpperTransform upperPartition =
+ new UpperTransform(
+ Collections.singletonList(
+ new FieldRef(0, partitionField.name(),
partitionField.type())));
+
+ assertThat(
+ readPartBucketLevel(
+ builder.equal(upperPartition,
BinaryString.fromString("{2, 20}"))))
+ .containsExactlyInAnyOrder("{2, 20}-0-0", "{2, 20}-0-0");
+ }
+
@Test
public void testReadFilesFromSpecifiedSnapshot() throws Exception {
List<InternalRow> expectedRow = getExpectedResult(1L);
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/system/SnapshotsTableTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/system/SnapshotsTableTest.java
index 23e26d60a2..81633ee782 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/system/SnapshotsTableTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/system/SnapshotsTableTest.java
@@ -32,6 +32,8 @@ import org.apache.paimon.fs.Path;
import org.apache.paimon.fs.local.LocalFileIO;
import org.apache.paimon.manifest.ManifestCommittable;
import org.apache.paimon.options.ExpireConfig;
+import org.apache.paimon.predicate.FieldRef;
+import org.apache.paimon.predicate.LowerTransform;
import org.apache.paimon.predicate.Predicate;
import org.apache.paimon.predicate.PredicateBuilder;
import org.apache.paimon.schema.FileSystemSchemaManager;
@@ -55,6 +57,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -166,6 +169,42 @@ public class SnapshotsTableTest extends TableTestBase {
assertThat(result).containsExactlyInAnyOrderElementsOf(getExpectedResult(new
long[] {1}));
}
+ @Test
+ public void testReadSnapshotsWithTransformFilter() throws Exception {
+ PredicateBuilder builder = new
PredicateBuilder(snapshotsTable.rowType());
+ int snapshotIdIdx =
snapshotsTable.rowType().getFieldNames().indexOf("snapshot_id");
+ int commitKindIdx =
snapshotsTable.rowType().getFieldNames().indexOf("commit_kind");
+ LowerTransform lowerCommitKind =
+ new LowerTransform(
+ Collections.singletonList(
+ new FieldRef(
+ commitKindIdx,
+ "commit_kind",
+
snapshotsTable.rowType().getTypeAt(commitKindIdx))));
+
+ assertThat(
+ readWithFilter(
+ PredicateBuilder.and(
+ builder.greaterOrEqual(snapshotIdIdx,
2L),
+ builder.equal(
+ lowerCommitKind,
+
BinaryString.fromString("append")))))
+ .containsExactlyInAnyOrderElementsOf(getExpectedResult(new
long[] {2}));
+ assertThat(
+ readWithFilter(
+ builder.equal(lowerCommitKind,
BinaryString.fromString("compact"))))
+ .isEmpty();
+
+ int schemaIdIdx =
snapshotsTable.rowType().getFieldNames().indexOf("schema_id");
+ assertThat(
+ readWithFilter(
+ PredicateBuilder.and(
+ builder.equal(
+ lowerCommitKind,
BinaryString.fromString("append")),
+ builder.equal(schemaIdIdx, 999L))))
+ .isEmpty();
+ }
+
@Test
public void testReadSnapshotsWithEqualFilterOnUnknownId() throws Exception
{
PredicateBuilder builder = new
PredicateBuilder(snapshotsTable.rowType());
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/system/TagsTableTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/system/TagsTableTest.java
index 31bc9401ea..5cb2c47b0b 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/system/TagsTableTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/system/TagsTableTest.java
@@ -24,8 +24,10 @@ import org.apache.paimon.data.GenericRow;
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.data.Timestamp;
import org.apache.paimon.manifest.ManifestCommittable;
+import org.apache.paimon.predicate.FieldRef;
import org.apache.paimon.predicate.Predicate;
import org.apache.paimon.predicate.PredicateBuilder;
+import org.apache.paimon.predicate.UpperTransform;
import org.apache.paimon.reader.RecordReader;
import org.apache.paimon.schema.Schema;
import org.apache.paimon.table.FileStoreTable;
@@ -45,6 +47,7 @@ import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -151,6 +154,24 @@ class TagsTableTest extends TableTestBase {
assertThat(readTagNames(builder.greaterThan(1,
maxSnapshotId))).isEmpty();
}
+ @Test
+ void testReadWithTransformFilter() throws Exception {
+ table.createTag("tag-a");
+ table.createTag("tag-b");
+
+ PredicateBuilder builder = new PredicateBuilder(TagsTable.TABLE_TYPE);
+ UpperTransform upperTagName =
+ new UpperTransform(
+ Collections.singletonList(
+ new FieldRef(0, "tag_name",
DataTypes.STRING().notNull())));
+ Predicate upperEqual = builder.equal(upperTagName,
BinaryString.fromString("TAG-A"));
+ assertThat(readTagNames(upperEqual)).containsExactly("tag-a");
+
+ Predicate orPredicate =
+ PredicateBuilder.or(builder.equal(0,
BinaryString.fromString("tag-b")), upperEqual);
+
assertThat(readTagNames(orPredicate)).containsExactlyInAnyOrder("tag-a",
"tag-b");
+ }
+
@Test
void testReadWithNullFilterReturnsAll() throws Exception {
table.createTag("tag-a");