scovich commented on code in PR #8625:
URL: https://github.com/apache/arrow-rs/pull/8625#discussion_r2432778527
##########
parquet-variant-compute/src/variant_array.rs:
##########
@@ -1405,4 +1423,48 @@ mod test {
assert!(i.next().is_none());
assert!(i.next_back().is_none());
}
+
+ #[test]
+ fn test_from_variant_opts_into_variant_array() {
+ let v = vec![None, Some(Variant::Null), Some(Variant::BooleanFalse),
None];
+
+ let variant_array = VariantArray::from_iter(v);
+
+ assert_eq!(variant_array.len(), 4);
+
+ assert!(variant_array.is_null(0));
+
+ assert!(!variant_array.is_null(1));
+ assert_eq!(variant_array.value(1), Variant::Null);
+
+ assert!(!variant_array.is_null(2));
+ assert_eq!(variant_array.value(2), Variant::BooleanFalse);
+
+ assert!(variant_array.is_null(3));
+ }
+
+ #[test]
+ fn test_from_variants_into_variant_array() {
+ let v = vec![
+ Variant::Null,
+ Variant::BooleanFalse,
+ Variant::ShortString(ShortString::try_new("norm").unwrap()),
+ ];
+
+ let variant_array = VariantArray::from_iter(v.into_iter());
Review Comment:
Shouldn't need that `into_iter` call, the trait takes `IntoIterator` as
input?
##########
parquet-variant-compute/src/variant_array.rs:
##########
@@ -439,6 +440,22 @@ impl From<VariantArray> for ArrayRef {
}
}
+impl<'m, 'v> FromIterator<Option<Variant<'m, 'v>>> for VariantArray {
+ fn from_iter<T: IntoIterator<Item = Option<Variant<'m, 'v>>>>(iter: T) ->
Self {
+ let mut b = VariantArrayBuilder::new(0);
+ b.extend(iter);
+ b.build()
+ }
+}
+
+impl<'m, 'v> FromIterator<Variant<'m, 'v>> for VariantArray {
+ fn from_iter<T: IntoIterator<Item = Variant<'m, 'v>>>(iter: T) -> Self {
+ let mut b = VariantArrayBuilder::new(0);
+ b.extend(iter.into_iter().map(Some));
+ b.build()
Review Comment:
Would this work?
```suggestion
Self::from_iter(iter.into_iter().map(Some))
```
--
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]