Skip to content

Commit 7f11f0c

Browse files
committed
fix builders
Signed-off-by: Connor Tsui <[email protected]>
1 parent 7d5740b commit 7f11f0c

3 files changed

Lines changed: 15 additions & 78 deletions

File tree

‎vortex-array/src/builders/fixed_size_list.rs‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ impl FixedSizeListBuilder {
108108
///
109109
/// [`ListArray`]: crate::arrays::ListArray
110110
pub fn append_value(&mut self, value: ListScalar) -> VortexResult<()> {
111-
if value.is_null() {
111+
let Some(array) = value.as_array() else {
112112
self.append_null();
113113
return Ok(());
114-
}
114+
};
115115

116116
if value.len() != self.list_size() as usize {
117117
vortex_bail!(
@@ -122,21 +122,7 @@ impl FixedSizeListBuilder {
122122
);
123123
}
124124

125-
// Fast-path: if the list scalar is backed by an array, append the entire thing directly.
126-
if let Some(array) = value.as_array() {
127-
return self.append_array_as_list(array);
128-
}
129-
130-
// Otherwise we must append the individual scalars.
131-
let elements = value
132-
.elements()
133-
.vortex_expect("non-null ListScalar must have elements");
134-
for scalar in elements {
135-
self.elements_builder.append_scalar(&scalar)?;
136-
}
137-
self.nulls.append_non_null();
138-
139-
Ok(())
125+
self.append_array_as_list(array)
140126
}
141127

142128
/// Finishes the builder directly into a [`FixedSizeListArray`].

‎vortex-array/src/builders/list.rs‎

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -110,31 +110,13 @@ impl<O: IntegerPType> ListBuilder<O> {
110110

111111
/// Appends a list `value` to the builder.
112112
pub fn append_value(&mut self, value: ListScalar) -> VortexResult<()> {
113-
if value.is_null() {
114-
self.append_null();
115-
return Ok(());
116-
}
117-
118-
// Fast-path: if the list scalar is backed by an array, append the entire thing directly.
119-
if let Some(array) = value.as_array() {
120-
return self.append_array_as_list(array);
121-
}
122-
123-
// Otherwise, we must append the individual scalars.
124-
let elements = value
125-
.elements()
126-
.vortex_expect("non-null ListScalar must have elements");
127-
for scalar in elements {
128-
self.elements_builder.append_scalar(&scalar)?;
113+
match value.as_array() {
114+
Some(array) => self.append_array_as_list(array),
115+
None => {
116+
self.append_null();
117+
Ok(())
118+
}
129119
}
130-
131-
self.nulls.append_non_null();
132-
self.offsets_builder.append_value(
133-
O::from_usize(self.elements_builder.len())
134-
.vortex_expect("Failed to convert from usize to O"),
135-
);
136-
137-
Ok(())
138120
}
139121

140122
/// Finishes the builder directly into a [`ListArray`].

‎vortex-array/src/builders/listview.rs‎

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -152,44 +152,13 @@ impl<O: IntegerPType, S: IntegerPType> ListViewBuilder<O, S> {
152152
/// This method extends the value builder with the provided values and records
153153
/// the offset and size of the new list.
154154
pub fn append_value(&mut self, value: ListScalar) -> VortexResult<()> {
155-
if value.is_null() {
156-
self.append_null();
157-
return Ok(());
158-
}
159-
160-
// Fast-path: if the list scalar is backed by an array, append the entire thing directly.
161-
if let Some(array) = value.as_array() {
162-
return self.append_array_as_list(array);
163-
}
164-
165-
// Otherwise, we must append the individual scalars.
166-
let elements = value
167-
.elements()
168-
.vortex_expect("non-null ListScalar must have elements");
169-
170-
let curr_offset = self.elements_builder.len();
171-
let num_elements = elements.len();
172-
173-
// We must assert this even in release mode to ensure that the safety comment in
174-
// `finish_into_listview` is correct.
175-
assert!(
176-
((curr_offset + num_elements) as u64) < O::max_value_as_u64(),
177-
"appending this list would cause an offset overflow"
178-
);
179-
180-
for scalar in elements {
181-
self.elements_builder.append_scalar(&scalar)?;
155+
match value.as_array() {
156+
Some(array) => self.append_array_as_list(array),
157+
None => {
158+
self.append_null();
159+
Ok(())
160+
}
182161
}
183-
self.nulls.append_non_null();
184-
185-
self.offsets_builder.append_value(
186-
O::from_usize(curr_offset).vortex_expect("Failed to convert from usize to `O`"),
187-
);
188-
self.sizes_builder.append_value(
189-
S::from_usize(num_elements).vortex_expect("Failed to convert from usize to `S`"),
190-
);
191-
192-
Ok(())
193162
}
194163

195164
/// Finishes the builder directly into a [`ListViewArray`].

0 commit comments

Comments
 (0)