Spark 3.5.4+: vectorized Parquet reads return wrong values in 1.6.x (backport #11731 to 1.6.x)

オープン
#18,927 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@aquwikimedia がすでに取り組んでいます。

2026年11月13日 から。

  • #18931 @aquwikimedia による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java, spark

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

bug
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
主要言語
Java
スター
9.4k
フォーク
3.7k
平均マージ
2日 15時間
マージ済み PR(30日)
169

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/iceberg のほかの issue

apache/iceberg の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。