viirya commented on code in PR #4382:
URL: https://github.com/apache/arrow-rs/pull/4382#discussion_r1222185583
##########
arrow-array/src/array/map_array.rs:
##########
@@ -40,6 +40,106 @@ pub struct MapArray {
}
impl MapArray {
+ /// Create a new [`MapArray`] from the provided parts
+ ///
+ /// # Errors
+ ///
+ /// Errors if
+ ///
+ /// * `offsets.len() - 1 != nulls.len()`
+ /// * `offsets.last() > entries.len()`
+ /// * `field.is_nullable()`
+ /// * `entries.null_count() != 0`
+ /// * `entries.columns().len() != 2`
+ /// * `field.data_type() != entries.data_type()`
+ pub fn try_new(
+ field: FieldRef,
+ offsets: OffsetBuffer<i32>,
+ entries: StructArray,
+ nulls: Option<NullBuffer>,
+ ordered: bool,
+ ) -> Result<Self, ArrowError> {
+ let len = offsets.len() - 1; // Offsets guaranteed to not be empty
+ let end_offset = offsets.last().unwrap().as_usize();
+ // don't need to check other values of `offsets` because they are
checked
+ // during construction of `OffsetsBuffer`
+ if end_offset > entries.len() {
+ return Err(ArrowError::InvalidArgumentError(format!(
+ "Max offset of {end_offset} exceeds length of entries {}",
+ entries.len()
+ )));
+ }
+
+ if let Some(n) = nulls.as_ref() {
+ if n.len() != len {
+ return Err(ArrowError::InvalidArgumentError(format!(
+ "Incorrect length of null buffer for MapArray, expected
{len} got {}",
+ n.len(),
+ )));
+ }
+ }
+ if field.is_nullable() || entries.null_count() != 0 {
+ return Err(ArrowError::InvalidArgumentError(
+ "MapArray entries cannot contain be null".to_string(),
Review Comment:
```suggestion
"MapArray entries cannot contain null".to_string(),
```
--
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]