Coverage Report

Created: 2025-08-26 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/Users/andrewlamb/Software/arrow-rs/arrow-data/src/transform/union.rs
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
use super::{Extend, _MutableArrayData};
19
use crate::ArrayData;
20
21
0
pub(super) fn build_extend_sparse(array: &ArrayData) -> Extend<'_> {
22
0
    let type_ids = array.buffer::<i8>(0);
23
24
0
    Box::new(
25
0
        move |mutable: &mut _MutableArrayData, index: usize, start: usize, len: usize| {
26
            // extends type_ids
27
0
            mutable
28
0
                .buffer1
29
0
                .extend_from_slice(&type_ids[start..start + len]);
30
31
0
            mutable
32
0
                .child_data
33
0
                .iter_mut()
34
0
                .for_each(|child| child.extend(index, start, start + len))
35
0
        },
36
    )
37
0
}
38
39
0
pub(super) fn build_extend_dense(array: &ArrayData) -> Extend<'_> {
40
0
    let type_ids = array.buffer::<i8>(0);
41
0
    let offsets = array.buffer::<i32>(1);
42
0
    let arrow_schema::DataType::Union(src_fields, _) = array.data_type() else {
43
0
        unreachable!();
44
    };
45
46
0
    Box::new(
47
0
        move |mutable: &mut _MutableArrayData, index: usize, start: usize, len: usize| {
48
            // extends type_ids
49
0
            mutable
50
0
                .buffer1
51
0
                .extend_from_slice(&type_ids[start..start + len]);
52
53
0
            (start..start + len).for_each(|i| {
54
0
                let type_id = type_ids[i];
55
0
                let child_index = src_fields
56
0
                    .iter()
57
0
                    .position(|(r, _)| r == type_id)
58
0
                    .expect("invalid union type ID");
59
0
                let src_offset = offsets[i] as usize;
60
0
                let child_data = &mut mutable.child_data[child_index];
61
0
                let dst_offset = child_data.len();
62
63
                // Extend offsets
64
0
                mutable.buffer2.push(dst_offset as i32);
65
0
                mutable.child_data[child_index].extend(index, src_offset, src_offset + 1)
66
0
            })
67
0
        },
68
    )
69
0
}
70
71
0
pub(super) fn extend_nulls_dense(_mutable: &mut _MutableArrayData, _len: usize) {
72
0
    panic!("cannot call extend_nulls on UnionArray as cannot infer type");
73
}
74
75
0
pub(super) fn extend_nulls_sparse(_mutable: &mut _MutableArrayData, _len: usize) {
76
0
    panic!("cannot call extend_nulls on UnionArray as cannot infer type");
77
}