Repository navigation
fix(parquet-variant-compute): reject unsupported types in empty and all-null cast_to_variant input - #12246
Conversation
…val in empty and all-null input
…ll-null cast_to_variant input
sdf-jkl
left a comment
There was a problem hiding this comment.
Thanks @dayan02dev this is great! Could you please address the suggestions below 🙏
| input: &dyn Array, | ||
| options: &CastOptions, | ||
| ) -> Result<VariantArray, ArrowError> { | ||
| // Create row builder for the input array type |
There was a problem hiding this comment.
Could this say why it has to come before the fast path, so it doesn't get moved back for performance later?
| // Create row builder for the input array type | |
| // Build before the all-null fast path so unsupported types fail regardless of contents. |
| } | ||
|
|
||
| #[test] | ||
| fn test_cast_to_variant_duration_or_interval_errors_empty_or_all_null() { |
There was a problem hiding this comment.
This test repeats the type list and error assertion of test_cast_to_variant_duration_or_interval_errors. That test only missed the bug because all its arrays contain a value. I'd fold the new cases into it, generating the empty, all-null, list, struct and union cases from each array's data_type(), so there is one list of unsupported types
There was a problem hiding this comment.
Done in e1f4642. test_cast_to_variant_duration_or_interval_errors now builds the empty and all-null cases from each array's data_type(): as the type itself, as a list element, as a struct field, and as a sparse union child. So the seven types are listed once. The is_err assertion now names the generated type and the row count. The supported-type controls (Int64, List<Int64>, and a union of Int32 and Utf8) sit at the end of the same test. The test still fails without the fix (on List(Duration(s)) with 0 rows), and with only the reorder (on the empty union case).
…all-null cases into the duration/interval test
sdf-jkl
left a comment
There was a problem hiding this comment.
Thanks @dayan02dev this is a very clean fix
Which issue does this PR close?
Rationale for this change
cast_to_variantreturnedOkfor duration/interval types (directly or nested) when the input was empty or all null, and the unsupported-type error as soon as one row held a value. There are two causes:cast_to_variant_with_optionsreturned beforemake_arrow_to_variant_row_builder, which is the only place types are checked.UnionArrowToVariantBuilder::newlooped over the per-rowtype_ids()buffer, so it only built (and type-checked) the children some row selects, and rebuilt that child's builder once per row.Moving the type check before the shortcut, as the issue suggests, fixes the first cause but not the second: an empty union with a duration child, or one whose rows never select that child, is still accepted. So the union loop also changes.
What changes are included in this PR?
append_nullsfast path.union_array.fields().iter()) instead of per row. This matches the comment above the loop and the behaviour before [Variant] Implement row builders for cast_to_variant #8299.#12211 also edits the body of the same union loop, so one of the two will need a small rebase.
Are these changes tested?
Yes.
test_cast_to_variant_duration_or_interval_errorsnow also checks empty and all-null arrays of each of the seven duration/interval types, directly and inside a list, a struct and a sparse union, plus supported controls. Without the fix it fails withList(Duration(s)) with 0 rows; with only the fast-path reorder it still fails on the empty union case.Are there any significant user-facing changes?
InvalidArgumentErroras populated arrays instead ofOk. No signatures change.If you'd rather keep the fast path cost-free for maps, the alternatives are narrowing the map key cast to the offsets range, or a
DataType-only recursive check before the shortcut.AI usage disclosure
The patch, test, verification and the benchmark numbers above were produced with an AI coding agent (Claude Code), and a separate agent session re-checked them before submission.