You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor!: do not default the struct array length to 0 in Struct::try_new (#7247)
* Do not default the struct array length to 0 in Struct::try_new if there are no child arrays.
* Extend testing for new_empty_fields
* Add try_new_with_length
Copy file name to clipboardExpand all lines: arrow-array/src/array/struct_array.rs
+85-5Lines changed: 85 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -91,6 +91,28 @@ impl StructArray {
91
91
Self::try_new(fields, arrays, nulls).unwrap()
92
92
}
93
93
94
+
/// Create a new [`StructArray`] from the provided parts, returning an error on failure
95
+
///
96
+
/// The length will be inferred from the length of the child arrays. Returns an error if
97
+
/// there are no child arrays. Consider using [`Self::try_new_with_length`] if the length
98
+
/// is known to avoid this.
99
+
///
100
+
/// # Errors
101
+
///
102
+
/// Errors if
103
+
///
104
+
/// * `fields.len() == 0`
105
+
/// * Any reason that [`Self::try_new_with_length`] would error
106
+
pubfntry_new(
107
+
fields:Fields,
108
+
arrays:Vec<ArrayRef>,
109
+
nulls:Option<NullBuffer>,
110
+
) -> Result<Self,ArrowError>{
111
+
let len = arrays.first().map(|x| x.len()).ok_or_else(||ArrowError::InvalidArgumentError("use StructArray::try_new_with_length or StructArray::new_empty to create a struct array with no fields so that the length can be set correctly".to_string()))?;
0 commit comments