-
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] Optizime IN filter pushdown to snapshot/tag/schema system tables #4436
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
da9010a
[core] Support IN filter pushdown for snapshot and schema tables
xuzifu666 f8105e1
fix imports
xuzifu666 5cb9b69
fix
xuzifu666 116c04f
support tag
xuzifu666 e105876
fix
de1c84d
fix imports
d1bfef2
fix name
42ec226
fix
xuzifu666 2bc72cb
address
1dcf28f
fix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
import org.apache.paimon.predicate.LeafPredicateExtractor; | ||
import org.apache.paimon.predicate.LessOrEqual; | ||
import org.apache.paimon.predicate.LessThan; | ||
import org.apache.paimon.predicate.Or; | ||
import org.apache.paimon.predicate.Predicate; | ||
import org.apache.paimon.reader.RecordReader; | ||
import org.apache.paimon.table.FileStoreTable; | ||
|
@@ -62,6 +63,7 @@ | |
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
|
@@ -206,6 +208,7 @@ private class SnapshotsRead implements InnerTableRead { | |
private RowType readType; | ||
private Optional<Long> optionalFilterSnapshotIdMax = Optional.empty(); | ||
private Optional<Long> optionalFilterSnapshotIdMin = Optional.empty(); | ||
private final List<Long> snapshotIds = new ArrayList<>(); | ||
|
||
public SnapshotsRead(FileIO fileIO) { | ||
this.fileIO = fileIO; | ||
|
@@ -220,12 +223,27 @@ public InnerTableRead withFilter(Predicate predicate) { | |
String leafName = "snapshot_id"; | ||
if (predicate instanceof CompoundPredicate) { | ||
CompoundPredicate compoundPredicate = (CompoundPredicate) predicate; | ||
List<Predicate> children = compoundPredicate.children(); | ||
if ((compoundPredicate.function()) instanceof And) { | ||
List<Predicate> children = compoundPredicate.children(); | ||
for (Predicate leaf : children) { | ||
handleLeafPredicate(leaf, leafName); | ||
} | ||
} | ||
|
||
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. List children = compoundPredicate.children(); |
||
// optimize for IN filter | ||
if ((compoundPredicate.function()) instanceof Or) { | ||
for (Predicate leaf : children) { | ||
if (leaf instanceof LeafPredicate | ||
&& (((LeafPredicate) leaf).function() instanceof Equal) | ||
&& leaf.visit(LeafPredicateExtractor.INSTANCE).get(leafName) | ||
!= null) { | ||
snapshotIds.add((Long) ((LeafPredicate) leaf).literals().get(0)); | ||
} else { | ||
snapshotIds.clear(); | ||
break; | ||
} | ||
} | ||
} | ||
} else { | ||
handleLeafPredicate(predicate, leafName); | ||
} | ||
|
@@ -284,9 +302,15 @@ public RecordReader<InternalRow> createReader(Split split) throws IOException { | |
} | ||
SnapshotManager snapshotManager = | ||
new SnapshotManager(fileIO, ((SnapshotsSplit) split).location, branch); | ||
Iterator<Snapshot> snapshots = | ||
snapshotManager.snapshotsWithinRange( | ||
optionalFilterSnapshotIdMax, optionalFilterSnapshotIdMin); | ||
|
||
Iterator<Snapshot> snapshots; | ||
if (!snapshotIds.isEmpty()) { | ||
snapshots = snapshotManager.snapshotsWithId(snapshotIds); | ||
} else { | ||
snapshots = | ||
snapshotManager.snapshotsWithinRange( | ||
optionalFilterSnapshotIdMax, optionalFilterSnapshotIdMin); | ||
} | ||
|
||
Iterator<InternalRow> rows = Iterators.transform(snapshots, this::toRow); | ||
if (readType != null) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should extract a class to reduce duplicate codes, this can be done in a new PR.
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.
OK,would refactor it as suggest,Thanks @JingsongLi