[WIP] Parquet: add_files, migrate and snapshot can record bounds that hide rows when a row group has no usable min or max
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 55/100
Línea de trabajo
Start with the row-group loop and variant loop in parquet/src/main/java/org/apache/iceberg/parquet/ParquetMetrics.java, then compare their handling with ParquetMetricsRowGroupFilter. Reproduce the missing bounds with the Spark and PyArrow examples in the issue and inspect the existing Parquet metrics tests. Done means metrics retain counts but omit bounds when a row group has non-null values without usable min or max, and the filtered reads and DELETE find the expected rows.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Apache Iceberg version
1.12.0 (latest release)
Query engine
Spark
Please describe the bug 🐞
Iceberg's Parquet footer metrics build a column's lower and upper bounds from the row groups whose statistics hold a usable min and max. A row group whose statistics hold a null count but no usable min or max contributes its counts only, and the bounds of the other row groups are kept. When that row group holds a value outside those bounds, scan planning skips the file for a filter that matches the value. Filtered reads then miss the row, and a filtered DELETE leaves it in place. add_files, migrate and snapshot register files through these metrics.
These files read that way:
- parquet-java: Spark's Parquet writer, parquet-mr 1.13.1, and Iceberg's own writer, on parquet-java 1.17.1, give a float or double row group holding NaN and 100.0 the statistics
min 100.0, max NaN. For floating point columns in type order, the format tells readers to ignore a NaN min or max, parquet.thrift. parquet-java's reader does, and keeps the null count, Statistics. - DuckDB 1.5.3 and 2.0.1: a float or double row group holding a NaN gets a null count and a NaN count but no min or max, primitive_column_writer.cpp.
- PyArrow 25.0.1 and 26.0.1: a string or binary row group whose largest value is longer than the default
max_statistics_sizeof 4,096 bytes gets a null count and no min or max; 4,096 bytes keeps them, properties.h.
On Spark 3.5.10 with PyArrow 26.0.1:
import tempfile
import pyarrow as pa
import pyarrow.parquet as pq
from pyspark.sql import SparkSession
work = tempfile.mkdtemp()
spark = (SparkSession.builder.master("local[1]")
.config("spark.jars.packages", "org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:1.12.0")
.config("spark.sql.extensions", "org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions")
.config("spark.sql.catalog.local", "org.apache.iceberg.spark.SparkCatalog")
.config("spark.sql.catalog.local.type", "hadoop")
.config("spark.sql.catalog.local.warehouse", f"file://{work}/warehouse")
.config("spark.hadoop.parquet.block.size", "1") # a row group every two rows
.config("spark.hadoop.parquet.page.size.row.check.min", "2")
.config("spark.hadoop.parquet.page.size.row.check.max", "2")
.getOrCreate())
# A Parquet file written by Spark, whose second row group holds a NaN
rows = [(1.0,), (2.0,), (float("nan"),), (100.0,)]
spark.createDataFrame(spark.sparkContext.parallelize(rows, 1), "d double").write.parquet(f"file://{work}/doubles")
spark.sql("CREATE TABLE local.db.doubles (d double) USING iceberg")
spark.sql(f"CALL local.system.add_files(table => 'db.doubles', source_table => '`parquet`.`file://{work}/doubles`')")
spark.sql("SELECT readable_metrics.d.lower_bound, readable_metrics.d.upper_bound FROM local.db.doubles.files").show()
spark.sql("SELECT count(*) FROM local.db.doubles WHERE d = 100.0").show()
spark.sql("DELETE FROM local.db.doubles WHERE d = 100.0")
spark.sql("SELECT count(*) FROM local.db.doubles").show()
# A Parquet file written by PyArrow, whose second row group holds a value longer than 4,096 bytes
long_value = "z" * 5000
pq.write_table(pa.table({"v": ["a", "b", "c", long_value]}), f"{work}/strings.parquet", row_group_size=2)
spark.sql("CREATE TABLE local.db.strings (v string) USING iceberg "
"TBLPROPERTIES ('format-version' = '2', 'write.delete.mode' = 'merge-on-read')")
spark.sql(f"CALL local.system.add_files(table => 'db.strings', source_table => '`parquet`.`file://{work}/strings.parquet`')")
spark.sql("SELECT readable_metrics.v.upper_bound FROM local.db.strings.files").show()
spark.sql(f"SELECT count(*) FROM local.db.strings WHERE v = '{long_value}'").show()
spark.sql(f"DELETE FROM local.db.strings WHERE v = '{long_value}'")
spark.sql("SELECT count(*) FROM local.db.strings").show()
| Table | Recorded bounds | Rows matching the filter | Rows after the DELETE |
|---|---|---|---|
doubles |
1.0 to 2.0 | 0, expected 1 | 4, expected 3 |
strings |
upper bound b |
0, expected 1 | 4, expected 3 |
Both DELETE statements succeed and leave all 4 rows. Files of the same kinds miss rows the same way on 1.4.3, 1.10.0 and a build of main at 65d832d, and snapshot misses the same rows on 1.12.0.
All three procedures reach the footer through SparkTableUtil:
- Callers:
add_filestakesimportSparkPartitionsfor a file path, as above, andimportSparkTablefor a catalog table, AddFilesProcedure and L227-L254.migrateandsnapshottakeimportSparkTable, MigrateTableSparkAction and SnapshotTableSparkAction. - The footer read: both go through TableMigrationUtil to
ParquetUtil.fileMetrics. - Delta Lake: its snapshot action calls
ParquetUtil.fileMetricstoo, BaseSnapshotDeltaLakeTableAction.
The loop over a column's row groups is in ParquetMetrics.
- It drops the column's metrics only when a row group's statistics are null or empty; #8559 added the empty case.
- Otherwise it takes min and max only
if (stats.hasNonNullValue()). The variant loop at L623-L643 does the same. - The row-group filter already treats such statistics as undefined, ParquetMetricsRowGroupFilter, since #6517 fixed the same NaN case there.
Iceberg's own commits record the right bounds here: ParquetMetrics prefers the metrics a writer supplies for a field, ParquetMetrics, and a Spark append of the same four rows into an Iceberg table records 1.0 to 100.0. That append wrote one row group, so add_files of its file records no bounds and the filter still finds the row. A different file that Iceberg wrote with two row groups, one of them holding a NaN, does get the short bound when it is registered again through add_files.
Bounds must hold every non-null, non-NaN value in the file, Field-level Metrics and Statistics, and readers may skip a file by them, Scan Planning. I'd propose that a column keep its counts and get no bounds when one of its row groups holds non-null values but no usable min or max: minMaxUndefined in the row-group filter, and not allNulls. apache/iceberg-python#4313 made the same change in PyIceberg.
This report was drafted with an AI assistant, which also ran the reproduction on 1.12.0 and checked the linked lines. Not run: migrate, which takes the same path as snapshot.
Willingness to contribute
- I can contribute a fix for this bug independently
- I would be willing to contribute a fix for this bug with guidance from the Iceberg community
- I cannot contribute a fix for this bug at this time
- Lenguaje dominante
- Java
- Estrellas
- 9.5k
- Forks
- 3.7k
- Merge medio
- 2 d 2 h
- PR fusionados (30 d)
- 170
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/iceberg
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Spark: Test INSERT targets with computed IDENTIFIER expressionsPosiblemente ocupada @shivadarshan-devadiga la tomó hace 15 días. Abiertoimprovement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
[Core] TestAvroPartitionStatsHandler fails on Windows due to unclosed partition statistics scanPosiblemente ocupada @Ankitkj1999 la tomó hace 17 días. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Core: TableMetadata.Builder allows adding encryption keys to v1/v2 tablesPosiblemente ocupada @yusufyildiz34 la tomó hace 37 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
apache/iceberg#18632 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Kafka: Filter empty strings and whitespace in IcebergSinkConfig stringToListPosiblemente ocupada @mohamed-elbrik la tomó hace 42 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
Todos los issues de apache/iceberg
Issues similares
-
bug vault
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
bancolombia/secrets-manager#150 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 92/100
HexaHexes/neoforge-mod-template#124 ·
Los mantenedores suelen responder en 1 día
-
awaiting triage java new feature P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días
-
source-survicate: pagination reads pagination and stops after one page; substreams drop survey_idAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
OpenLiberty/open-liberty#36410 ·
Los mantenedores suelen responder en 1 día