Skip to content

Commit

Permalink
Core: Cache dropStats in ManifestReader iterator (apache#5836)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuzhang authored Nov 9, 2022
1 parent 305e320 commit a50a295
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/apache/iceberg/ManifestReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ CloseableIterable<ManifestEntry<F>> liveEntries() {
/** @return an Iterator of DataFile. Makes defensive copies of files before returning */
@Override
public CloseableIterator<F> iterator() {
return CloseableIterable.transform(liveEntries(), e -> e.file().copy(!dropStats(columns)))
.iterator();
boolean dropStats = dropStats(columns);
return CloseableIterable.transform(liveEntries(), e -> e.file().copy(!dropStats)).iterator();
}

private static Schema projection(
Expand Down
19 changes: 19 additions & 0 deletions core/src/test/java/org/apache/iceberg/TestManifestReaderStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ public void testReadIteratorWithFilterAndSelectStatsIncludesFullStats() throws I
}
}

@Test
public void testReadIteratorWithProjectStats() throws IOException {
ManifestFile manifest = writeManifest(1000L, FILE);
try (ManifestReader<DataFile> reader =
ManifestFiles.read(manifest, FILE_IO)
.project(new Schema(ImmutableList.of(DataFile.FILE_PATH, DataFile.VALUE_COUNTS)))) {
DataFile entry = reader.iterator().next();

Assert.assertEquals(FILE_PATH, entry.path());
Assert.assertEquals(VALUE_COUNT, entry.valueCounts());
Assert.assertNull(entry.columnSizes());
Assert.assertNull(entry.nullValueCounts());
Assert.assertNull(entry.nanValueCounts());
Assert.assertNull(entry.lowerBounds());
Assert.assertNull(entry.upperBounds());
assertNullRecordCount(entry);
}
}

@Test
public void testReadEntriesWithSelectNotProjectStats() throws IOException {
ManifestFile manifest = writeManifest(1000L, FILE);
Expand Down

0 comments on commit a50a295

Please sign in to comment.