Skip to content

Core: Use time-travel schema when resolving partition spec in scan #13301

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -119,7 +119,7 @@ protected TableScan newRefinedScan(Table table, Schema schema, TableScanContext
@Override
protected CloseableIterable<FileScanTask> doPlanFiles() {
FileIO io = table().io();
Map<Integer, PartitionSpec> specs = Maps.newHashMap(table().specs());
Map<Integer, PartitionSpec> specs = Maps.newHashMap(specs());
Schema dataTableSchema = table().schema();
Expression filter = shouldIgnoreResiduals() ? Expressions.alwaysTrue() : filter();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ private DeleteFileIndex planDeletesLocally(List<ManifestFile> deleteManifests) {
}

return builder
.specsById(table().specs())
.specsById(specs())
.filterData(filter())
.caseSensitive(isCaseSensitive())
.scanMetrics(scanMetrics())
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/apache/iceberg/DataScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected ManifestGroup newManifestGroup(
.caseSensitive(isCaseSensitive())
.select(withColumnStats ? SCAN_WITH_STATS_COLUMNS : SCAN_COLUMNS)
.filterData(filter())
.specsById(table().specs())
.specsById(specs())
.scanMetrics(scanMetrics())
.ignoreDeleted()
.columnsToKeepStats(columnsToKeepStats());
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/apache/iceberg/DataTableScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public CloseableIterable<FileScanTask> doPlanFiles() {
.caseSensitive(isCaseSensitive())
.select(scanColumns())
.filterData(filter())
.specsById(table().specs())
.specsById(specs())
.scanMetrics(scanMetrics())
.ignoreDeleted()
.columnsToKeepStats(columnsToKeepStats());
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/org/apache/iceberg/SnapshotScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ protected ScanMetrics scanMetrics() {
return scanMetrics;
}

protected Map<Integer, PartitionSpec> specs() {
Map<Integer, PartitionSpec> specs = table().specs();
// requires latest schema
if (!useSnapshotSchema() || snapshotId() == null) {
return specs;
}

Choose a reason for hiding this comment

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

can we have a test showcasing the functionality fixed by this contribution?

Copy link
Author

Choose a reason for hiding this comment

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

I am looking for the proper place to add the test, but I’m not sure where it should go. would appreciate some guidance

// this is a time travel request
Schema snapshotSchema = tableSchema();
Map<Integer, PartitionSpec> newSpecs = Maps.newHashMapWithExpectedSize(specs.size());
for (Map.Entry<Integer, PartitionSpec> entry : specs.entrySet()) {
newSpecs.put(entry.getKey(), entry.getValue().toUnbound().bindUnchecked(snapshotSchema));
}
return newSpecs;
}

public ThisT useSnapshot(long scanSnapshotId) {
Preconditions.checkArgument(
snapshotId() == null, "Cannot override snapshot, already set snapshot id=%s", snapshotId());
Expand Down