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

Aperta Adatta ai principianti
#7,596 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust, scala, spark
Ambito
backend, databases

Direzione di ricerca

Inizia in merge_rows.rs, intorno alle righe 625–626, e segui come MergeRowsStream costruisce le maschere delle righe senza corrispondenza. Riproduci il comportamento di Arrow 59 con l’esempio fornito di array suddiviso, poi verifica che le maschere corrispondano a and(a, not(b)) e che MergeRows nativo non vada più in panico; la issue suggerisce di sostituire le due chiamate a and_not come soluzione temporanea.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Scala
Stelle
1.3k
Fork
418
Merge medio
2g 23h
PR unite (30g)
158

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/datafusion-comet

Tutte le issue di apache/datafusion-comet

Issue simili

Altre issue su Scala

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.