[Variant] Safe cast_to_variant failures produce Variant null instead of Arrow null

Aperta
#11,939 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #11978 di @ump45nose — chiusa senza merge

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
databases

Direzione di ricerca

Read parquet-variant-compute/src/arrow_to_variant.rs around the safe conversion failure branch and the timestamp overflow test in parquet-variant-compute/src/cast_to_variant.rs. Compare the output validity behavior with Arrow's cast kernel and the issue's expected behavior. Done means safe top-level failures produce null rows, valid values and input nulls retain their behavior, and unsafe conversion still errors.

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

Descrizione

bug

Describe the bug

cast_to_variant_with_options with CastOptions { safe: true, .. } encodes conversion failures as Variant::Null while leaving the output row valid. Arrow's cast kernel marks failed conversions null in the output array, as documented by CastOptions::safe.

Found while implementing Spark-compatible SQL TRY_CAST(... AS VARIANT) in datafusion-variant. Spark documents TRY_CAST as returning SQL NULL on runtime conversion errors, including overflow. Downstream code must currently convert these failed results to SQL NULL explicitly.

To Reproduce

Reproduced with arrow = "60.0.0" and parquet-variant-compute = "60.0.0":

use arrow::array::{Array, TimestampSecondArray};
use arrow::compute::{CastOptions, cast_with_options};
use arrow::datatypes::{DataType, TimeUnit};
use parquet_variant_compute::cast_to_variant_with_options;

fn main() {
    let input = TimestampSecondArray::from(vec![Some(i64::MAX), Some(0), None]);
    let options = CastOptions { safe: true, ..Default::default() };

    let arrow = cast_with_options(
        &input,
        &DataType::Timestamp(TimeUnit::Microsecond, None),
        &options,
    ).unwrap();
    let variant = cast_to_variant_with_options(&input, &options).unwrap();

    println!("Arrow overflow is null: {}", arrow.is_null(0));
    println!("Variant overflow is null: {}", variant.is_null(0));
    println!("Variant overflow value: {:?}", variant.value(0));
    assert!(!variant.is_null(1));
    assert!(variant.is_null(2));
    assert!(arrow.is_null(0));
    assert!(variant.is_null(0)); // Fails: overflow is encoded as Variant::Null.
}

Output before the assertion failure:

Arrow overflow is null: true
Variant overflow is null: false
Variant overflow value: Null

Expected behavior

For a failed top-level conversion with safe: true, mark the output row null, matching Arrow's cast kernel. Valid conversions and input nulls should retain their current behavior; safe: false should continue to return an error.

Additional context

Source inspection of main at 5746b443f7 confirms the same behavior: the failure branch appends Variant::Null, and the timestamp overflow test expects it.

The original discussion in #8059 proposed setting the array element null on overflow, following Arrow's cast model. A later discussion in #8233 suggested Variant::Null instead of None. #8984 subsequently unified the options with Arrow's CastOptions while preserving behavior.

Lingua principale
Rust
Stelle
3.7k
Fork
1.5k
Merge medio
2g 16h
PR unite (30g)
183

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/arrow-rs

Tutte le issue di apache/arrow-rs

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.