raghav-reglobe commented on code in PR #16363:
URL: https://github.com/apache/iceberg/pull/16363#discussion_r3545800406
##########
core/src/main/java/org/apache/iceberg/TableProperties.java:
##########
@@ -176,14 +176,21 @@ private TableProperties() {}
"write.delete.parquet.row-group-check-max-record-count";
public static final int PARQUET_ROW_GROUP_CHECK_MAX_RECORD_COUNT_DEFAULT =
10000;
- public static final String PARQUET_ROW_GROUP_SIZE_TRACK_UNCOMPRESSED =
- "write.parquet.row-group-size-track-uncompressed";
- public static final boolean
PARQUET_ROW_GROUP_SIZE_TRACK_UNCOMPRESSED_DEFAULT = false;
-
public static final String PARQUET_BLOOM_FILTER_MAX_BYTES =
"write.parquet.bloom-filter-max-bytes";
public static final int PARQUET_BLOOM_FILTER_MAX_BYTES_DEFAULT = 1024 * 1024;
+ // Enables Parquet's adaptive bloom filter sizing. When true,
+ // the writer evaluates ~5 candidate bloom filters and picks the smallest
that
+ // satisfies actual NDV at FPP. Works in combination with
+ // PARQUET_BLOOM_FILTER_MAX_BYTES, which bounds the largest candidate — the
+ // adaptive size never exceeds it. Significantly reduces file size for
+ // low-row-count writes (e.g., streaming microbatches) that would otherwise
pad
+ // the parquet file with an empty PARQUET_BLOOM_FILTER_MAX_BYTES buffer.
Review Comment:
Not strongly — dropped it. configuration.md covers it.
##########
parquet/src/test/java/org/apache/iceberg/parquet/TestParquetAdaptiveBloomFilter.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.parquet;
+
+import static
org.apache.iceberg.TableProperties.PARQUET_BLOOM_FILTER_ADAPTIVE_ENABLED;
+import static
org.apache.iceberg.TableProperties.PARQUET_BLOOM_FILTER_COLUMN_ENABLED_PREFIX;
+import static
org.apache.iceberg.TableProperties.PARQUET_BLOOM_FILTER_MAX_BYTES;
+import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericRecordBuilder;
+import org.apache.iceberg.Files;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.avro.AvroSchemaUtil;
+import org.apache.iceberg.io.FileAppender;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Tests for the adaptive bloom filter sizing TBLPROPERTY ({@code
+ * write.parquet.bloom-filter-adaptive-enabled}).
+ *
+ * <p>Without adaptive sizing, parquet-mr's {@code
ColumnValueCollector.initBloomFilter} allocates a
+ * fixed {@code bloom-filter-max-bytes} buffer per bloom-enabled column
regardless of actual NDV
+ * (the {@code !ndv.isPresent() && !adaptive} branch calls {@code new
BlockSplitBloomFilter(
+ * maxBloomFilterSize, maxBloomFilterSize)}). For low-row-count writes this
produces a file
+ * dominated by an empty bloom filter buffer. The adaptive flag (PARQUET-2254)
makes parquet-mr pick
+ * the smallest of N candidate filter sizes that satisfies actual NDV at FPP.
+ *
+ * <p>These tests use the createWriterFunc code path because that is the path
Iceberg uses for Spark
+ * and Flink data writes; the legacy ParquetWriteBuilder path goes through
parquet-mr directly
+ * without consulting Iceberg-specific properties.
+ */
+public class TestParquetAdaptiveBloomFilter {
Review Comment:
No strong reason — moved the two tests into TestParquet next to the other
writer-property tests and dropped the separate class.
##########
parquet/src/test/java/org/apache/iceberg/parquet/TestParquetAdaptiveBloomFilter.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.parquet;
+
+import static
org.apache.iceberg.TableProperties.PARQUET_BLOOM_FILTER_ADAPTIVE_ENABLED;
+import static
org.apache.iceberg.TableProperties.PARQUET_BLOOM_FILTER_COLUMN_ENABLED_PREFIX;
+import static
org.apache.iceberg.TableProperties.PARQUET_BLOOM_FILTER_MAX_BYTES;
+import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericRecordBuilder;
+import org.apache.iceberg.Files;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.avro.AvroSchemaUtil;
+import org.apache.iceberg.io.FileAppender;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Tests for the adaptive bloom filter sizing TBLPROPERTY ({@code
+ * write.parquet.bloom-filter-adaptive-enabled}).
+ *
+ * <p>Without adaptive sizing, parquet-mr's {@code
ColumnValueCollector.initBloomFilter} allocates a
+ * fixed {@code bloom-filter-max-bytes} buffer per bloom-enabled column
regardless of actual NDV
Review Comment:
The class javadoc is gone now that the tests live in TestParquet — the
remaining comments reference the Iceberg property constants.
##########
parquet/src/test/java/org/apache/iceberg/parquet/TestParquetAdaptiveBloomFilter.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.parquet;
+
+import static
org.apache.iceberg.TableProperties.PARQUET_BLOOM_FILTER_ADAPTIVE_ENABLED;
+import static
org.apache.iceberg.TableProperties.PARQUET_BLOOM_FILTER_COLUMN_ENABLED_PREFIX;
+import static
org.apache.iceberg.TableProperties.PARQUET_BLOOM_FILTER_MAX_BYTES;
+import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericRecordBuilder;
+import org.apache.iceberg.Files;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.avro.AvroSchemaUtil;
+import org.apache.iceberg.io.FileAppender;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Tests for the adaptive bloom filter sizing TBLPROPERTY ({@code
+ * write.parquet.bloom-filter-adaptive-enabled}).
+ *
+ * <p>Without adaptive sizing, parquet-mr's {@code
ColumnValueCollector.initBloomFilter} allocates a
+ * fixed {@code bloom-filter-max-bytes} buffer per bloom-enabled column
regardless of actual NDV
+ * (the {@code !ndv.isPresent() && !adaptive} branch calls {@code new
BlockSplitBloomFilter(
+ * maxBloomFilterSize, maxBloomFilterSize)}). For low-row-count writes this
produces a file
+ * dominated by an empty bloom filter buffer. The adaptive flag (PARQUET-2254)
makes parquet-mr pick
+ * the smallest of N candidate filter sizes that satisfies actual NDV at FPP.
+ *
+ * <p>These tests use the createWriterFunc code path because that is the path
Iceberg uses for Spark
+ * and Flink data writes; the legacy ParquetWriteBuilder path goes through
parquet-mr directly
+ * without consulting Iceberg-specific properties.
+ */
+public class TestParquetAdaptiveBloomFilter {
+
+ private static final Schema SCHEMA = new Schema(required(1, "id",
Types.LongType.get()));
+
+ @TempDir private Path temp;
+
+ /**
+ * Writes a parquet file via the createWriterFunc code path with bloom
filter enabled on the
+ * {@code id} column and a 4 MiB max-bytes cap. Returns the resulting file
size.
+ */
+ private long writeAndMeasure(boolean adaptive) throws IOException {
+ File file = new File(temp.toFile(), "test_" + adaptive + "_" +
System.nanoTime() + ".parquet");
+ OutputFile outFile = Files.localOutput(file);
+
+ Parquet.WriteBuilder writer =
+ Parquet.write(outFile)
+ .schema(SCHEMA)
+ .createWriterFunc(ParquetAvroWriter::buildWriter)
+ .set(PARQUET_BLOOM_FILTER_COLUMN_ENABLED_PREFIX + "id", "true")
+ .set(PARQUET_BLOOM_FILTER_MAX_BYTES, "4194304");
+
+ if (adaptive) {
+ writer = writer.set(PARQUET_BLOOM_FILTER_ADAPTIVE_ENABLED, "true");
+ }
+
+ org.apache.avro.Schema avroSchema =
AvroSchemaUtil.convert(SCHEMA.asStruct());
+ try (FileAppender<GenericData.Record> appender = writer.build()) {
+ for (int i = 0; i < 5; i++) {
+ appender.add(new GenericRecordBuilder(avroSchema).set("id", (long)
i).build());
+ }
+ }
+
+ return file.length();
+ }
+
+ @Test
+ public void adaptiveSizingShrinksFile() throws IOException {
+ // Without adaptive, parquet-mr writes the full bloom-filter-max-bytes
buffer (~4 MiB).
Review Comment:
Done — switched to the Iceberg property constants.
##########
parquet/src/test/java/org/apache/iceberg/parquet/TestParquetAdaptiveBloomFilter.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.parquet;
+
+import static
org.apache.iceberg.TableProperties.PARQUET_BLOOM_FILTER_ADAPTIVE_ENABLED;
+import static
org.apache.iceberg.TableProperties.PARQUET_BLOOM_FILTER_COLUMN_ENABLED_PREFIX;
+import static
org.apache.iceberg.TableProperties.PARQUET_BLOOM_FILTER_MAX_BYTES;
+import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericRecordBuilder;
+import org.apache.iceberg.Files;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.avro.AvroSchemaUtil;
+import org.apache.iceberg.io.FileAppender;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Tests for the adaptive bloom filter sizing TBLPROPERTY ({@code
+ * write.parquet.bloom-filter-adaptive-enabled}).
+ *
+ * <p>Without adaptive sizing, parquet-mr's {@code
ColumnValueCollector.initBloomFilter} allocates a
+ * fixed {@code bloom-filter-max-bytes} buffer per bloom-enabled column
regardless of actual NDV
+ * (the {@code !ndv.isPresent() && !adaptive} branch calls {@code new
BlockSplitBloomFilter(
+ * maxBloomFilterSize, maxBloomFilterSize)}). For low-row-count writes this
produces a file
+ * dominated by an empty bloom filter buffer. The adaptive flag (PARQUET-2254)
makes parquet-mr pick
+ * the smallest of N candidate filter sizes that satisfies actual NDV at FPP.
+ *
+ * <p>These tests use the createWriterFunc code path because that is the path
Iceberg uses for Spark
+ * and Flink data writes; the legacy ParquetWriteBuilder path goes through
parquet-mr directly
+ * without consulting Iceberg-specific properties.
+ */
+public class TestParquetAdaptiveBloomFilter {
+
+ private static final Schema SCHEMA = new Schema(required(1, "id",
Types.LongType.get()));
+
+ @TempDir private Path temp;
+
+ /**
+ * Writes a parquet file via the createWriterFunc code path with bloom
filter enabled on the
+ * {@code id} column and a 4 MiB max-bytes cap. Returns the resulting file
size.
+ */
+ private long writeAndMeasure(boolean adaptive) throws IOException {
Review Comment:
Fair — the helper now just delegates to ParquetWritingTestUtils.write and
returns the written length.
##########
docs/docs/configuration.md:
##########
@@ -57,8 +56,8 @@ Iceberg tables support table properties to configure table
behavior, like the de
| write.parquet.bloom-filter-max-bytes | 1048576 (1 MB)
| The maximum number of bytes for a bloom filter bitset
|
| write.parquet.bloom-filter-fpp.column.col1 | 0.01
| The false positive probability for a bloom filter applied to 'col1'
(must > 0.0 and < 1.0)
|
| write.parquet.bloom-filter-ndv.column.col1 | (not set)
| The expected number of distinct values for a bloom filter applied to
'col1' (must > 0)
|
+| write.parquet.bloom-filter-adaptive-enabled | false
| Use parquet-mr adaptive bloom filter sizing (PARQUET-2254): evaluate
candidate filters and pick the smallest that satisfies the actual NDV at the
configured FPP, bounded by 'bloom-filter-max-bytes', instead of always
allocating the full max-bytes buffer |
Review Comment:
Good point — added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]