[Variant] `variant_get` string and binary cast errors show Rust builder type names

Aperta Adatta ai principianti
#12,214 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #12280 di @Subodh-17 — chiusa senza merge

Valutazione

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

Direzione di ricerca

Leggi parquet-variant-compute/src/variant_to_arrow.rs, in particolare i rami per stringhe e dati binari di define_variant_to_primitive_builder! intorno alle righe collegate nell’issue. Confronta come questi rami formattano gli errori di conversione con gli altri rami. Il lavoro è completato quando gli errori per Utf8, LargeUtf8, Utf8View, Binary, LargeBinary e BinaryView indicano il tipo di dati Arrow richiesto e i test confermano i nomi previsti.

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

Descrizione

bug

Describe the bug

When variant_get cannot convert a value to a string or binary type, the error names the Rust builder type instead of the Arrow data type. Other targets name the data type, such as Int32.

This affects Utf8, LargeUtf8, Utf8View, Binary, LargeBinary, and BinaryView. Reported downstream in datafusion-contrib/datafusion-variant#173, where SELECT parse_json('{"status":200}'):status::VARCHAR shows this message to SQL users.

To Reproduce

Reproduced with arrow, parquet-variant, and parquet-variant-compute 60.1.0:

use std::sync::Arc;

use arrow::array::{ArrayRef, StringArray};
use arrow::compute::CastOptions;
use arrow::datatypes::{DataType, Field};
use parquet_variant::VariantPath;
use parquet_variant_compute::{GetOptions, json_to_variant, variant_get};

fn get_error(json: &str, data_type: DataType) -> String {
    let input: ArrayRef = Arc::new(StringArray::from(vec![json]));
    let variant = ArrayRef::from(json_to_variant(&input).unwrap());
    let options = GetOptions::new_with_path(VariantPath::try_from("status").unwrap())
        .with_as_type(Some(Arc::new(Field::new("result", data_type, true))))
        .with_cast_options(CastOptions {
            safe: false,
            ..Default::default()
        });
    variant_get(&variant, options).unwrap_err().to_string()
}

fn main() {
    println!("{}", get_error(r#"{"status":"n/a"}"#, DataType::Int32));
    println!("{}", get_error(r#"{"status":200}"#, DataType::Utf8));
    println!("{}", get_error(r#"{"status":200}"#, DataType::Utf8View));
    println!("{}", get_error(r#"{"status":200}"#, DataType::Binary));
}

Output:

Cast error: Failed to extract primitive of type Int32 from variant ShortString(ShortString("n/a")) at path VariantPath([])
Cast error: Failed to extract primitive of type arrow_array::builder::generic_bytes_builder::GenericByteBuilder<arrow_array::types::GenericStringType<i32>> from variant Int16(200) at path VariantPath([])
Cast error: Failed to extract primitive of type arrow_array::builder::generic_bytes_view_builder::GenericByteViewBuilder<arrow_array::types::StringViewType> from variant Int16(200) at path VariantPath([])
Cast error: Failed to extract primitive of type arrow_array::builder::generic_bytes_builder::GenericByteBuilder<arrow_array::types::GenericBinaryType<i32>> from variant Int16(200) at path VariantPath([])

Expected behavior

The error names the requested Arrow type, as it does for Int32. For example, Utf8, Utf8View, and Binary for the last three lines above.

Additional context

The string and binary arms of define_variant_to_primitive_builder! pass B::type_name() into the message, while the other arms pass an Arrow DataType. StringLikeArrayBuilder::type_name and BinaryLikeArrayBuilder::type_name are documented as human-readable, but every implementation returns std::any::type_name. These two arms are their only callers. The code is unchanged on main at b2b7d47051.

#10651 tracks the other parts of this message: the hardcoded VariantPath([]) and the Debug formatting of the value. Whether a numeric variant should convert to a string at all is a separate question.

Willingness to contribute

I plan to contribute a fix for this bug independently

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.