-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[Variant] Allow appending raw object/list bytes to variant builders #8141
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
Conversation
alamb
left a comment
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.
The code in this PR looks great. I think it just needs some tests
Very nice
| } | ||
| /// Macro to generate the match statement for each append_variant, try_append_variant, and | ||
| /// append_variant_bytes -- they each have slightly different handling for object and list handling. | ||
| macro_rules! variant_append_value { |
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.
nice
|
While adding the tests, it turns out that I need the read-only metadata builder. Otherwise, there's no way to add (or copy) individual object fields across -- even if the set of strings is the same, they would get newly allocated field ids in the output variant, potentially in a different order. |
|
@alamb -- merged up and using read-only metadata builders now cc @codephage2020 and @klion26 in case you want to make a review pass. |
codephage2020
left a comment
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.
LGTM!
klion26
left a comment
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 for the contribution, LGTM
| /// Macro to generate the match statement for each append_variant, try_append_variant, and | ||
| /// append_variant_bytes -- they each have slightly different handling for object and list handling. | ||
| macro_rules! variant_append_value { | ||
| ($builder:expr, $value:expr, $object_pat:pat => $object_arm:expr, $list_pat:pat => $list_arm:expr) => { |
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.
nice!
| } | ||
|
|
||
| #[test] | ||
| fn test_append_variant_bytes_round_trip() { |
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.
Do we need to add a test case for the Variant::List match arm in append_variant_bytes?
| } | ||
|
|
||
| #[test] | ||
| fn test_complex_nested_filtering_injection() { |
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.
Nice test!
alamb
left a comment
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.
Looks great to me -- thank you @scovich @klion26 and @codephage2020
| /// The caller must ensure that the metadata dictionary is already built and correct for | ||
| /// any objects or lists being appended, but the value's new field name is handled normally. | ||
| /// | ||
| /// # Note |
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.
Is this note still valid? I think there is no inserting of keys that happens via this API
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.
This method creates a new variant object field.
The field's value is raw bytes but the field's key is still inserted normally.
So yes, it can still fail if the key is invalid or duplicate.
|
🚀 |
Which issue does this PR close?
Rationale for this change
When working with shredded variants, we need the ability to copy nested object fields and array elements of one variant to a destination. This is a cheap byte-wise copy that relies on the fact that the new variant being built uses the same metadata dictionary as the source variant it is derived from.
What changes are included in this PR?
Define a helper macro that encapsulates the logic for variant appends, now that we have three very similar methods (differing only in their handling of list/object values and their return type).
Add new methods:
ValueBuilder::append_variant_bytes, which is called by new methodsVariantBuilder::append_value_bytes,ListBuilder::append_value_bytes, andObjectBuilder::[try_]insert_bytes.Are these changes tested?
New unit tests
Are there any user-facing changes?
The new methods are public.