[Variant] Support Shredded Lists/Array in variant_get#9049
[Variant] Support Shredded Lists/Array in variant_get#9049alamb merged 4 commits intoapache:mainfrom
variant_get#9049Conversation
scovich
left a comment
There was a problem hiding this comment.
I only had a few minutes to skim, and I couldn't tell quickly what was code movement vs. actual changes. Would there be a way to split them out into separate commits or something? Or at least describe clearly what moved vs. what changed?
The second commit in the stack was helpful that way, but the first commit still seemed to do an awful lot.
I am also happy to help review / quickly merge a PR that is just code movement |
136640a to
649cfcf
Compare
klion26
left a comment
There was a problem hiding this comment.
LGTM, Maybe we can create an issue to track the VariantPathElement::Index case.
| } | ||
|
|
||
| #[test] | ||
| fn test_variant_get_list_like_safe_cast() { |
There was a problem hiding this comment.
Do we need to add some cases for that with VariantPathElement::Field(We don't support VariantPathElement::Index in the current pr) or some perfectly shredded case
When trying to use shred_variant to generate some perfectly shredded cases, I found that the member variable value is not null for the return value of shred_variant. Is this the expected behavior? According to the parquet-vairant-spec
If the value is not an array, typed_value must be null. If the value is an array, value must be null.
There was a problem hiding this comment.
Good idea, I will add some tests for VariantPathElement::Field.
For shred_variant, I think the following test covers the behavior in the spec.
arrow-rs/parquet-variant-compute/src/shred_variant.rs
Lines 1193 to 1242 in 802b890
We can make some changes to the test to verify that the value would be an array of None if the input is a perfectly shredded list array,
#[test]
fn test_array_shredding_as_list() {
let input = build_variant_array(vec![
VariantRow::List(vec![
VariantValue::from(1i64),
VariantValue::from(2i64),
VariantValue::from(3i64),
]),
VariantRow::List(vec![
VariantValue::from(1i64),
VariantValue::from(2i64),
VariantValue::from(3i64),
]),
VariantRow::List(vec![
VariantValue::from(1i64),
VariantValue::from(2i64),
VariantValue::from(3i64),
]),
VariantRow::List(vec![
VariantValue::from(1i64),
VariantValue::from(2i64),
VariantValue::from(3i64),
]),
]);
let list_schema = DataType::List(Arc::new(Field::new("item", DataType::Int64, true)));
let result = shred_variant(&input, &list_schema).unwrap();
assert_eq!(result.len(), 4);
assert_list_structure_and_elements::<Int64Type, i32>(
&result,
4, // expected length
&[0, 3, 6, 9, 12], // expected offsets
&[Some(3), Some(3), Some(3), Some(3)], // expected sizes
&[None, None, None, None], // `value`
(
&[
Some(1),
Some(2),
Some(3),
Some(1),
Some(2),
Some(3),
Some(1),
Some(2),
Some(3),
Some(1),
Some(2),
Some(3),
], // `typed_values...typed_value`
&[
None, None, None, None, None, None, None, None, None, None, None, None,
], // `typed_values...value`
), // `typed_value`
);
}There was a problem hiding this comment.
Ah, yes, thanks for pointing this(shred_variant) out, please ignore my previous comment.
|
Thanks for the PR @liamzwbao and for the review @klion26 |
# Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. --> - Followup of #9049. # Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> # What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> Add tests of path index access for list in `variant_get` to address the comment #9049 (review) # Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Yes # Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please call them out. --> No
Which issue does this PR close?
variant_get#8082.Rationale for this change
What changes are included in this PR?
ArrayVariantToArrowRowBuilderfromshred_varianttovariant_to_arrowso it can be shared withvariant_get.variant_to_arrowto clarify the hierarchy: start with the top-levelVariantToArrowRowBuilder, then second-level builders such asPrimitiveVariantToArrowRowBuilderandArrayVariantToArrowRowBuilder, etc.variant_getwith lists.Are these changes tested?
Yes
Are there any user-facing changes?
variant_getnow supports lists.