Skip to content

[Variant] variant_get cast errors lose the requested path #10651

Open

Description

@sdf-jkl

Describe the bug

Primitive cast errors from variant_get hardcode the path as VariantPath([]).

The value is extracted before being passed to the primitive conversion builder, so the builder no longer knows the original path requested by the caller.

The diagnostic also exposes the Variant value's internal Debug representation. There is an existing TODO to format this more cleanly.

To Reproduce

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};

#[test]
fn variant_get_cast_error_loses_requested_path() {
    let input: ArrayRef =
        Arc::new(StringArray::from(vec![r#"{"a":"n/a"}"#]));
    let variant = ArrayRef::from(json_to_variant(&input).unwrap());

    let options = GetOptions::new_with_path(
        VariantPath::try_from("a").unwrap(),
    )
    .with_as_type(Some(Arc::new(Field::new(
        "result",
        DataType::Int32,
        true,
    ))))
    .with_cast_options(CastOptions {
        safe: false,
        ..Default::default()
    });

    let error = variant_get(&variant, options).unwrap_err();

    assert_eq!(
        error.to_string(),
        r#"Cast error: Failed to extract primitive of type Int32 from variant ShortString(ShortString("n/a")) at path VariantPath([])"#
    );
}

The error reports an empty path even though a was requested.

Expected behavior

The error should report the complete path requested by the caller—in this example, a—and display the offending value cleanly rather than as ShortString(ShortString("n/a")).

For partially shredded values, the reported path should include any prefix already traversed through shredded fields.

Additional context

The error likely needs to be constructed or enriched at a layer that retains the original path. The unshredded fallback receives only the remaining path suffix, which is insufficient to produce the complete path after partially shredded traversal.

Activity

  1. changed the title [-]`variant_get` cast errors lose the requested path[/-] [+][Variant] `variant_get` cast errors lose the requested path[/+] on Aug 11, 2026
  2. HussainQadri commented on Aug 12, 2026

    @HussainQadri

    take — I'll work on preserving the requested VariantPath through cast failures and add regression coverage for the full path including partially shredded traversal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions