From e4aebc22783823566e5f456a289d8549ba2da34d Mon Sep 17 00:00:00 2001 From: Joe Isaacs Date: Wed, 18 Dec 2024 18:19:28 +0000 Subject: [PATCH] fix builder bugs --- vortex-array/src/builders/list.rs | 2 +- vortex-array/src/builders/struct_.rs | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/vortex-array/src/builders/list.rs b/vortex-array/src/builders/list.rs index 91fcb8d0e6..f93445e1cd 100644 --- a/vortex-array/src/builders/list.rs +++ b/vortex-array/src/builders/list.rs @@ -34,7 +34,7 @@ where ) -> Self { // I would expect the list to have more than one value per index let value_builder = builder_with_capacity(value_dtype.as_ref(), 2 * capacity); - let mut index_builder = PrimitiveBuilder::with_capacity(nullability, capacity); + let mut index_builder = PrimitiveBuilder::with_capacity(Nullability::NonNullable, capacity); // The first index of the list, which is always 0 and represents an empty list. index_builder.append_zero(); diff --git a/vortex-array/src/builders/struct_.rs b/vortex-array/src/builders/struct_.rs index 5ddb49eacc..546d8296c3 100644 --- a/vortex-array/src/builders/struct_.rs +++ b/vortex-array/src/builders/struct_.rs @@ -49,9 +49,10 @@ impl StructBuilder { } if let Some(fields) = struct_scalar.fields() { - for (builder, field) in self.builders.iter_mut().zip(fields) { + for (builder, field) in self.builders.iter_mut().zip_eq(fields) { builder.append_scalar(&field)?; } + self.validity.append_value(true); } else { self.append_null() } @@ -94,6 +95,7 @@ impl ArrayBuilder for StructBuilder { } fn finish(&mut self) -> VortexResult { + let len = self.len(); let fields: Vec = self .builders .iter_mut() @@ -105,12 +107,9 @@ impl ArrayBuilder for StructBuilder { Nullability::Nullable => Validity::Array(self.validity.finish()?), }; - Ok(StructArray::try_new( - self.struct_dtype.names().clone(), - fields, - self.len(), - validity, - )? - .into_array()) + Ok( + StructArray::try_new(self.struct_dtype.names().clone(), fields, len, validity)? + .into_array(), + ) } }