-
Notifications
You must be signed in to change notification settings - Fork 1k
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] Enable file index for DV table #4310
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import org.apache.paimon.CoreOptions.ChangelogProducer; | ||
import org.apache.paimon.CoreOptions.MergeEngine; | ||
import org.apache.paimon.KeyValueFileStore; | ||
import org.apache.paimon.fileindex.FileIndexPredicate; | ||
import org.apache.paimon.io.DataFileMeta; | ||
import org.apache.paimon.manifest.ManifestEntry; | ||
import org.apache.paimon.manifest.ManifestFile; | ||
|
@@ -31,11 +32,17 @@ | |
import org.apache.paimon.stats.SimpleStatsEvolution; | ||
import org.apache.paimon.stats.SimpleStatsEvolutions; | ||
import org.apache.paimon.table.source.ScanMode; | ||
import org.apache.paimon.types.RowType; | ||
import org.apache.paimon.utils.SnapshotManager; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.apache.paimon.CoreOptions.MergeEngine.AGGREGATE; | ||
import static org.apache.paimon.CoreOptions.MergeEngine.FIRST_ROW; | ||
|
@@ -54,6 +61,10 @@ public class KeyValueFileStoreScan extends AbstractFileStoreScan { | |
private final MergeEngine mergeEngine; | ||
private final ChangelogProducer changelogProducer; | ||
|
||
private final boolean fileIndexReadEnabled; | ||
// just cache. | ||
private final Map<Long, Predicate> dataFilterMapping = new HashMap<>(); | ||
|
||
public KeyValueFileStoreScan( | ||
ManifestsReader manifestsReader, | ||
BucketSelectConverter bucketSelectConverter, | ||
|
@@ -65,7 +76,8 @@ public KeyValueFileStoreScan( | |
Integer scanManifestParallelism, | ||
boolean deletionVectorsEnabled, | ||
MergeEngine mergeEngine, | ||
ChangelogProducer changelogProducer) { | ||
ChangelogProducer changelogProducer, | ||
boolean fileIndexReadEnabled) { | ||
super( | ||
manifestsReader, | ||
snapshotManager, | ||
|
@@ -85,6 +97,7 @@ public KeyValueFileStoreScan( | |
this.deletionVectorsEnabled = deletionVectorsEnabled; | ||
this.mergeEngine = mergeEngine; | ||
this.changelogProducer = changelogProducer; | ||
this.fileIndexReadEnabled = fileIndexReadEnabled; | ||
} | ||
|
||
public KeyValueFileStoreScan withKeyFilter(Predicate predicate) { | ||
|
@@ -118,6 +131,28 @@ protected boolean filterByStats(ManifestEntry entry) { | |
return true; | ||
} | ||
|
||
private boolean filterByFileIndex(@Nullable byte[] embeddedIndexBytes, ManifestEntry entry) { | ||
if (embeddedIndexBytes == null) { | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If fileIndex does not exist in embeddedIndex but in a separate file, what logic of filter by FileIndex in pk table with DV? |
||
} | ||
|
||
RowType dataRowType = scanTableSchema(entry.file().schemaId()).logicalRowType(); | ||
|
||
Predicate dataPredicate = | ||
dataFilterMapping.computeIfAbsent( | ||
entry.file().schemaId(), | ||
id -> | ||
fieldValueStatsConverters.convertFilter( | ||
entry.file().schemaId(), valueFilter)); | ||
|
||
try (FileIndexPredicate predicate = | ||
new FileIndexPredicate(embeddedIndexBytes, dataRowType)) { | ||
return predicate.testPredicate(dataPredicate); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Exception happens while checking predicate.", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exception happens while checking fileIndex predicate. |
||
} | ||
} | ||
|
||
private boolean isValueFilterEnabled(ManifestEntry entry) { | ||
if (valueFilter == null) { | ||
return false; | ||
|
@@ -181,7 +216,12 @@ private boolean filterByValueFilter(ManifestEntry entry) { | |
.getOrCreate(file.schemaId()) | ||
.evolution(file.valueStats(), file.rowCount(), file.valueStatsCols()); | ||
return valueFilter.test( | ||
file.rowCount(), result.minValues(), result.maxValues(), result.nullCounts()); | ||
file.rowCount(), | ||
result.minValues(), | ||
result.maxValues(), | ||
result.nullCounts()) | ||
&& (!fileIndexReadEnabled | ||
|| filterByFileIndex(entry.file().embeddedIndex(), entry)); | ||
} | ||
|
||
private static boolean noOverlapping(List<ManifestEntry> entries) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add "File index support Append Only tables and pk table with DV" in fileIndex doc