From c7316a69aae30fe8a8ef70ac1e33f3dcb7240589 Mon Sep 17 00:00:00 2001 From: Krisztian Szucs Date: Tue, 24 Nov 2026 14:54:02 +0100 Subject: [PATCH] GH-3991: Apply the page row count limit to the first page of ParquetWriter's row groups ColumnWriteStoreBase's BloomFilterWriteStore constructor, used by every ParquetWriter, did not cap the first page size check at the page row count limit. The vectored IO tests' filter was fitted to the old page layout. --- .../column/impl/ColumnWriteStoreBase.java | 2 +- .../TestParquetFileReaderVectoredIO.java | 6 ++-- .../parquet/hadoop/TestParquetWriter.java | 29 +++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/parquet-column/src/main/java/org/apache/parquet/column/impl/ColumnWriteStoreBase.java b/parquet-column/src/main/java/org/apache/parquet/column/impl/ColumnWriteStoreBase.java index 9bc7726491..e75f98a319 100644 --- a/parquet-column/src/main/java/org/apache/parquet/column/impl/ColumnWriteStoreBase.java +++ b/parquet-column/src/main/java/org/apache/parquet/column/impl/ColumnWriteStoreBase.java @@ -122,7 +122,7 @@ public ColumnWriter getColumnWriter(ColumnDescriptor path) { } this.columns = unmodifiableMap(mcolumns); - this.rowCountForNextSizeCheck = props.getMinRowCountForPageSizeCheck(); + this.rowCountForNextSizeCheck = min(props.getMinRowCountForPageSizeCheck(), props.getPageRowCountLimit()); columnWriterProvider = new ColumnWriterProvider() { @Override diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileReaderVectoredIO.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileReaderVectoredIO.java index 41d65591c9..8739cfe3a2 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileReaderVectoredIO.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetFileReaderVectoredIO.java @@ -392,7 +392,7 @@ public void testSplitsOversizedFilteredPageIntoBoundedVectoredRanges() throws Ex @Test public void testSplitsAdjacentFilteredPageRangesAtMaximumAllocation() throws Exception { - int maximumAllocation = 1416; + int maximumAllocation = 1774; RecordingAllocator allocator = new RecordingAllocator(); RecordingSeekableInputStream stream = newStream(FailureMode.NONE); FilterPredicate predicate = or(ltEq(intColumn("id"), 99), gtEq(intColumn("id"), 120)); @@ -708,14 +708,14 @@ private static ParquetReadOptions readOptions( .withMaxAllocationInBytes(maximumAllocation); if (filterPages) { FilterPredicate predicate = - or(ltEq(intColumn("id"), 99), and(gtEq(intColumn("id"), 108), ltEq(intColumn("id"), 115))); + or(ltEq(intColumn("id"), 95), and(gtEq(intColumn("id"), 104), ltEq(intColumn("id"), 111))); builder.useColumnIndexFilter(true).withRecordFilter(FilterCompat.get(predicate)); } return builder.build(); } private static void assertRows(PageReadStore pages, MessageType projection, boolean filtered) { - assertRows(pages, projection, filtered, filtered ? 108 : ROW_COUNT); + assertRows(pages, projection, filtered, filtered ? 104 : ROW_COUNT); } private static void assertRows(PageReadStore pages, MessageType projection, boolean filtered, long expectedRows) { diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetWriter.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetWriter.java index 3866e3fdd4..fa7492a371 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetWriter.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetWriter.java @@ -49,6 +49,7 @@ import java.nio.channels.FileChannel; import java.nio.file.Files; import java.nio.file.StandardOpenOption; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -354,6 +355,34 @@ public void testNullValuesWithPageRowLimit() throws IOException { } } + @Test + public void testPageRowCountLimitAppliesToFirstPage() throws IOException { + MessageType schema = Types.buildMessage().required(INT32).named("id").named("msg"); + GroupFactory factory = new SimpleGroupFactory(schema); + + Path path = newTempPath(); + try (ParquetWriter writer = ExampleParquetWriter.builder(path) + .withAllocator(allocator) + .withType(schema) + .withPageRowCountLimit(10) + .withDictionaryEncoding(false) + .build()) { + for (int i = 0; i < 100; ++i) { + writer.write(factory.newGroup().append("id", i)); + } + } + + try (ParquetFileReader reader = ParquetFileReader.open(HadoopInputFile.fromPath(path, new Configuration()))) { + PageReader pageReader = + reader.readNextRowGroup().getPageReader(schema.getColumns().get(0)); + List pageRowCounts = new ArrayList<>(); + for (DataPage page = pageReader.readPage(); page != null; page = pageReader.readPage()) { + pageRowCounts.add(page.getValueCount()); + } + assertThat(pageRowCounts).containsExactly(10, 10, 10, 10, 10, 10, 10, 10, 10, 10); + } + } + @Test public void testParquetFileWithBloomFilter() throws IOException { MessageType schema = Types.buildMessage()