Creates an `ArrayData`, consuming `self` # Safety By default the underlying buffers are checked to ensure they are valid Arrow data. However, if the [`Self::skip_validation`] flag has been set to true (by the `unsafe` API) this validation is skipped. If the data is not valid, undefined behavior will result.
(self)
| 2163 | /// to true (by the `unsafe` API) this validation is skipped. If the data is |
| 2164 | /// not valid, undefined behavior will result. |
| 2165 | pub fn build(self) -> Result<ArrayData, ArrowError> { |
| 2166 | let Self { |
| 2167 | data_type, |
| 2168 | len, |
| 2169 | null_count, |
| 2170 | null_bit_buffer, |
| 2171 | nulls, |
| 2172 | offset, |
| 2173 | buffers, |
| 2174 | child_data, |
| 2175 | align_buffers, |
| 2176 | skip_validation, |
| 2177 | } = self; |
| 2178 | |
| 2179 | let nulls = nulls |
| 2180 | .or_else(|| { |
| 2181 | let buffer = null_bit_buffer?; |
| 2182 | let buffer = BooleanBuffer::new(buffer, offset, len); |
| 2183 | Some(match null_count { |
| 2184 | Some(n) => { |
| 2185 | // SAFETY: call to `data.validate_data()` below validates the null buffer is valid |
| 2186 | unsafe { NullBuffer::new_unchecked(buffer, n) } |
| 2187 | } |
| 2188 | None => NullBuffer::new(buffer), |
| 2189 | }) |
| 2190 | }) |
| 2191 | .filter(|b| b.null_count() != 0); |
| 2192 | |
| 2193 | let mut data = ArrayData { |
| 2194 | data_type, |
| 2195 | len, |
| 2196 | offset, |
| 2197 | buffers, |
| 2198 | child_data, |
| 2199 | nulls, |
| 2200 | }; |
| 2201 | |
| 2202 | if align_buffers { |
| 2203 | data.align_buffers(); |
| 2204 | } |
| 2205 | |
| 2206 | // SAFETY: `skip_validation` is only set to true using `unsafe` APIs |
| 2207 | if !skip_validation.get() || cfg!(feature = "force_validate") { |
| 2208 | data.validate_data()?; |
| 2209 | } |
| 2210 | Ok(data) |
| 2211 | } |
| 2212 | |
| 2213 | /// Ensure that all buffers are aligned, copying data if necessary |
| 2214 | /// |