Coverage Report

Created: 2026-09-15 02:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/array/function_array_utils.h
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
#pragma once
18
19
#include "core/column/column.h"
20
#include "core/column/column_array.h"
21
#include "core/column/column_nullable.h"
22
#include "core/data_type/data_type.h"
23
#include "core/types.h"
24
25
namespace doris {
26
class IColumn;
27
} // namespace doris
28
29
namespace doris {
30
31
struct ColumnArrayMutableData {
32
public:
33
    MutableColumnPtr array_nested_col = nullptr;
34
    ColumnUInt8::Container* nested_nullmap_data = nullptr;
35
    MutableColumnPtr offsets_col = nullptr;
36
    ColumnArray::Offsets64* offsets_ptr = nullptr;
37
    IColumn* nested_col = nullptr;
38
};
39
40
struct ColumnArrayExecutionData {
41
public:
42
6
    void reset() {
43
6
        array_nullmap_data = nullptr;
44
6
        array_col = nullptr;
45
6
        offsets_ptr = nullptr;
46
6
        nested_nullmap_data = nullptr;
47
6
        nested_col = nullptr;
48
6
    }
49
50
public:
51
    const UInt8* array_nullmap_data = nullptr;
52
    const ColumnArray* array_col = nullptr;
53
    const ColumnArray::Offsets64* offsets_ptr = nullptr;
54
    const UInt8* nested_nullmap_data = nullptr;
55
    ColumnPtr nested_col = nullptr;
56
57
0
    ColumnArrayMutableData to_mutable_data() const {
58
0
        ColumnArrayMutableData dst;
59
0
        dst.offsets_col = ColumnArray::ColumnOffsets::create();
60
0
        dst.offsets_ptr =
61
0
                &reinterpret_cast<ColumnArray::ColumnOffsets*>(dst.offsets_col.get())->get_data();
62
0
        dst.array_nested_col =
63
0
                ColumnNullable::create(nested_col->clone_empty(), ColumnUInt8::create());
64
0
        auto* nullable_col = reinterpret_cast<ColumnNullable*>(dst.array_nested_col.get());
65
0
        dst.nested_nullmap_data = &nullable_col->get_null_map_data();
66
0
        dst.nested_col = nullable_col->get_nested_column_ptr().get();
67
0
        for (size_t row = 0; row < offsets_ptr->size(); ++row) {
68
0
            dst.offsets_ptr->push_back((*offsets_ptr)[row]);
69
0
            size_t off = (*offsets_ptr)[row - 1];
70
0
            size_t len = (*offsets_ptr)[row] - off;
71
0
            for (size_t start = off; start < off + len; ++start) {
72
0
                if (nested_nullmap_data && nested_nullmap_data[start]) {
73
0
                    dst.nested_col->insert_default();
74
0
                    dst.nested_nullmap_data->push_back(1);
75
0
                } else {
76
0
                    dst.nested_col->insert_from(*nested_col, start);
77
0
                    dst.nested_nullmap_data->push_back(0);
78
0
                }
79
0
            }
80
0
        }
81
0
        return dst;
82
0
    }
83
};
84
bool extract_column_array_info(const IColumn& src, ColumnArrayExecutionData& data);
85
86
ColumnArrayMutableData create_mutable_data(const IColumn* nested_col, bool is_nullable);
87
88
MutableColumnPtr assemble_column_array(ColumnArrayMutableData& data);
89
90
// array[offset:length]
91
void slice_array(ColumnArrayMutableData& dst, ColumnArrayExecutionData& src,
92
                 const IColumn& offset_column, const IColumn* length_column);
93
94
using ColumnArrayExecutionDatas = std::vector<ColumnArrayExecutionData>;
95
} // namespace doris