-
Notifications
You must be signed in to change notification settings - Fork 3k
Cache PositionIndex #5264
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
Cache PositionIndex #5264
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 |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| import org.apache.iceberg.deletes.PositionDeleteIndex; | ||
| import org.apache.iceberg.expressions.Expressions; | ||
| import org.apache.iceberg.io.CloseableIterable; | ||
| import org.apache.iceberg.io.CloseableIterator; | ||
| import org.apache.iceberg.io.InputFile; | ||
| import org.apache.iceberg.orc.ORC; | ||
| import org.apache.iceberg.parquet.Parquet; | ||
|
|
@@ -72,6 +73,7 @@ public abstract class DeleteFilter<T> { | |
| private PositionDeleteIndex deleteRowPositions = null; | ||
| private List<Predicate<T>> isInDeleteSets = null; | ||
| private Predicate<T> eqDeleteRows = null; | ||
| private CloseableIterator<Long> deletePositionIte; | ||
|
|
||
| protected DeleteFilter(String filePath, List<DeleteFile> deletes, Schema tableSchema, Schema requestedSchema) { | ||
| this.setFilterThreshold = DEFAULT_SET_FILTER_THRESHOLD; | ||
|
|
@@ -128,6 +130,9 @@ protected long pos(T record) { | |
| return (Long) posAccessor.get(asStructLike(record)); | ||
| } | ||
|
|
||
| /** | ||
| * Please only close the last CloseableIterable if you want to reuse the filter | ||
| */ | ||
| public CloseableIterable<T> filter(CloseableIterable<T> records) { | ||
| return applyEqDeletes(applyPosDeletes(records)); | ||
| } | ||
|
|
@@ -222,18 +227,23 @@ private CloseableIterable<T> applyPosDeletes(CloseableIterable<T> records) { | |
| return records; | ||
| } | ||
|
|
||
| List<CloseableIterable<Record>> deletes = Lists.transform(posDeletes, this::openPosDeletes); | ||
|
|
||
| // if there are fewer deletes than a reasonable number to keep in memory, use a set | ||
| if (posDeletes.stream().mapToLong(DeleteFile::recordCount).sum() < setFilterThreshold) { | ||
| PositionDeleteIndex positionIndex = Deletes.toPositionIndex(filePath, deletes); | ||
| Predicate<T> isDeleted = record -> positionIndex.isDeleted(pos(record)); | ||
| if (deleteRowPositions == null) { | ||
|
Contributor
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. I don't think this should run line 225 to open the deletes if they can be reused.
Contributor
Author
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. I get you |
||
| List<CloseableIterable<Record>> deletes = Lists.transform(posDeletes, this::openPosDeletes); | ||
| deleteRowPositions = Deletes.toPositionIndex(filePath, deletes); | ||
| } | ||
| Predicate<T> isDeleted = record -> deleteRowPositions.isDeleted(pos(record)); | ||
|
Contributor
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
Contributor
Author
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. No NPE. The return of " Deletes.toPositionIndex(filePath, deletes)" must not be null. |
||
| return createDeleteIterable(records, isDeleted); | ||
| } | ||
|
|
||
| if (deletePositionIte == null) { | ||
| List<CloseableIterable<Record>> deletes = Lists.transform(posDeletes, this::openPosDeletes); | ||
| deletePositionIte = Deletes.deletePositions(filePath, deletes).iterator(); | ||
| } | ||
| return hasIsDeletedColumn ? | ||
| Deletes.streamingMarker(records, this::pos, Deletes.deletePositions(filePath, deletes), this::markRowDeleted) : | ||
| Deletes.streamingFilter(records, this::pos, Deletes.deletePositions(filePath, deletes)); | ||
| Deletes.streamingMarker(records, this::pos, deletePositionIte, this::markRowDeleted) : | ||
| Deletes.streamingFilter(records, this::pos, deletePositionIte); | ||
| } | ||
|
|
||
| private CloseableIterable<T> createDeleteIterable(CloseableIterable<T> records, Predicate<T> isDeleted) { | ||
|
|
||
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.
What about the else case? In that case we will not cache.
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.
Yes, it won't cache because the deletes are streamed from files.
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.
Yes, Because it use sort merge to avoid loading too many delete rows in memory.
Uh oh!
There was an error while loading. Please reload this page.
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.
But, They should't reopen position delete file and read position delete file from head, they should read position delete file continue。I will do some change here