[WIP] Parquet: add_files, migrate and snapshot can record bounds that hide rows when a row group has no usable min or max
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Java
- Stelle
- 9.5k
- Fork
- 3.7k
- Merge medio
- 2g 2h
- PR unite (30g)
- 170
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/iceberg
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Spark: Test INSERT targets with computed IDENTIFIER expressionsForse già presa @shivadarshan-devadiga l’ha presa 15 giorni fa. Apertaimprovement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
[Core] TestAvroPartitionStatsHandler fails on Windows due to unclosed partition statistics scanForse già presa @Ankitkj1999 l’ha presa 17 giorni fa. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Core: TableMetadata.Builder allows adding encryption keys to v1/v2 tablesForse già presa @yusufyildiz34 l’ha presa 37 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
apache/iceberg#18632 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Kafka: Filter empty strings and whitespace in IcebergSinkConfig stringToListForse già presa @mohamed-elbrik l’ha presa 42 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di apache/iceberg
Issue simili
-
bug vault
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
bancolombia/secrets-manager#150 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 92/100
HexaHexes/neoforge-mod-template#124 ·
I maintainer di solito rispondono entro 1 giorno
-
awaiting triage java new feature P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 2 giorni
-
source-survicate: pagination reads pagination and stops after one page; substreams drop survey_idAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
OpenLiberty/open-liberty#36410 ·
I maintainer di solito rispondono entro 1 giorno