You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "scovich (via GitHub)" <gi...@apache.org> on 2025/09/11 16:48:31 UTC
[PR] [Variant] Support custom variant builder parent state [arrow-rs]
scovich opened a new pull request, #8324:
URL: https://github.com/apache/arrow-rs/pull/8324
# 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.
- Closes #NNN.
# Rationale for this change
The `ParentState` class, combined with `VariantBuilderExt` trait, makes it pretty easy to work with variant builders. But it only works for "well-known" builder types -- which does not and cannot include the `VariantArrayBuilder` because it lives in a different crate.
This becomes a problem for e.g. https://github.com/apache/arrow-rs/issues/8323, because it's currently impossible to append multiple values to a `VariantArrayBuilder` -- it needs to create and `finish` one`VariantArrayVariantBuilder` adapter for each appended value.
Plus, we will eventually need a `VariantValueArrayBuilder` that works with read-only metadata, for shredding, unshredding, and projecting variant values. Which will undoubtedly encounter the same sorts of problems, since shredding and unshredding code relies heavily on `VariantBuilderExt`.
# What changes are included in this PR?
Make `ParentState` customizable, which allows `VariantArrayBuilder` to directly implement `VariantBuilderExt`. This simplifies both the array builder's implementation and the code that uses it, and also opens the way for other custom builders like the `VariantValueArrayBuilder` we will eventually need.
NOTE: One (serious) downside of this approach is the use of a boxed trait instance. This effectively requires a heap allocation (and virtual method dispatch) for every single value appended to a variant array, which I really don't love.
If we don't like the overhead of the boxed trait approach, alternatives I've considered include:
* Add new parent state enum variants for each new type of `VariantBuilderExt`, even those that come from other crates.
* PRO: The least amount of code of any alternative I've considered
* PRO: Zero additional overhead compared to "native" types
* CON: Architectural violation to make parquet-variant crate (at least somewhat) aware of parquet-variant-compute crate that depends on it.
* Make the various builder classes generic, and change `ParentState` to a (not dyn-compat) trait that becomes a type constraint for those classes.
* NOTE: `VariantBuilderExt` is already not dyn-compat
* PRO: Even _less_ overhead than what we have today, because we no longer need enum variant dispatch all over the place
* CON: A lot of code churn to make all the necessary classes generic. Tho it's unclear how much that will actually impact users of the API. Messy library code isn't necessarily bad, as long as it has a clean user surface.
* CON: Each impl would have to define _all_ trait fields and nearly all methods -- even the ones that are the same for every impl -- to avoid running afoul of the rust borrow checker. The same borrow checker issues are why every `ParentState` enum variant defines the same half dozen fields over and over, in addition to any variant-specific extra state.
# Are these changes tested?
Yes, many unit tests were updated to use the new approach instead of the old (removed) approach.
# Are there any user-facing changes?
No, because variant support is still experimental, but:
* `ParentState` has a new enum variant that references a new public `CustomParentState` trait, with corresponding new `ParentState::custom` constructor for it.
* `VariantArrayBuilder` now implements `VariantBuilderExt` directly, and the old `VariantArrayVariantBuilder` adapter class has been removed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3281948458
@alamb I would be interested in your reaction to the approach in this PR vs. the potential alternatives?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282596573
> * CON: Each impl would have to define _all_ trait fields and nearly all methods -- even the ones that are the same for every impl -- to avoid running afoul of the rust borrow checker. The same borrow checker issues are why every `ParentState` enum variant defines the same half dozen fields over and over, in addition to any variant-specific extra state.
I just realized, I must have misunderstood something. The fact that `CustomParentState` approach actually _works_, especially the `ArrayBuilderState`, suggests that the borrow checker is only a problem if the mut references are being taken by different functions?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282008018
🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/scripts/gh_compare_arrow.sh) Running
Linux aal-dev 6.14.0-1014-gcp #15~24.04.1-Ubuntu SMP Fri Jul 25 23:26:08 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing variant-builder-custom-state (1110bb305ddf22759f92231f5d567f8d77a02023) to 7e38bbb0c9f0d4379fe109884c90ab2254ce86af [diff](https://github.com/apache/arrow-rs/compare/7e38bbb0c9f0d4379fe109884c90ab2254ce86af..1110bb305ddf22759f92231f5d567f8d77a02023)
BENCH_NAME=variant_builder
BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench variant_builder
BENCH_FILTER=
BENCH_BRANCH_NAME=variant-builder-custom-state
Results will be posted here when complete
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3288145130
🤖: Benchmark completed
<details><summary>Details</summary>
<p>
```
group main variant-builder-custom-state
----- ---- ----------------------------
bench_validate_complex_object 1.05 242.1±0.45µs ? ?/sec 1.00 229.6±0.27µs ? ?/sec
bench_validate_large_nested_list 1.00 19.0±0.04ms ? ?/sec 1.00 18.9±0.03ms ? ?/sec
bench_validate_large_object 1.00 55.6±0.06ms ? ?/sec 1.00 55.5±0.08ms ? ?/sec
```
</p>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282058226
🤖: Benchmark completed
<details><summary>Details</summary>
<p>
```
group main variant-builder-custom-state
----- ---- ----------------------------
bench_extend_metadata_builder 1.00 61.8±4.60ms ? ?/sec 1.07 66.0±3.63ms ? ?/sec
bench_object_field_names_reverse_order 1.00 21.9±0.67ms ? ?/sec 1.01 22.2±1.08ms ? ?/sec
bench_object_list_partially_same_schema 1.00 1277.9±29.72µs ? ?/sec 1.00 1276.6±16.12µs ? ?/sec
bench_object_list_same_schema 1.01 25.6±0.21ms ? ?/sec 1.00 25.4±0.19ms ? ?/sec
bench_object_list_unknown_schema 1.00 13.9±0.15ms ? ?/sec 1.00 14.0±0.11ms ? ?/sec
bench_object_partially_same_schema 1.00 3.4±0.01ms ? ?/sec 1.00 3.3±0.01ms ? ?/sec
bench_object_same_schema 1.00 38.9±0.20ms ? ?/sec 1.01 39.3±0.11ms ? ?/sec
bench_object_unknown_schema 1.01 16.5±0.04ms ? ?/sec 1.00 16.3±0.04ms ? ?/sec
iteration/unvalidated_fallible_iteration 1.00 2.7±0.00ms ? ?/sec 1.00 2.7±0.01ms ? ?/sec
iteration/validated_iteration 1.00 49.3±0.06µs ? ?/sec 1.01 49.7±0.39µs ? ?/sec
validation/unvalidated_construction 1.00 6.7±0.01µs ? ?/sec 1.00 6.7±0.01µs ? ?/sec
validation/validated_construction 1.05 63.5±0.11µs ? ?/sec 1.00 60.6±0.10µs ? ?/sec
validation/validation_cost 1.00 56.8±0.06µs ? ?/sec 1.04 59.3±0.12µs ? ?/sec
```
</p>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3281990440
> CON: Architectural violation to make parquet-variant crate (at least somewhat) aware of parquet-variant-compute crate that depends on it.
Another potential option is to move some/all the specialized builder code into the parquet-variant crate 🤔
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282041331
> > > CON: Architectural violation to make parquet-variant crate (at least somewhat) aware of parquet-variant-compute crate that depends on it.
> >
> >
> > Another potential option is to move some/all the specialized builder code into the parquet-variant crate 🤔
>
> Moving `VariantArrayBuilder` to from parquet-variant-compute to parquet-variant crate would indeed resolve the architectural violation. Is that even such a bad thing?
It doesn't seem like a bad idea to me, to be honest.
The only potential issue would be people who wanted to use parquet-variant without the dependency on arrow (I am only theorizing here, I don't know if that is actually an important usecase).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3284611054
> >
>
> @alamb is this really a common pattern? Is there a better way to import just `ArrowError`? Or nobody cares because the crate is anyway super lightweight (with no required dependencies on other crates)
If you really need just ArrowError arrow_schema is a fine way to do it
I think it is more common to use arrow_schema for ArrowError and DataType
I think parquet-variant uses ArrowError at the moment for convenience. Its own error type like `VariantError` probably makes sense long term
We could add a `From` impls for ArrowError and it would be pretty easy to switch back and forth
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3281995270
> > CON: Architectural violation to make parquet-variant crate (at least somewhat) aware of parquet-variant-compute crate that depends on it.
>
> Another potential option is to move some/all the specialized builder code into the parquet-variant crate 🤔
Moving `VariantArrayBuilder` to from parquet-variant-compute to parquet-variant crate would indeed solve the problem. Is that even such a bad thing?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#discussion_r2341854191
##########
parquet-variant/src/builder.rs:
##########
@@ -709,6 +727,14 @@ pub enum ParentState<'a> {
saved_fields_size: usize,
finished: bool,
},
+ Custom {
+ value_builder: &'a mut ValueBuilder,
+ saved_value_builder_offset: usize,
+ metadata_builder: &'a mut dyn MetadataBuilder,
+ saved_metadata_builder_dict_size: usize,
+ state: Box<dyn CustomParentState + 'a>,
Review Comment:
👍 makes sense to me
I wonder if we should go even farther and change parent state to *only* have a ` state: Box<dyn CustomParentState + 'a>,` (and not different variants for Variant, List, Object, etc)
That might simplify things even more, however, it would have the downside of adding allocation / dispatch for everything 🤔
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#discussion_r2343716660
##########
parquet-variant/src/builder.rs:
##########
@@ -679,55 +734,46 @@ impl<S: AsRef<str>> Extend<S> for WritableMetadataBuilder {
///
/// The redundancy in `value_builder` and `metadata_builder` is because all the references come from
/// the parent, and we cannot "split" a mutable reference across two objects (parent state and the
-/// child builder that uses it). So everything has to be here. Rust layout optimizations should
-/// treat the variants as a union, so that accessing a `value_builder` or `metadata_builder` is
-/// branch-free.
+/// child builder that uses it). So everything has to be here.
#[derive(Debug)]
-pub enum ParentState<'a> {
- Variant {
- value_builder: &'a mut ValueBuilder,
- saved_value_builder_offset: usize,
- metadata_builder: &'a mut dyn MetadataBuilder,
- saved_metadata_builder_dict_size: usize,
- finished: bool,
- },
- List {
- value_builder: &'a mut ValueBuilder,
- saved_value_builder_offset: usize,
- metadata_builder: &'a mut dyn MetadataBuilder,
- saved_metadata_builder_dict_size: usize,
- offsets: &'a mut Vec<usize>,
- saved_offsets_size: usize,
- finished: bool,
- },
- Object {
- value_builder: &'a mut ValueBuilder,
- saved_value_builder_offset: usize,
- metadata_builder: &'a mut dyn MetadataBuilder,
- saved_metadata_builder_dict_size: usize,
- fields: &'a mut IndexMap<u32, usize>,
- saved_fields_size: usize,
- finished: bool,
- },
+pub struct ParentState<'a> {
+ value_builder: &'a mut ValueBuilder,
Review Comment:
to be honest, I prefer the previous version which avoided allocations for the most part.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3284635551
🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/scripts/gh_compare_arrow.sh) Running
Linux aal-dev 6.14.0-1014-gcp #15~24.04.1-Ubuntu SMP Fri Jul 25 23:26:08 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing variant-builder-custom-state (b3fcddece7d16b6555c2dc8411f8af6da2a92c4a) to 7e38bbb0c9f0d4379fe109884c90ab2254ce86af [diff](https://github.com/apache/arrow-rs/compare/7e38bbb0c9f0d4379fe109884c90ab2254ce86af..b3fcddece7d16b6555c2dc8411f8af6da2a92c4a)
BENCH_NAME=variant_builder
BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench variant_builder
BENCH_FILTER=
BENCH_BRANCH_NAME=variant-builder-custom-state
Results will be posted here when complete
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3284619060
🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/scripts/gh_compare_arrow.sh) Running
Linux aal-dev 6.14.0-1014-gcp #15~24.04.1-Ubuntu SMP Fri Jul 25 23:26:08 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing variant-builder-custom-state (b3fcddece7d16b6555c2dc8411f8af6da2a92c4a) to 7e38bbb0c9f0d4379fe109884c90ab2254ce86af [diff](https://github.com/apache/arrow-rs/compare/7e38bbb0c9f0d4379fe109884c90ab2254ce86af..b3fcddece7d16b6555c2dc8411f8af6da2a92c4a)
BENCH_NAME=variant_kernels
BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench variant_kernels
BENCH_FILTER=
BENCH_BRANCH_NAME=variant-builder-custom-state
Results will be posted here when complete
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on code in PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#discussion_r2342271492
##########
parquet-variant/src/builder.rs:
##########
@@ -709,6 +727,14 @@ pub enum ParentState<'a> {
saved_fields_size: usize,
finished: bool,
},
+ Custom {
+ value_builder: &'a mut ValueBuilder,
+ saved_value_builder_offset: usize,
+ metadata_builder: &'a mut dyn MetadataBuilder,
+ saved_metadata_builder_dict_size: usize,
+ state: Box<dyn CustomParentState + 'a>,
Review Comment:
Found the problems:
1. It wasn't safe for list and object parent state constructors to delegate to the normal constructor, because they make eager changes (which happens before invoking the delegated constructor and causes the wrong offsets to be captured). Fixed by directly creating the parent state, instead of delegating to the other constructor.
2. There was a subtle design flaw in the original `CustomParentState::finish` -- it was overfitted to the `VariantArrayBuilder` case, and called `metadata_builder.finish()` -- which no other builder wants to do. FIxed by changing the signature to just pass the builders, instead of finished offsets.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282069170
Re `bench_extend_metadata_builder` 11% slower:
That doesn't make sense -- it doesn't even build variant values in the first place? It's just pre-registering field names on a `VariantBuilder` that doesn't even use custom parent state??
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282020513
🤖: Benchmark completed
<details><summary>Details</summary>
<p>
```
group main variant-builder-custom-state
----- ---- ----------------------------
bench_extend_metadata_builder 1.00 57.4±3.39ms ? ?/sec 1.11 63.6±3.15ms ? ?/sec
bench_object_field_names_reverse_order 1.02 21.1±0.92ms ? ?/sec 1.00 20.6±1.26ms ? ?/sec
bench_object_list_partially_same_schema 1.00 1274.1±21.53µs ? ?/sec 1.00 1280.4±21.61µs ? ?/sec
bench_object_list_same_schema 1.01 25.4±0.24ms ? ?/sec 1.00 25.2±0.24ms ? ?/sec
bench_object_list_unknown_schema 1.00 13.7±0.18ms ? ?/sec 1.01 13.8±0.17ms ? ?/sec
bench_object_partially_same_schema 1.00 3.3±0.01ms ? ?/sec 1.01 3.3±0.01ms ? ?/sec
bench_object_same_schema 1.00 38.7±0.09ms ? ?/sec 1.02 39.3±0.23ms ? ?/sec
bench_object_unknown_schema 1.00 16.2±0.14ms ? ?/sec 1.00 16.3±0.04ms ? ?/sec
iteration/unvalidated_fallible_iteration 1.00 2.7±0.01ms ? ?/sec 1.00 2.7±0.01ms ? ?/sec
iteration/validated_iteration 1.01 49.5±0.54µs ? ?/sec 1.00 49.1±0.19µs ? ?/sec
validation/unvalidated_construction 1.01 6.7±0.01µs ? ?/sec 1.00 6.7±0.01µs ? ?/sec
validation/validated_construction 1.00 61.1±0.13µs ? ?/sec 1.00 60.9±0.14µs ? ?/sec
validation/validation_cost 1.01 54.6±0.08µs ? ?/sec 1.00 54.2±0.06µs ? ?/sec
```
</p>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3288321333
Looks great and the performance seems like they are even a little faster. 🚀 thank you so much @scovich
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3288138256
🤖: Benchmark completed
<details><summary>Details</summary>
<p>
```
group main variant-builder-custom-state
----- ---- ----------------------------
batch_json_string_to_variant json_list 8k string 1.11 27.8±0.10ms ? ?/sec 1.00 25.1±0.17ms ? ?/sec
batch_json_string_to_variant random_json(2633 bytes per document) 1.00 303.7±0.54ms ? ?/sec 1.02 309.4±6.90ms ? ?/sec
batch_json_string_to_variant repeated_struct 8k string 1.06 7.9±0.06ms ? ?/sec 1.00 7.4±0.02ms ? ?/sec
variant_get_primitive 1.00 619.5±1.78ns ? ?/sec 1.00 618.2±3.92ns ? ?/sec
```
</p>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on code in PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#discussion_r2344603044
##########
parquet-variant-compute/src/variant_array_builder.rs:
##########
@@ -26,27 +26,6 @@ use parquet_variant::{
use parquet_variant::{ParentState, ValueBuilder, WritableMetadataBuilder};
use std::sync::Arc;
-/// Builder-specific state for array building that manages array-level offsets and nulls
-#[derive(Debug)]
-struct ArrayBuilderState<'a> {
Review Comment:
I just moved this code down to `impl VariantBuilderExt` that actually uses it. It seems better to have the actual array builder be the first class defined in this module.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3288144407
🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/scripts/gh_compare_arrow.sh) Running
Linux aal-dev 6.14.0-1014-gcp #15~24.04.1-Ubuntu SMP Fri Jul 25 23:26:08 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing variant-builder-custom-state (f636d6f7cc14c49a04a45a91e2b57b2169c0c80a) to 7e38bbb0c9f0d4379fe109884c90ab2254ce86af [diff](https://github.com/apache/arrow-rs/compare/7e38bbb0c9f0d4379fe109884c90ab2254ce86af..f636d6f7cc14c49a04a45a91e2b57b2169c0c80a)
BENCH_NAME=variant_validation
BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench variant_validation
BENCH_FILTER=
BENCH_BRANCH_NAME=variant-builder-custom-state
Results will be posted here when complete
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on code in PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#discussion_r2341888610
##########
parquet-variant/src/builder.rs:
##########
@@ -709,6 +727,14 @@ pub enum ParentState<'a> {
saved_fields_size: usize,
finished: bool,
},
+ Custom {
+ value_builder: &'a mut ValueBuilder,
+ saved_value_builder_offset: usize,
+ metadata_builder: &'a mut dyn MetadataBuilder,
+ saved_metadata_builder_dict_size: usize,
+ state: Box<dyn CustomParentState + 'a>,
Review Comment:
The thought also crossed my mind. I initially discarded it because it seemed bad to make those existing uses slower as well... but thinking more, the overheads will mostly hurt code that builds top-level primitive variant values -- once we get into complex types, there will be plenty of other overheads to hide this small one.
Given that this PR (unfortunately) penalizes that fastest-path case, it probably wouldn't hurt (much) to make the more complex slow-path cases use the same approach?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on code in PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#discussion_r2342152065
##########
parquet-variant/src/builder.rs:
##########
@@ -709,6 +727,14 @@ pub enum ParentState<'a> {
saved_fields_size: usize,
finished: bool,
},
+ Custom {
+ value_builder: &'a mut ValueBuilder,
+ saved_value_builder_offset: usize,
+ metadata_builder: &'a mut dyn MetadataBuilder,
+ saved_metadata_builder_dict_size: usize,
+ state: Box<dyn CustomParentState + 'a>,
Review Comment:
... and I also apparently broke something. Debugging.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3284654230
🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/scripts/gh_compare_arrow.sh) Running
Linux aal-dev 6.14.0-1014-gcp #15~24.04.1-Ubuntu SMP Fri Jul 25 23:26:08 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing variant-builder-custom-state (b3fcddece7d16b6555c2dc8411f8af6da2a92c4a) to 7e38bbb0c9f0d4379fe109884c90ab2254ce86af [diff](https://github.com/apache/arrow-rs/compare/7e38bbb0c9f0d4379fe109884c90ab2254ce86af..b3fcddece7d16b6555c2dc8411f8af6da2a92c4a)
BENCH_NAME=variant_validation
BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench variant_validation
BENCH_FILTER=
BENCH_BRANCH_NAME=variant-builder-custom-state
Results will be posted here when complete
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282020653
🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/scripts/gh_compare_arrow.sh) Running
Linux aal-dev 6.14.0-1014-gcp #15~24.04.1-Ubuntu SMP Fri Jul 25 23:26:08 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing variant-builder-custom-state (1110bb305ddf22759f92231f5d567f8d77a02023) to 7e38bbb0c9f0d4379fe109884c90ab2254ce86af [diff](https://github.com/apache/arrow-rs/compare/7e38bbb0c9f0d4379fe109884c90ab2254ce86af..1110bb305ddf22759f92231f5d567f8d77a02023)
BENCH_NAME=variant_validation
BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench variant_validation
BENCH_FILTER=
BENCH_BRANCH_NAME=variant-builder-custom-state
Results will be posted here when complete
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282328661
> Also re benchmarks: Do we even _have_ any benchmarks for appending primitive numeric values to a `VariantArrayBuilder`? Because that's the case that would expose the increased overhead, if any would.
Not sure -- I agree let's not hold up this PR to look into the one benchmark report
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3284635366
🤖: Benchmark completed
<details><summary>Details</summary>
<p>
```
group main variant-builder-custom-state
----- ---- ----------------------------
batch_json_string_to_variant json_list 8k string 1.00 27.6±0.12ms ? ?/sec 1.19 32.8±0.21ms ? ?/sec
batch_json_string_to_variant random_json(2633 bytes per document) 1.00 305.5±0.56ms ? ?/sec 1.11 337.9±0.65ms ? ?/sec
batch_json_string_to_variant repeated_struct 8k string 1.00 7.9±0.01ms ? ?/sec 1.03 8.1±0.02ms ? ?/sec
variant_get_primitive 1.00 620.0±1.35ns ? ?/sec 1.00 621.1±0.79ns ? ?/sec
```
</p>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3288131550
🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/scripts/gh_compare_arrow.sh) Running
Linux aal-dev 6.14.0-1014-gcp #15~24.04.1-Ubuntu SMP Fri Jul 25 23:26:08 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing variant-builder-custom-state (f636d6f7cc14c49a04a45a91e2b57b2169c0c80a) to 7e38bbb0c9f0d4379fe109884c90ab2254ce86af [diff](https://github.com/apache/arrow-rs/compare/7e38bbb0c9f0d4379fe109884c90ab2254ce86af..f636d6f7cc14c49a04a45a91e2b57b2169c0c80a)
BENCH_NAME=variant_kernels
BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench variant_kernels
BENCH_FILTER=
BENCH_BRANCH_NAME=variant-builder-custom-state
Results will be posted here when complete
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3284925283
@scovich after your updates to have everything use the same indirection mechanism, it seems that many benchmarks got slower -- I think we should revert to having the specific enums. I am sorry for any confusion / rework I have caused.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3285709479
@alamb -- I changed to generic `ParentState<S: BuilderSpecificState>`, could you take it for a benchmarking spin so we know what impact it has?
Meanwhile:
* `VariantBuilderExt` did _not_ become generic -- it can capture the genericity with an associated type instead.
* Changing to generic only seems to have affected code implementing builders and parent state; I didn't have to change any use sites.
* The PR is still a net win in LoC, in spite of that churn.
Thoughts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3281994083
🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/scripts/gh_compare_arrow.sh) Running
Linux aal-dev 6.14.0-1014-gcp #15~24.04.1-Ubuntu SMP Fri Jul 25 23:26:08 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing variant-builder-custom-state (1110bb305ddf22759f92231f5d567f8d77a02023) to 7e38bbb0c9f0d4379fe109884c90ab2254ce86af [diff](https://github.com/apache/arrow-rs/compare/7e38bbb0c9f0d4379fe109884c90ab2254ce86af..1110bb305ddf22759f92231f5d567f8d77a02023)
BENCH_NAME=variant_kernels
BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench variant_kernels
BENCH_FILTER=
BENCH_BRANCH_NAME=variant-builder-custom-state
Results will be posted here when complete
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3284658662
🤖: Benchmark completed
<details><summary>Details</summary>
<p>
```
group main variant-builder-custom-state
----- ---- ----------------------------
bench_validate_complex_object 1.00 231.3±1.65µs ? ?/sec 1.00 230.3±0.44µs ? ?/sec
bench_validate_large_nested_list 1.00 19.2±0.04ms ? ?/sec 1.02 19.6±0.04ms ? ?/sec
bench_validate_large_object 1.00 55.1±0.08ms ? ?/sec 1.00 55.3±0.08ms ? ?/sec
```
</p>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282060226
> > > > CON: Architectural violation to make parquet-variant crate (at least somewhat) aware of parquet-variant-compute crate that depends on it.
> > >
> > >
> > > Another potential option is to move some/all the specialized builder code into the parquet-variant crate 🤔
> >
> >
> > Moving `VariantArrayBuilder` to from parquet-variant-compute to parquet-variant crate would indeed resolve the architectural violation. Is that even such a bad thing?
>
> It doesn't seem like a bad idea to me, to be honest.
>
> The only potential issue would be people who wanted to use parquet-variant without the dependency on arrow (I am only theorizing here, I don't know if that is actually an important usecase).
That's an interesting point. In https://github.com/delta-io/delta-kernel-rs/, for example, arrow is the default (but not required) engine implementation -- a Delta connector based on the kernel could choose to use its own native facilities instead. But variant is part of the Delta specification, so it could be important to have access to a robust binary variant implementation even if the engine isn't otherwise using arrow.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282043384
🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/scripts/gh_compare_arrow.sh) Running
Linux aal-dev 6.14.0-1014-gcp #15~24.04.1-Ubuntu SMP Fri Jul 25 23:26:08 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing variant-builder-custom-state (1110bb305ddf22759f92231f5d567f8d77a02023) to 7e38bbb0c9f0d4379fe109884c90ab2254ce86af [diff](https://github.com/apache/arrow-rs/compare/7e38bbb0c9f0d4379fe109884c90ab2254ce86af..1110bb305ddf22759f92231f5d567f8d77a02023)
BENCH_NAME=variant_builder
BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench variant_builder
BENCH_FILTER=
BENCH_BRANCH_NAME=variant-builder-custom-state
Results will be posted here when complete
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282025038
🤖: Benchmark completed
<details><summary>Details</summary>
<p>
```
group main variant-builder-custom-state
----- ---- ----------------------------
bench_validate_complex_object 1.00 230.9±0.44µs ? ?/sec 1.00 230.4±0.45µs ? ?/sec
bench_validate_large_nested_list 1.00 19.5±0.06ms ? ?/sec 1.00 19.4±0.05ms ? ?/sec
bench_validate_large_object 1.00 55.0±0.13ms ? ?/sec 1.00 54.9±0.09ms ? ?/sec
```
</p>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282077854
Also re benchmarks: Do we even _have_ any benchmarks for appending primitive numeric values to a `VariantArrayBuilder`? Because that's the case that would expose the increased overhead, if any would.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on code in PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#discussion_r2342134721
##########
parquet-variant/src/builder.rs:
##########
@@ -709,6 +727,14 @@ pub enum ParentState<'a> {
saved_fields_size: usize,
finished: bool,
},
+ Custom {
+ value_builder: &'a mut ValueBuilder,
+ saved_value_builder_offset: usize,
+ metadata_builder: &'a mut dyn MetadataBuilder,
+ saved_metadata_builder_dict_size: usize,
+ state: Box<dyn CustomParentState + 'a>,
Review Comment:
I update the PR to use the same approach for everything (`ParentState` is now a struct instead of an enum).
Holler if you hate it and I can easily revert.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on code in PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#discussion_r2344616766
##########
parquet-variant/src/builder.rs:
##########
@@ -1683,26 +1712,31 @@ pub trait VariantBuilderExt {
/// Creates a nested list builder. See e.g. [`VariantBuilder::new_list`]. Panics if the nested
/// builder cannot be created, see e.g. [`ObjectBuilder::new_list`].
- fn new_list(&mut self) -> ListBuilder<'_> {
+ fn new_list(&mut self) -> ListBuilder<'_, Self::State<'_>> {
Review Comment:
NOTE: If associated type defaults were stable, we could simplify the code even further:
```rust
pub trait VariantBuilderExt {
/// The builder specific state used by nested builders
type State<'a>: BuilderSpecificState + 'a
where
Self: 'a;
type ListBuilder<'a> = ListBuilder<'a, Self::State<'a>>
where
Self: 'a;
type ObjectBuilder<'a> = ObjectBuilder<'a, Self::State<'a>>
where
Self: 'a;
...
fn try_new_list(&mut self) -> Result<Self::ListBuilder<'_>, ArrowError>;
fn try_new_object(&mut self) -> Result<Self::ObjectBuilder<'_>, ArrowError>;
}
```
(the various trait implementors could just inherit and use `Self::ListBuilder` and `Self::ObjectBuilder`)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282007869
🤖: Benchmark completed
<details><summary>Details</summary>
<p>
```
group main variant-builder-custom-state
----- ---- ----------------------------
batch_json_string_to_variant json_list 8k string 1.00 27.8±0.14ms ? ?/sec 1.01 27.9±0.13ms ? ?/sec
batch_json_string_to_variant random_json(2633 bytes per document) 1.00 315.7±4.44ms ? ?/sec 1.00 315.3±0.52ms ? ?/sec
batch_json_string_to_variant repeated_struct 8k string 1.02 7.9±0.04ms ? ?/sec 1.00 7.8±0.02ms ? ?/sec
variant_get_primitive 1.00 617.8±1.12ns ? ?/sec 1.00 619.7±6.88ns ? ?/sec
```
</p>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3284653995
🤖: Benchmark completed
<details><summary>Details</summary>
<p>
```
group main variant-builder-custom-state
----- ---- ----------------------------
bench_extend_metadata_builder 1.00 59.1±2.50ms ? ?/sec 1.07 63.1±2.26ms ? ?/sec
bench_object_field_names_reverse_order 1.23 21.4±0.48ms ? ?/sec 1.00 17.4±0.80ms ? ?/sec
bench_object_list_partially_same_schema 1.00 1278.4±15.36µs ? ?/sec 1.08 1385.4±17.41µs ? ?/sec
bench_object_list_same_schema 1.00 25.7±0.18ms ? ?/sec 1.14 29.4±0.18ms ? ?/sec
bench_object_list_unknown_schema 1.00 13.7±0.09ms ? ?/sec 1.13 15.6±0.12ms ? ?/sec
bench_object_partially_same_schema 1.00 3.3±0.01ms ? ?/sec 1.05 3.5±0.01ms ? ?/sec
bench_object_same_schema 1.00 38.5±0.09ms ? ?/sec 1.10 42.2±0.09ms ? ?/sec
bench_object_unknown_schema 1.00 16.3±0.05ms ? ?/sec 1.08 17.7±0.04ms ? ?/sec
iteration/unvalidated_fallible_iteration 1.00 2.7±0.00ms ? ?/sec 1.02 2.7±0.00ms ? ?/sec
iteration/validated_iteration 1.01 49.9±0.11µs ? ?/sec 1.00 49.3±0.16µs ? ?/sec
validation/unvalidated_construction 1.00 6.7±0.01µs ? ?/sec 1.00 6.7±0.02µs ? ?/sec
validation/validated_construction 1.00 61.1±0.11µs ? ?/sec 1.00 61.0±0.10µs ? ?/sec
validation/validation_cost 1.03 56.2±0.12µs ? ?/sec 1.00 54.5±0.14µs ? ?/sec
```
</p>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3285463911
> after your updates to have everything use the same indirection mechanism, it seems that many benchmarks got slower -- I think we should revert to having the specific enums. I am sorry for any confusion / rework I have caused.
Honestly, that tells me we just don't have benchmarks to measure the impact of the original change, and that we either need to go generic or accept the architectural violation of having enum variants for array builders (but the latter would be difficult to pull off, given that `NullBuffer` is part of the builder specific state, and arrow-array is not available in parquet-variant.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on code in PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#discussion_r2344616766
##########
parquet-variant/src/builder.rs:
##########
@@ -1683,26 +1712,31 @@ pub trait VariantBuilderExt {
/// Creates a nested list builder. See e.g. [`VariantBuilder::new_list`]. Panics if the nested
/// builder cannot be created, see e.g. [`ObjectBuilder::new_list`].
- fn new_list(&mut self) -> ListBuilder<'_> {
+ fn new_list(&mut self) -> ListBuilder<'_, Self::State<'_>> {
Review Comment:
NOTE: If associated type defaults were stable, we could simplify the code even further:
```rust
pub trait VariantBuilderExt {
/// The builder specific state used by nested builders
type State<'a>: BuilderSpecificState + 'a
where
Self: 'a;
type ListBuilder<'a> = ListBuilder<'a, Self::State<'a>>
where
Self: 'a;
type ObjectBuilder<'a> = ObjectBuilder<'a, Self::State<'a>>
where
Self: 'a;
...
fn try_new_list(&mut self) -> Result<Self::ListBuilder<'_>, ArrowError>;
fn try_new_object(&mut self) -> Result<Self::ObjectBuilder<'_>, ArrowError>;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] Support custom variant builder parent state [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282045919
Rerunning the `BENCH_NAME=variant_builder` benchmark to see if this is reproduceable:
```
group main variant-builder-custom-state
----- ---- ----------------------------
bench_extend_metadata_builder 1.00 57.4±3.39ms ? ?/sec 1.11 63.6±3.15ms ? ?/sec
```
All the other benchmarks look pretty good to me
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3282616792
> currently, it [`parquet-variant` crate] only depends on `arrow-schema`
According to my AI assistant:
> The `parquet-variant` crate does NOT use any other Arrow functionality - it doesn't use Arrow arrays, schemas, data types, or compute functions. The dependency on `arrow-schema` is purely for the standardized `ArrowError` type, which provides consistent error handling across the Arrow ecosystem.
>
> This is a common pattern in the Arrow Rust ecosystem where crates use arrow-schema just for the error types to maintain consistency, even when they don't use other Arrow functionality.
@alamb is this really a common pattern? Is there a better way to import just `ArrowError`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#discussion_r2346439492
##########
parquet-variant/src/builder.rs:
##########
@@ -736,34 +748,68 @@ impl BuilderSpecificState for ObjectParentState<'_> {
/// the parent, and we cannot "split" a mutable reference across two objects (parent state and the
/// child builder that uses it). So everything has to be here.
#[derive(Debug)]
-pub struct ParentState<'a> {
+pub struct ParentState<'a, S: BuilderSpecificState> {
value_builder: &'a mut ValueBuilder,
saved_value_builder_offset: usize,
metadata_builder: &'a mut dyn MetadataBuilder,
saved_metadata_builder_dict_size: usize,
- builder_state: Box<dyn BuilderSpecificState + 'a>,
+ builder_state: S,
Review Comment:
❤️
##########
parquet-variant/src/builder.rs:
##########
@@ -736,34 +748,68 @@ impl BuilderSpecificState for ObjectParentState<'_> {
/// the parent, and we cannot "split" a mutable reference across two objects (parent state and the
/// child builder that uses it). So everything has to be here.
#[derive(Debug)]
-pub struct ParentState<'a> {
+pub struct ParentState<'a, S: BuilderSpecificState> {
value_builder: &'a mut ValueBuilder,
saved_value_builder_offset: usize,
metadata_builder: &'a mut dyn MetadataBuilder,
saved_metadata_builder_dict_size: usize,
- builder_state: Box<dyn BuilderSpecificState + 'a>,
+ builder_state: S,
finished: bool,
}
-impl<'a> ParentState<'a> {
+impl<'a, S: BuilderSpecificState> ParentState<'a, S> {
/// Creates a new ParentState instance. The value and metadata builder
/// state is checkpointed and will roll back on drop, unless [`Self::finish`] is called. The
/// builder-specific state is governed by its own `finish` and `rollback` calls.
- pub fn new<T: BuilderSpecificState + 'a>(
+ pub fn new(
value_builder: &'a mut ValueBuilder,
metadata_builder: &'a mut dyn MetadataBuilder,
- builder_state: T,
+ builder_state: S,
) -> Self {
- ParentState {
+ Self {
saved_value_builder_offset: value_builder.offset(),
value_builder,
saved_metadata_builder_dict_size: metadata_builder.num_field_names(),
metadata_builder,
- builder_state: Box::new(builder_state),
+ builder_state,
finished: false,
}
}
+ /// Marks the insertion as having succeeded and invokes
+ /// [`BuilderSpecificState::finish`]. Internal state will no longer roll back on drop.
Review Comment:
I found the reference to the past ("no longer") a little confusing
```suggestion
/// [`BuilderSpecificState::finish`].
///
/// Note: Does not call `rollback()` on drop
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3288138294
🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/scripts/gh_compare_arrow.sh) Running
Linux aal-dev 6.14.0-1014-gcp #15~24.04.1-Ubuntu SMP Fri Jul 25 23:26:08 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing variant-builder-custom-state (f636d6f7cc14c49a04a45a91e2b57b2169c0c80a) to 7e38bbb0c9f0d4379fe109884c90ab2254ce86af [diff](https://github.com/apache/arrow-rs/compare/7e38bbb0c9f0d4379fe109884c90ab2254ce86af..f636d6f7cc14c49a04a45a91e2b57b2169c0c80a)
BENCH_NAME=variant_builder
BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench variant_builder
BENCH_FILTER=
BENCH_BRANCH_NAME=variant-builder-custom-state
Results will be posted here when complete
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Variant] ParentState tracks builder-specific state in a uniform way [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8324:
URL: https://github.com/apache/arrow-rs/pull/8324#issuecomment-3288144377
🤖: Benchmark completed
<details><summary>Details</summary>
<p>
```
group main variant-builder-custom-state
----- ---- ----------------------------
bench_extend_metadata_builder 1.10 59.9±2.17ms ? ?/sec 1.00 54.5±2.34ms ? ?/sec
bench_object_field_names_reverse_order 1.05 20.2±0.50ms ? ?/sec 1.00 19.2±0.96ms ? ?/sec
bench_object_list_partially_same_schema 1.00 1268.3±14.63µs ? ?/sec 1.00 1272.3±16.27µs ? ?/sec
bench_object_list_same_schema 1.01 25.4±0.26ms ? ?/sec 1.00 25.1±0.16ms ? ?/sec
bench_object_list_unknown_schema 1.00 13.5±0.07ms ? ?/sec 1.00 13.6±0.14ms ? ?/sec
bench_object_partially_same_schema 1.00 3.3±0.01ms ? ?/sec 1.01 3.4±0.01ms ? ?/sec
bench_object_same_schema 1.00 38.8±0.11ms ? ?/sec 1.02 39.6±0.13ms ? ?/sec
bench_object_unknown_schema 1.00 16.2±0.07ms ? ?/sec 1.01 16.3±0.13ms ? ?/sec
iteration/unvalidated_fallible_iteration 1.00 2.6±0.01ms ? ?/sec 1.04 2.7±0.04ms ? ?/sec
iteration/validated_iteration 1.01 49.3±0.07µs ? ?/sec 1.00 49.1±0.05µs ? ?/sec
validation/unvalidated_construction 1.01 6.7±0.01µs ? ?/sec 1.00 6.7±0.02µs ? ?/sec
validation/validated_construction 1.00 60.3±0.10µs ? ?/sec 1.01 61.1±0.57µs ? ?/sec
validation/validation_cost 1.01 53.6±0.08µs ? ?/sec 1.00 53.2±0.08µs ? ?/sec
```
</p>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org