Concatenates two `BinaryViewArray`s element-wise. If either element is `Null`, the result element is also `Null`. # Errors - Returns an error if the input arrays have different lengths. - Returns an error if any concatenated value exceeds `u32::MAX` in length.
(
left: &BinaryViewArray,
right: &BinaryViewArray,
)
| 228 | /// - Returns an error if the input arrays have different lengths. |
| 229 | /// - Returns an error if any concatenated value exceeds `u32::MAX` in length. |
| 230 | pub fn concat_elements_binary_view_array( |
| 231 | left: &BinaryViewArray, |
| 232 | right: &BinaryViewArray, |
| 233 | ) -> Result<BinaryViewArray, ArrowError> { |
| 234 | if left.len() != right.len() { |
| 235 | return Err(ArrowError::ComputeError(format!( |
| 236 | "Arrays must have the same length: {} != {}", |
| 237 | left.len(), |
| 238 | right.len() |
| 239 | ))); |
| 240 | } |
| 241 | let mut result = BinaryViewBuilder::with_capacity(left.len()); |
| 242 | |
| 243 | // Avoid reallocations by writing to a reused buffer |
| 244 | let mut buffer = MutableBuffer::new(0); |
| 245 | |
| 246 | // Pre-compute combined null bitmap, so the per-row NULL check is efficient |
| 247 | let nulls = NullBuffer::union(left.nulls(), right.nulls()); |
| 248 | |
| 249 | for i in 0..left.len() { |
| 250 | if nulls.as_ref().is_some_and(|n| n.is_null(i)) { |
| 251 | result.append_null(); |
| 252 | } else { |
| 253 | buffer.clear(); |
| 254 | buffer.extend_from_slice(left.value(i)); |
| 255 | buffer.extend_from_slice(right.value(i)); |
| 256 | result.try_append_value(&buffer)?; |
| 257 | } |
| 258 | } |
| 259 | Ok(result.finish()) |
| 260 | } |
| 261 | |
| 262 | /// Concatenates two `StringViewArray`s element-wise. |
| 263 | /// If either element is `Null`, the result element is also `Null`. |