[WIP] Parquet: add_files, migrate and snapshot can record bounds that hide rows when a row group has no usable min or max

Abierto
#19,236 0 comentarios 0 reacciones 0 asignados Ver en GitHub

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
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java, spark

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_size of 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:

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

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/iceberg

Todos los issues de apache/iceberg

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.