Path: blob/main/crates/polars-compute/src/gather/binary.rs
6939 views
// Licensed to the Apache Software Foundation (ASF) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The ASF licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617use arrow::array::{Array, BinaryArray, PrimitiveArray};18use arrow::offset::Offset;1920use super::Index;21use super::generic_binary::*;2223/// `take` implementation for utf8 arrays24/// # Safety25/// The indices must be in-bounds.26pub unsafe fn take_unchecked<O: Offset, I: Index>(27values: &BinaryArray<O>,28indices: &PrimitiveArray<I>,29) -> BinaryArray<O> {30let dtype = values.dtype().clone();31let indices_has_validity = indices.null_count() > 0;32let values_has_validity = values.null_count() > 0;3334let (offsets, values, validity) = match (values_has_validity, indices_has_validity) {35(false, false) => {36take_no_validity_unchecked::<O, I>(values.offsets(), values.values(), indices.values())37},38(true, false) => take_values_validity(values, indices.values()),39(false, true) => take_indices_validity(values.offsets(), values.values(), indices),40(true, true) => take_values_indices_validity(values, indices),41};42BinaryArray::<O>::new_unchecked(dtype, offsets, values, validity)43}444546