Skip to main content

arrow_data/transform/
fixed_binary.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5use super::{_MutableArrayData, Extend};
6use crate::ArrayData;
7use crate::data::get_fixed_size_binary_width;
8
9pub(super) fn build_extend(array: &ArrayData) -> Extend<'_> {
10    let size = get_fixed_size_binary_width(array.data_type());
11    let values = &array.buffers()[0].as_slice()[array.offset() * size..];
12    Box::new(
13        move |mutable: &mut _MutableArrayData, _, start: usize, len: usize| {
14            let buffer = &mut mutable.buffer1;
15            buffer.extend_from_slice(&values[start * size..(start + len) * size]);
16            Ok(())
17        },
18    )
19}
20
21pub(super) fn extend_nulls(
22    mutable: &mut _MutableArrayData,
23    len: usize,
24) -> Result<(), arrow_schema::ArrowError> {
25    let size = get_fixed_size_binary_width(&mutable.data_type);
26
27    let values_buffer = &mut mutable.buffer1;
28    values_buffer
29        .try_extend_zeros(len * size)
30        .map_err(|e| arrow_schema::ArrowError::MemoryError(e.to_string()))?;
31    Ok(())
32}