Create a new [`GenericByteArray`] from the provided parts, returning an error on failure # Errors `offsets.len() - 1 != nulls.len()` Any consecutive pair of `offsets` does not denote a valid slice of `values`
(
offsets: OffsetBuffer<T::Offset>,
values: Buffer,
nulls: Option<NullBuffer>,
)
| 126 | /// * `offsets.len() - 1 != nulls.len()` |
| 127 | /// * Any consecutive pair of `offsets` does not denote a valid slice of `values` |
| 128 | pub fn try_new( |
| 129 | offsets: OffsetBuffer<T::Offset>, |
| 130 | values: Buffer, |
| 131 | nulls: Option<NullBuffer>, |
| 132 | ) -> Result<Self, ArrowError> { |
| 133 | let len = offsets.len() - 1; |
| 134 | |
| 135 | // Verify that each pair of offsets is a valid slices of values |
| 136 | T::validate(&offsets, &values)?; |
| 137 | |
| 138 | if let Some(n) = nulls.as_ref() { |
| 139 | if n.len() != len { |
| 140 | return Err(ArrowError::InvalidArgumentError(format!( |
| 141 | "Incorrect length of null buffer for {}{}Array, expected {len} got {}", |
| 142 | T::Offset::PREFIX, |
| 143 | T::PREFIX, |
| 144 | n.len(), |
| 145 | ))); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | Ok(Self { |
| 150 | data_type: T::DATA_TYPE, |
| 151 | value_offsets: offsets, |
| 152 | value_data: values, |
| 153 | nulls, |
| 154 | }) |
| 155 | } |
| 156 | |
| 157 | /// Create a new [`GenericByteArray`] from the provided parts, without validation |
| 158 | /// |