Native MergeRows can panic or produce wrong masks - arrow 59 `and_not` mishandles sliced arrays

オープン 初心者向け
#7,596 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

まだ誰も着手していません。

評価

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

調査の方向性

merge_rows.rs の625~626行付近から始め、MergeRowsStream が一致しない行のマスクをどのように構築するかを追ってください。提供されたスライス済み配列の例で Arrow 59 の動作を再現し、マスクが and(a, not(b)) と一致すること、およびネイティブの MergeRows がパニックしなくなることを確認してください。issue では、回避策として2つの and_not 呼び出しを置き換えることが提案されています。

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

説明

requires-triage
Describe the bug

MergeRowsStream builds the "not matched" masks with arrow::compute::kernels::boolean::and_not (merge_rows.rs:625-626). In arrow 59.x and_not mixes up the offsets of its inputs when one of them is a slice (apache/arrow-rs#10698, fixed in apache/arrow-rs#10699 for 60.0.0, not backported). Comet main resolves arrow to 59.3.2, so the bug is still there.

After the full outer join one marker column can be a slice with a non-zero offset. Then the task either panics with offset + len out of bounds, or gets wrong masks with no error and applies inserts and deletes to the wrong rows. We hit the panic on Iceberg MERGE with spark.comet.exec.mergeRows.enabled=true (Comet 1.2.0, Spark 4.0.2); with the flag off the jobs pass.

Steps to reproduce
// arrow = "=59.3.2"
use arrow::array::{Array, BooleanArray};
use arrow::compute::kernels::boolean::{and, and_not, not};

fn mask(len: usize, f: fn(usize) -> bool) -> BooleanArray {
    BooleanArray::from((0..len).map(f).collect::<Vec<_>>())
}

fn main() {
    let left = mask(3000, |i| i % 3 != 0).slice(0, 1000);
    let right = mask(2000, |i| i % 5 == 0).slice(1000, 1000);
    let expected = and(&left, &not(&right).unwrap()).unwrap();
    let actual = and_not(&left, &right).unwrap();
    let wrong = (0..1000).filter(|&i| actual.value(i) != expected.value(i)).count();
    println!("wrong values: {wrong} of 1000"); // 59.x: 533, 60.1: 0
}
Expected behavior

and_not(a, b) gives the same result as and(a, not(b)), and native MergeRows does not panic.

Additional context

Until Comet moves to arrow 60 (#7249), replacing the two calls with and(a, &not(b)?) fixes it.

Willingness to contribute

I can contribute a fix for this bug independently

主要言語
Scala
スター
1.3k
フォーク
418
平均マージ
2日 23時間
マージ済み PR(30日)
158

環境構築

はじめの一歩

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

apache/datafusion-comet のほかの issue

apache/datafusion-comet の issue をすべて見る

似ている issue

Scala の issue をもっと見る

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

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