diff --git a/core/src/main/java/org/apache/iceberg/DataFilesTable.java b/core/src/main/java/org/apache/iceberg/DataFilesTable.java index 4b153b19fc2b..abc06a48fbeb 100644 --- a/core/src/main/java/org/apache/iceberg/DataFilesTable.java +++ b/core/src/main/java/org/apache/iceberg/DataFilesTable.java @@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; import java.util.Collection; -import org.apache.iceberg.avro.Avro; import org.apache.iceberg.expressions.Expression; import org.apache.iceberg.expressions.ResidualEvaluator; import org.apache.iceberg.io.CloseableIterable; @@ -107,16 +106,7 @@ protected long targetSplitSize(TableOperations ops) { @Override protected CloseableIterable planFiles( TableOperations ops, Snapshot snapshot, Expression rowFilter, boolean caseSensitive, boolean colStats) { - CloseableIterable manifests = Avro - .read(ops.io().newInputFile(snapshot.manifestListLocation())) - .rename("manifest_file", GenericManifestFile.class.getName()) - .rename("partitions", GenericPartitionFieldSummary.class.getName()) - // 508 is the id used for the partition field, and r508 is the record name created for it in Avro schemas - .rename("r508", GenericPartitionFieldSummary.class.getName()) - .project(ManifestFile.schema()) - .reuseContainers(false) - .build(); - + CloseableIterable manifests = CloseableIterable.withNoopClose(snapshot.manifests()); String schemaString = SchemaParser.toJson(schema()); String specString = PartitionSpecParser.toJson(PartitionSpec.unpartitioned()); ResidualEvaluator residuals = ResidualEvaluator.unpartitioned(rowFilter); diff --git a/core/src/main/java/org/apache/iceberg/HistoryTable.java b/core/src/main/java/org/apache/iceberg/HistoryTable.java index 1ee50225d5d2..abc18290759e 100644 --- a/core/src/main/java/org/apache/iceberg/HistoryTable.java +++ b/core/src/main/java/org/apache/iceberg/HistoryTable.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; import java.util.function.Function; +import org.apache.iceberg.io.CloseableIterable; import org.apache.iceberg.types.Types; import org.apache.iceberg.util.SnapshotUtil; @@ -81,6 +82,12 @@ private class HistoryScan extends StaticTableScan { HistoryScan() { super(ops, table, HISTORY_SCHEMA, HistoryTable.this::task); } + + @Override + public CloseableIterable planFiles() { + // override planFiles to avoid the check for a current snapshot because this metadata table is for all snapshots + return CloseableIterable.withNoopClose(HistoryTable.this.task(this)); + } } private static Function convertHistoryEntryFunc(Table table) { diff --git a/core/src/main/java/org/apache/iceberg/ManifestEntriesTable.java b/core/src/main/java/org/apache/iceberg/ManifestEntriesTable.java index 8185f0aeda46..11b430ebf1b5 100644 --- a/core/src/main/java/org/apache/iceberg/ManifestEntriesTable.java +++ b/core/src/main/java/org/apache/iceberg/ManifestEntriesTable.java @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; import java.util.Collection; -import org.apache.iceberg.avro.Avro; import org.apache.iceberg.expressions.Expression; import org.apache.iceberg.expressions.ResidualEvaluator; import org.apache.iceberg.io.CloseableIterable; @@ -105,16 +104,7 @@ protected long targetSplitSize(TableOperations ops) { @Override protected CloseableIterable planFiles( TableOperations ops, Snapshot snapshot, Expression rowFilter, boolean caseSensitive, boolean colStats) { - CloseableIterable manifests = Avro - .read(ops.io().newInputFile(snapshot.manifestListLocation())) - .rename("manifest_file", GenericManifestFile.class.getName()) - .rename("partitions", GenericPartitionFieldSummary.class.getName()) - // 508 is the id used for the partition field, and r508 is the record name created for it in Avro schemas - .rename("r508", GenericPartitionFieldSummary.class.getName()) - .project(ManifestFile.schema()) - .reuseContainers(false) - .build(); - + CloseableIterable manifests = CloseableIterable.withNoopClose(snapshot.manifests()); String schemaString = SchemaParser.toJson(schema()); String specString = PartitionSpecParser.toJson(PartitionSpec.unpartitioned()); diff --git a/core/src/main/java/org/apache/iceberg/ManifestsTable.java b/core/src/main/java/org/apache/iceberg/ManifestsTable.java index 14f46bcd17b2..4eb776edce3f 100644 --- a/core/src/main/java/org/apache/iceberg/ManifestsTable.java +++ b/core/src/main/java/org/apache/iceberg/ManifestsTable.java @@ -79,8 +79,9 @@ public Schema schema() { } protected DataTask task(TableScan scan) { + String manifestListLocation = scan.snapshot().manifestListLocation(); return StaticDataTask.of( - ops.io().newInputFile(scan.snapshot().manifestListLocation()), + ops.io().newInputFile(manifestListLocation != null ? manifestListLocation : ops.current().file().location()), scan.snapshot().manifests(), this::manifestFileToRow); } diff --git a/core/src/main/java/org/apache/iceberg/SnapshotsTable.java b/core/src/main/java/org/apache/iceberg/SnapshotsTable.java index 633be050e7e4..bcb59f37fb2a 100644 --- a/core/src/main/java/org/apache/iceberg/SnapshotsTable.java +++ b/core/src/main/java/org/apache/iceberg/SnapshotsTable.java @@ -19,6 +19,7 @@ package org.apache.iceberg; +import org.apache.iceberg.io.CloseableIterable; import org.apache.iceberg.types.Types; /** @@ -78,6 +79,12 @@ private class SnapshotsTableScan extends StaticTableScan { SnapshotsTableScan() { super(ops, table, SNAPSHOT_SCHEMA, SnapshotsTable.this::task); } + + @Override + public CloseableIterable planFiles() { + // override planFiles to avoid the check for a current snapshot because this metadata table is for all snapshots + return CloseableIterable.withNoopClose(SnapshotsTable.this.task(this)); + } } private static StaticDataTask.Row snapshotToRow(Snapshot snap) {