-
Notifications
You must be signed in to change notification settings - Fork 3.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
Add support for partition pruning in Delta checkpoint iterator #19588
Merged
Merged
Changes from all commits
Commits
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
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
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
import io.trino.filesystem.TrinoFileSystemFactory; | ||
import io.trino.filesystem.TrinoInputFile; | ||
import io.trino.parquet.ParquetReaderOptions; | ||
import io.trino.plugin.deltalake.DeltaLakeColumnHandle; | ||
import io.trino.plugin.deltalake.DeltaLakeColumnMetadata; | ||
import io.trino.plugin.deltalake.DeltaLakeConfig; | ||
import io.trino.plugin.deltalake.transactionlog.TableSnapshot.MetadataAndProtocolEntry; | ||
|
@@ -39,6 +40,7 @@ | |
import io.trino.spi.TrinoException; | ||
import io.trino.spi.connector.ConnectorSession; | ||
import io.trino.spi.connector.SchemaTableName; | ||
import io.trino.spi.predicate.TupleDomain; | ||
import io.trino.spi.type.ArrayType; | ||
import io.trino.spi.type.BooleanType; | ||
import io.trino.spi.type.MapType; | ||
|
@@ -75,6 +77,8 @@ | |
import static io.airlift.slice.SizeOf.instanceSize; | ||
import static io.trino.cache.CacheUtils.invalidateAllIf; | ||
import static io.trino.plugin.deltalake.DeltaLakeErrorCode.DELTA_LAKE_INVALID_SCHEMA; | ||
import static io.trino.plugin.deltalake.DeltaLakeSessionProperties.isCheckpointFilteringEnabled; | ||
import static io.trino.plugin.deltalake.DeltaLakeSplitManager.partitionMatchesPredicate; | ||
import static io.trino.plugin.deltalake.transactionlog.TransactionLogParser.readLastCheckpoint; | ||
import static io.trino.plugin.deltalake.transactionlog.TransactionLogUtil.getTransactionLogJsonEntryPath; | ||
import static io.trino.plugin.deltalake.transactionlog.checkpoint.CheckpointEntryIterator.EntryType.ADD; | ||
|
@@ -219,9 +223,20 @@ public MetadataEntry getMetadataEntry(TableSnapshot tableSnapshot, ConnectorSess | |
.orElseThrow(() -> new TrinoException(DELTA_LAKE_INVALID_SCHEMA, "Metadata not found in transaction log for " + tableSnapshot.getTable())); | ||
} | ||
|
||
@Deprecated | ||
public List<AddFileEntry> getActiveFiles(TableSnapshot tableSnapshot, MetadataEntry metadataEntry, ProtocolEntry protocolEntry, ConnectorSession session) | ||
{ | ||
return getActiveFiles(tableSnapshot, metadataEntry, protocolEntry, TupleDomain.all(), session); | ||
} | ||
|
||
public List<AddFileEntry> getActiveFiles(TableSnapshot tableSnapshot, MetadataEntry metadataEntry, ProtocolEntry protocolEntry, TupleDomain<DeltaLakeColumnHandle> partitionConstraint, ConnectorSession session) | ||
{ | ||
try { | ||
if (isCheckpointFilteringEnabled(session)) { | ||
return loadActiveFiles(tableSnapshot, metadataEntry, protocolEntry, partitionConstraint, session).stream() | ||
.collect(toImmutableList()); | ||
} | ||
|
||
TableVersion tableVersion = new TableVersion(new TableLocation(tableSnapshot.getTable(), tableSnapshot.getTableLocation()), tableSnapshot.getVersion()); | ||
|
||
DeltaLakeDataFileCacheEntry cacheEntry = activeDataFileCache.get(tableVersion, () -> { | ||
|
@@ -249,7 +264,7 @@ public List<AddFileEntry> getActiveFiles(TableSnapshot tableSnapshot, MetadataEn | |
} | ||
} | ||
|
||
List<AddFileEntry> activeFiles = loadActiveFiles(tableSnapshot, metadataEntry, protocolEntry, session); | ||
List<AddFileEntry> activeFiles = loadActiveFiles(tableSnapshot, metadataEntry, protocolEntry, TupleDomain.all(), session); | ||
return new DeltaLakeDataFileCacheEntry(tableSnapshot.getVersion(), activeFiles); | ||
}); | ||
return cacheEntry.getActiveFiles(); | ||
|
@@ -259,7 +274,12 @@ public List<AddFileEntry> getActiveFiles(TableSnapshot tableSnapshot, MetadataEn | |
} | ||
} | ||
|
||
private List<AddFileEntry> loadActiveFiles(TableSnapshot tableSnapshot, MetadataEntry metadataEntry, ProtocolEntry protocolEntry, ConnectorSession session) | ||
private List<AddFileEntry> loadActiveFiles( | ||
TableSnapshot tableSnapshot, | ||
MetadataEntry metadataEntry, | ||
ProtocolEntry protocolEntry, | ||
TupleDomain<DeltaLakeColumnHandle> partitionConstraint, | ||
ConnectorSession session) | ||
{ | ||
List<Transaction> transactions = tableSnapshot.getTransactions(); | ||
try (Stream<DeltaLakeTransactionLogEntry> checkpointEntries = tableSnapshot.getCheckpointTransactionLogEntries( | ||
|
@@ -269,8 +289,12 @@ private List<AddFileEntry> loadActiveFiles(TableSnapshot tableSnapshot, Metadata | |
typeManager, | ||
fileSystemFactory.create(session), | ||
fileFormatDataSourceStats, | ||
Optional.of(new MetadataAndProtocolEntry(metadataEntry, protocolEntry)))) { | ||
Optional.of(new MetadataAndProtocolEntry(metadataEntry, protocolEntry)), | ||
partitionConstraint)) { | ||
return activeAddEntries(checkpointEntries, transactions) | ||
.filter(partitionConstraint.isAll() | ||
? addAction -> true | ||
: addAction -> partitionMatchesPredicate(addAction.getCanonicalPartitionValues(), partitionConstraint.getDomains().orElseThrow())) | ||
.collect(toImmutableList()); | ||
} | ||
catch (IOException e) { | ||
|
@@ -407,8 +431,9 @@ private <T> Stream<T> getEntries( | |
{ | ||
try { | ||
List<Transaction> transactions = tableSnapshot.getTransactions(); | ||
// Passing TupleDomain.all() because this method is used for getting all entries | ||
Stream<DeltaLakeTransactionLogEntry> checkpointEntries = tableSnapshot.getCheckpointTransactionLogEntries( | ||
session, entryTypes, checkpointSchemaManager, typeManager, fileSystem, stats, Optional.empty()); | ||
session, entryTypes, checkpointSchemaManager, typeManager, fileSystem, stats, Optional.empty(), TupleDomain.all()); | ||
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. Maybe worth a code comment why partitionConstraint isn't needed here. |
||
|
||
return entryMapper.apply( | ||
checkpointEntries, | ||
|
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.
Could you pls test coverage into
TestDeltaLakeFileOperations
withcheckpoint_filtering_enabled
session property enabled to add more transparence in regards to the consequences coming with this change?