-
Notifications
You must be signed in to change notification settings - Fork 1k
[Variant] Add variant to arrow for DataType::{Utf8, LargeUtf8} and DataType::Binary
#8768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
6e5c476 to
d4f068a
Compare
b745c38 to
109612e
Compare
|
@mbrobbel Thanks for the quick review. As the primitive builder for Appended two commits
|
DataType::{Utf8, LargeUtf8}DataType::{Utf8, LargeUtf8} and DataType::Binary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @klion26, the additional changes look good to me too.
| Date(VariantToPrimitiveArrowRowBuilder<'a, datatypes::Date32Type>), | ||
| Utf8(VariantToUtf8ArrowRowBuilder<'a, i32>), | ||
| LargeUtf8(VariantToUtf8ArrowRowBuilder<'a, i64>), | ||
| Binary(VariantToBinaryArrowRowBuilder<'a>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we already have a binary builder here, how about reusing it? Perhaps just change this line to make it work
Plus, this builder is called PrimitiveVariantToArrowRowBuilder but String and binary are not primitive type. So I think we need either rename the builder or put them into a new builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, the logic of VariantToBinaryVariantArrowRowBuilder is different from the Binary here, the VariantToBinaryVariantArrowRowBuilder is for the raw Variant, and here we want to process for Variant::Binary. I tried reuse the VariantToBinaryVariantArrowRowBuilder, it will contains the meta and other things also, we only need the binary value here.
And for the builder, please correct me if I'm wrong, the primitive here is for variant, not for the DataTypes, we put Null/Boolean/ Uuid in here also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed on the first one as we may not need metadata column if explicitly cast to Binary.
For the 2nd, I think the primitive is for arrow because we check is_primitive and will throw error if the request data type is not primitive here. Also based on the definition here, this builder is to convert variant values to primitive arrow. Given that, having Null/Boolean/Uuid in this builder makes the intent tricky. I’d prefer we rename the builder and update the docs as needed. We don't need a separate builder tho as we can reuse a lot of codes here.
For Variant primitive, we had a related discussion before. I think Parquet enforces primitive types at write time and unshred to ensure valid data. But for variant_get, it’s reasonable to allow casting to any valid Arrow datatype, even those without a direct Variant-primitive counterpart (e.g., Decimal256 or LargeUtf8).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the builder is transform some variant to arrow type, and the Variant has primitive/shortstring/object/list types, Here we want to handle the types for Variant::Primitive(include shortstring) types, in shred_variant::make_variant_to_shredded_variant_arrow_row_builder/variant_to_arrow#make_variant_to_arrow_row_builder we have other match arms(for objects/lists), the whole match arms will equal to all variant types.
For
check is_primitive and will throw error if the request data type is not primitive
I think this is for NotYetImplementation Error
And have an expert to confirm this is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we already have a binary builder here, how about reusing it? Perhaps just change this line to make it work
The VariantToBinaryVariantArrowRowBuilder converts shredded variant to unshredded (binary) variant.
Here, we need a builder that can extract Variant::Binary values into a BinaryArray, with nulls (or errors) wherever the variant was not (convertible to) binary.
I believe this PR correctly does the latter, but only for DataType::Binary. It leaves out DataType::BinaryView, DataType::LargeBinary and DataType::FixedSizeBinary.
The first three can all be covered by a single generic builder, by defining a new BinaryLikeArrayBuilder trait. It would be very similar to the StringLikeArrayBuilder trait that #8600 already added for the same reason.
It's debatable whether we actually need fixed-size binary support. If we did support it, it would need a custom builder whose extraction would presumably fail for any Variant::Binary with the wrong length?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the confusion comes from variant_get and shred_variant sharing variant_to_arrow.
variant_getshould allow casting to any valid Arrow type.shred_variantshould follow the shredding spec (only Parquet primitives + list/struct).
My advice:
- Add type checks in
shred_variantto enforce the spec. - Keep
variant_to_arrowa pure converter (the inverse ofarrow_to_variant).
Created an issue #8795 to keep track of.
Overall, no blockers from my side. I’ll submit a follow-up PR to fix the docs. It would also be great to add support for LargeBinary and BinaryView either in this PR or a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add LargeBinary and BinaryView and update the pr.
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.
What changes are included in this PR?
VariantToUtf8ArrowRowBuilder<'a, OffsetSizeTrait>, a structVariantToBinaryRowBuilder<'a>Utf8(VariantToUtf8ArrowRowBuilder<'a, i32>)andLargeUtf8(VariantToUtf8ArrowRowBuilder<'a, i64>)forPrimitiveVariantToArrowRowBuilderAre these changes tested?
Added new tests
Are there any user-facing changes?
No public API changed