Spark 3.5.4+: vectorized Parquet reads return wrong values in 1.6.x (backport #11731 to 1.6.x)
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- java, spark
- Ambito
- data-engineering
Direzione di ricerca
Start with IcebergArrowColumnVector in the Spark 3.5 module, which reuses Arrow vectors across batches and needs a no-op closeIfFreeable() override as in #11731. Then check the spark-hive35 Gradle build and bump it to Spark 3.5.4 on the 1.6.x branch. Run the reproduction script in the issue with a 1,000-row file and batch size 100; done means exceptAll returns 0 and the existing vectorized read tests pass.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Apache Iceberg version
1.6.1
Query engine
Spark
Please describe the bug 🐞
Summary
With Spark 3.5.4 or later and the Iceberg 1.6.x Spark 3.5 runtime, Iceberg's vectorized Parquet reader returns wrong values without any error for every row after the first batch (5,000 rows by default) of each data file. Sometimes the executor crashes instead (SIGSEGV, "double free", IncompatibleClassChangeError: vtable stub). Files on disk are correct; only the read is wrong.
This was fixed on main by #11731 (Bump Apache Spark to 3.5.4) and backported to 1.7.x (released in 1.7.2). It was never backported to 1.6.x.
Cause
Spark 3.5.4 (SPARK-50235, SPARK-50463) changed the code generated for ColumnarToRow: it calls ColumnarBatch.closeIfFreeable() after each batch. ColumnVector.closeIfFreeable() calls close() by default; vectors that reuse their memory must override it with a no-op, as Spark's own vectors do.
IcebergArrowColumnVector in 1.6.x reuses its Arrow vectors for every batch of a file but does not override closeIfFreeable(). After the first batch, Spark closes the vectors; Iceberg then writes the next batches into released buffers. Iceberg sets arrow.enable_unsafe_memory_access=true, so there is no bounds check and no error: Spark reads zeros or stale values (e.g. DATE columns become 1970-01-01), and the stray writes can corrupt other memory.
It only happens with whole-stage codegen on (the default), and only when Iceberg uses the vectorized reader (all projected columns are primitive).
Affected versions
| Iceberg | Spark 3.5.0 - 3.5.3 | Spark 3.5.4+ |
|---|---|---|
≤ 1.7.1 (iceberg-spark-runtime-3.5_2.12) |
OK | affected |
| 1.7.2, ≥ 1.8.0 | OK | OK (fixed by #11731) |
Reproduction
Spark 3.5.8 (any 3.5.4+), Java 8, iceberg-spark-runtime-3.5_2.12-1.6.1.jar. One data file of 1,000 rows, read with a batch size of 100:
from pyspark.sql import SparkSession
spark = (
SparkSession.builder.master("local[1]")
.config("spark.jars", "iceberg-spark-runtime-3.5_2.12-1.6.1.jar")
.config("spark.sql.catalog.local", "org.apache.iceberg.spark.SparkCatalog")
.config("spark.sql.catalog.local.type", "hadoop")
.config("spark.sql.catalog.local.warehouse", "/tmp/iceberg_repro")
.getOrCreate()
)
expected = spark.range(0, 1000).selectExpr(
"id", "date_add(date'2025-01-01', cast(id % 5 AS INT)) AS d", "id * 10 AS v", "concat('row_', id) AS s"
)
expected.coalesce(1).writeTo("local.db.t").tableProperty("write.distribution-mode", "none").create()
actual = spark.read.option("vectorization-enabled", "true").option("batch-size", "100").table("local.db.t")
print(actual.exceptAll(expected).count())
Expected: 0. Actual: 900 on Linux (every row after the first batch); on macOS the JVM crashed with SIGSEGV. With spark.sql.codegen.wholeStage=false, vectorization-enabled=false, or Spark 3.5.3, the result is 0.
We first hit it in production: a table with years() partitions (files > 5,000 rows) came back with wrong dates after a Spark 3.5.1 → 3.5.8 upgrade; smaller days() partitions hid it.
Why a backport to 1.6.x
1.6.1 is the last Iceberg release that runs on Java 8: 1.7.0 and later need Java 11. Spark 3.5.x still supports Java 8, so Java 8 Spark 3.5 users have no fixed release:
- upgrading Iceberg to 1.7.2 is not possible on Java 8;
- staying on Spark ≤ 3.5.3 means giving up the Spark 3.5.4 - 3.5.8 fixes, including security fixes;
- turning off vectorized reads (
spark.sql.iceberg.vectorization.enabled=false) works, but costs about 25 - 30% on scans in our tests.
And the failure mode is silent wrong results, which users of 1.6.1 with a recent Spark 3.5 may not have noticed.
The fix is the same 5-line override as in #11731, plus the spark-hive35 bump to 3.5.4 so that 1.6.x is built and tested against a Spark version that has closeIfFreeable(). I have a PR ready against 1.6.x.
I understand that 1.6.x is not actively maintained. Even if a 1.6.2 release is not planned, having the fix on the 1.6.x branch would help Java 8 users who build from it, and this issue documents the incompatibility for people searching for it.
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.4k
- Fork
- 3.7k
- Merge medio
- 2g 15h
- PR unite (30g)
- 169
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
-
Spark: Test INSERT targets with computed IDENTIFIER expressionsForse già presa @shivadarshan-devadiga l’ha presa 7 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 9 giorni fa. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Flink: JdbcLockFactory concurrent lock-table creation can fail with "table already exists" and restart the jobForse già presa @adiranjan25 l’ha presa 16 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
apache/iceberg#18797 · 1 commento ·
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 29 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 34 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
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
speakeasy-api/speakeasy#2159 ·
I maintainer di solito rispondono entro 1 giorno
-
area: cli
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
vitruv-tools/NeoJoin#415 ·
I maintainer di solito rispondono entro 1 giorno
-
Quick Installation step 2 installs from the plugin manager, but the plugin isn't published yetAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
jenkinsci/user-guide-ai-chatbot-plugin#132 ·
I maintainer di solito rispondono entro 6 giorni
-
account assessment course feature lecture
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug] 连接达梦时报错,agent 进程启动即退Apertabug db/dameng user-priority/P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno