scovich commented on code in PR #8825:
URL: https://github.com/apache/arrow-rs/pull/8825#discussion_r2535607866
##########
parquet-variant-compute/src/variant_to_arrow.rs:
##########
@@ -696,26 +696,43 @@ impl VariantToBinaryVariantArrowRowBuilder {
}
}
-struct FakeNullBuilder(NullArray);
+pub(crate) struct VariantToNullArrowRowBuilder<'a> {
+ cast_option: &'a CastOptions<'a>,
+ item_count: usize,
+}
-impl FakeNullBuilder {
- fn new(capacity: usize) -> Self {
- Self(NullArray::new(capacity))
+impl<'a> VariantToNullArrowRowBuilder<'a> {
+ fn new(cast_option: &'a CastOptions<'a>) -> Self {
+ Self {
+ cast_option,
+ item_count: 0,
+ }
}
- fn append_value<T>(&mut self, _: T) {}
- fn append_null(&mut self) {}
- fn finish(self) -> NullArray {
- self.0
+ fn append_value(&mut self, value: &Variant<'_, '_>) -> Result<bool> {
+ if value.as_null().is_some() {
+ self.item_count += 1;
+ Ok(true)
+ } else if self.cast_option.safe {
+ self.append_null()?;
+ Ok(false)
+ } else {
+ Err(ArrowError::CastError(format!(
Review Comment:
`define_variant_to_primitive_builder!` macro handles all this already?
Why not use it?
```rust
|value| matches!(value, Variant::Null).then_some(0)
```
and then
```rust
fn append_value(&mut self, _dummy: i32) {
self.item_count += 1;
}
fn append_null(&mut self) {
self.item_count += 1;
}
```
(no need to capture the cast options, the macro handles that 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]