Skip to content

Commit 411de06

Browse files
authored
chore: add try_from_iter_with_validity (#3608)
I think the cleanest way to modify the struct is to iter over the fields and names - but right now that's not really possible since nullability isn't settable. Could clean it up by changing `try_from_iter` directly, but I assumed we want to avoid that for backwards compatibility - lmk if that's not the case 🙂 Signed-off-by: blaginin <[email protected]>
1 parent 51fc068 commit 411de06

File tree

1 file changed

+13
-7
lines changed
  • vortex-array/src/arrays/struct_

1 file changed

+13
-7
lines changed

vortex-array/src/arrays/struct_/mod.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,13 @@ impl StructArray {
171171
Self::try_from_iter(items.iter().map(|(a, b)| (a, b.to_array())))
172172
}
173173

174-
pub fn try_from_iter<N: AsRef<str>, A: IntoArray, T: IntoIterator<Item = (N, A)>>(
174+
pub fn try_from_iter_with_validity<
175+
N: AsRef<str>,
176+
A: IntoArray,
177+
T: IntoIterator<Item = (N, A)>,
178+
>(
175179
iter: T,
180+
validity: Validity,
176181
) -> VortexResult<Self> {
177182
let (names, fields): (Vec<FieldName>, Vec<ArrayRef>) = iter
178183
.into_iter()
@@ -183,12 +188,13 @@ impl StructArray {
183188
.map(|f| f.len())
184189
.ok_or_else(|| vortex_err!("StructArray cannot be constructed from an empty slice of arrays because the length is unspecified"))?;
185190

186-
Self::try_new(
187-
FieldNames::from_iter(names),
188-
fields,
189-
len,
190-
Validity::NonNullable,
191-
)
191+
Self::try_new(FieldNames::from_iter(names), fields, len, validity)
192+
}
193+
194+
pub fn try_from_iter<N: AsRef<str>, A: IntoArray, T: IntoIterator<Item = (N, A)>>(
195+
iter: T,
196+
) -> VortexResult<Self> {
197+
Self::try_from_iter_with_validity(iter, Validity::NonNullable)
192198
}
193199

194200
// TODO(aduffy): Add equivalent function to support field masks for nested column access.

0 commit comments

Comments
 (0)