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

[core] [bug] Partition should not be filtered when manifest file predicate and file itself all min/max is null #3421

Merged
merged 5 commits into from
May 29, 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 @@ -368,10 +368,12 @@ public static Predicate partition(Map<String, String> map, RowType rowType) {
for (Map.Entry<String, String> entry : map.entrySet()) {
int idx = fieldNames.indexOf(entry.getKey());
Object literal = TypeUtils.castFromString(entry.getValue(), rowType.getTypeAt(idx));
Predicate predicateTemp =
literal == null ? builder.isNull(idx) : builder.equal(idx, literal);
if (predicate == null) {
predicate = builder.equal(idx, literal);
predicate = predicateTemp;
} else {
predicate = PredicateBuilder.and(predicate, builder.equal(idx, literal));
predicate = PredicateBuilder.and(predicate, predicateTemp);
}
}
return predicate;
Expand All @@ -394,10 +396,12 @@ public static Predicate equalPartition(BinaryRow partition, RowType partitionTyp
PredicateBuilder builder = new PredicateBuilder(partitionType);
Object[] literals = converter.convert(partition);
for (int i = 0; i < literals.length; i++) {
Predicate predicateTemp =
literals[i] == null ? builder.isNull(i) : builder.equal(i, literals[i]);
if (predicate == null) {
predicate = builder.equal(i, literals[i]);
predicate = predicateTemp;
} else {
predicate = PredicateBuilder.and(predicate, builder.equal(i, literals[i]));
predicate = PredicateBuilder.and(predicate, predicateTemp);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Predicate createEqualPredicate(BinaryRow binaryRow) {
Object[] partitionObjects = convert(binaryRow);
for (int i = 0; i < getArity(); i++) {
Object o = partitionObjects[i];
fieldPredicates.add(builder.equal(i, o));
fieldPredicates.add(o == null ? builder.isNull(i) : builder.equal(i, o));
}
return PredicateBuilder.and(fieldPredicates);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ private MultiplePartitionPredicate(
PredicateBuilder builder = new PredicateBuilder(partitionType);
for (int i = 0; i < collectors.length; i++) {
SimpleColStats stats = collectors[i].result();
min[i] = builder.greaterOrEqual(i, stats.min());
max[i] = builder.lessOrEqual(i, stats.max());
Object minValue = stats.min();
Object maxValue = stats.max();

min[i] = minValue == null ? builder.isNull(i) : builder.greaterOrEqual(i, minValue);
max[i] = maxValue == null ? builder.isNull(i) : builder.lessOrEqual(i, maxValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems wrong logic here.
Collector should not collect null values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, if it is null, all values are null.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ public SnapshotReader withPartitionFilter(Map<String, String> partitionSpec) {
m.getValue(),
rowType.getTypeAt(index),
false);
return predicateBuilder.equal(index, value);
return value == null
? predicateBuilder.isNull(index)
: predicateBuilder.equal(index, value);
})
.collect(Collectors.toList());
scan.withPartitionFilter(PredicateBuilder.and(partitionFilters));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@
import org.apache.paimon.fs.Path;
import org.apache.paimon.fs.local.LocalFileIO;
import org.apache.paimon.io.DataFileMeta;
import org.apache.paimon.manifest.SimpleFileEntry;
import org.apache.paimon.schema.Schema;
import org.apache.paimon.table.FileStoreTable;
import org.apache.paimon.table.sink.CommitMessage;
import org.apache.paimon.table.sink.CommitMessageImpl;
import org.apache.paimon.table.sink.StreamTableCommit;
import org.apache.paimon.types.DataTypes;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
Expand Down Expand Up @@ -171,4 +174,32 @@ private BinaryRow partition(int i) {
writer.complete();
return binaryRow;
}

@Test
public void testScanFilterWithNullPartition() throws Exception {
FileStoreTable table = createFileStoreTable();

AppendOnlyFileStoreWrite write = (AppendOnlyFileStoreWrite) table.store().newWrite("ss");
StreamTableCommit commit = table.newStreamWriteBuilder().newCommit();
write.withExecutionMode(false);

for (int i = 0; i < 100; i++) {
write.write(nullPartition(), i, GenericRow.of(null, i, i));
commit.commit(i, write.prepareCommit(false, i));
}

BinaryRow binaryRow = nullPartition();
FileStoreScan scan = table.store().newScan();
List<SimpleFileEntry> l0 =
scan.withPartitionFilter(Collections.singletonList(binaryRow)).readSimpleEntries();
Assertions.assertThat(l0.size()).isEqualTo(100);
}

private BinaryRow nullPartition() {
BinaryRow binaryRow = new BinaryRow(1);
BinaryRowWriter writer = new BinaryRowWriter(binaryRow);
writer.setNullAt(0);
writer.complete();
return binaryRow;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,8 @@ private Predicate createSpecificPartFilter(BinaryRow partition) {
List<Predicate> predicates = new ArrayList<>();
for (int i = 0; i < partitionKeys.size(); i++) {
int index = fieldNames.indexOf(partitionKeys.get(i));
predicates.add(
builder.equal(
index, InternalRowUtils.get(partition, i, rowType.getTypeAt(index))));
Object value = InternalRowUtils.get(partition, i, rowType.getTypeAt(index));
predicates.add(value == null ? builder.isNull(index) : builder.equal(index, value));
}
return PredicateBuilder.and(predicates);
}
Expand Down
Loading