[Variant] `variant_get` cast errors lose the requested path
- Dominant language
- Rust
- Stars
- 3.6k
- Forks
- 1.3k
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 168
Description
### 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
```rust
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.
Contributor guide
Research direction
Start with the variant_get entry point and the provided variant_get_cast_error_loses_requested_path reproduction, then trace GetOptions and the unshredded fallback through primitive conversion. Ensure cast errors retain the complete requested path, including shredded prefixes, and format the offending Variant value cleanly; the reproduction should pass with the expected wording.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100