[Variant] When possible, cast perfectly shredded children - #9862
Conversation
2de441e to
23b785d
Compare
23b785d to
e154a22
Compare
|
Ok seems like some tests are not fully deterministic and I missed that. |
e154a22 to
fb87e3d
Compare
11538b5 to
e01c2da
Compare
| } | ||
|
|
||
| None | ||
| match from_type { |
There was a problem hiding this comment.
Seems this overlaps with can_cast_types? can we simplify this
There was a problem hiding this comment.
yeah there's definitely overlap and a very similar structure, but I think we have to do this while the cast behaviors don't match.
There was a problem hiding this comment.
another options is just allow everything that arrow supports in the perfect cast case, and work to align the other cases enumerated in #8982 (comment)
There was a problem hiding this comment.
As we will align the logic between variant and arrow-cast, does this mean we can only keep the logic can_cast_types above? If can_cast_types returns tru,e we'll always try to do the cast
|
|
||
| #[test] | ||
| fn test_perfect_shredding_list_cast_gate_uses_variant_element_semantics() { | ||
| let int64_item = Arc::new(Field::new("item", DataType::Int64, true)); |
There was a problem hiding this comment.
Do we need to add more tests to cover the logic of can_use_perfect_shredding_arrow_cast here?
| variant_array: &VariantArray, | ||
| as_field: &Field, | ||
| cast_options: &CastOptions, | ||
| ) -> Result<Option<ArrayRef>> { |
There was a problem hiding this comment.
Why do we need the Result in the return value? Is it ok to use Option<arrayRef> here?
There was a problem hiding this comment.
there's a couple of thins here that do return a Result, I'll push a fix here soon
There was a problem hiding this comment.
Here we still keep the Result, 1) seems we can replace with Option<ArrayRef> if we don't change the code in L284; 2) the code here changed the logic because if we throw an error here, then in L284 we will return directly(a minimal rust-play)
|
|
||
| // Use Arrow's vectorized cast when it cleanly matches the shredded representation. If not, | ||
| // fall back to row-wise extraction to preserve the existing variant-specific semantics. | ||
| Ok(cast_with_options(target_array.as_ref(), as_field.data_type(), cast_options).ok()) |
There was a problem hiding this comment.
Does this mean that cast_with_options throws some error if the return value here is None? do we need to add some tests to cover this
Signed-off-by: Adam Gutglick <adam@spiraldb.com>
e01c2da to
a8279d4
Compare
|
I think its much better to just get to the point we align the casting behaviors instead of trying to pick and choose, so I'm closing this PR. Once we have full alignment there's a small subset for perfect shredding, happy to either re-open this one or open another one when we reach that point. |
Which issue does this PR close?
variant_getto cast kernel #8982Rationale for this change
For cases we can just cast the perfectly shredded array, this is a significant performance boost, we do that only for a subset of types where arrow's casting matches the existing cast behavior in
parquet-variant-compute.One issue here is that the casting behavior is slightly different, but that seems aligned with #8982 and other work.What changes are included in this PR?
If an array is perfectly shredded AND can be cast according to the existing cast semantics, we cast it instead of falling back to the row builder.
Are these changes tested?
In addition to existing tests, added an additional test to make sure it works.
Are there any user-facing changes?
None.