Coverage Report

Created: 2026-03-13 19:54

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
#include "common/compile_check_begin.h"
31
32
struct ColumnArrayMutableData {
33
public:
34
    MutableColumnPtr array_nested_col = nullptr;
35
    ColumnUInt8::Container* nested_nullmap_data = nullptr;
36
    MutableColumnPtr offsets_col = nullptr;
37
    ColumnArray::Offsets64* offsets_ptr = nullptr;
38
    IColumn* nested_col = nullptr;
39
};
40
41
struct ColumnArrayExecutionData {
42
public:
43
0
    void reset() {
44
0
        array_nullmap_data = nullptr;
45
0
        array_col = nullptr;
46
0
        offsets_ptr = nullptr;
47
0
        nested_nullmap_data = nullptr;
48
0
        nested_col = nullptr;
49
0
    }
50
51
public:
52
    const UInt8* array_nullmap_data = nullptr;
53
    const ColumnArray* array_col = nullptr;
54
    const ColumnArray::Offsets64* offsets_ptr = nullptr;
55
    const UInt8* nested_nullmap_data = nullptr;
56
    ColumnPtr nested_col = nullptr;
57
    DataTypePtr nested_type = nullptr;
58
    // wrap the nested column as variant column
59
    bool output_as_variant = false;
60
61
0
    ColumnArrayMutableData to_mutable_data() const {
62
0
        ColumnArrayMutableData dst;
63
0
        dst.offsets_col = ColumnArray::ColumnOffsets::create();
64
0
        dst.offsets_ptr =
65
0
                &reinterpret_cast<ColumnArray::ColumnOffsets*>(dst.offsets_col.get())->get_data();
66
0
        dst.array_nested_col =
67
0
                ColumnNullable::create(nested_col->clone_empty(), ColumnUInt8::create());
68
0
        auto* nullable_col = reinterpret_cast<ColumnNullable*>(dst.array_nested_col.get());
69
0
        dst.nested_nullmap_data = &nullable_col->get_null_map_data();
70
0
        dst.nested_col = nullable_col->get_nested_column_ptr().get();
71
0
        for (size_t row = 0; row < offsets_ptr->size(); ++row) {
72
0
            dst.offsets_ptr->push_back((*offsets_ptr)[row]);
73
0
            size_t off = (*offsets_ptr)[row - 1];
74
0
            size_t len = (*offsets_ptr)[row] - off;
75
0
            for (size_t start = off; start < off + len; ++start) {
76
0
                if (nested_nullmap_data && nested_nullmap_data[start]) {
77
0
                    dst.nested_col->insert_default();
78
0
                    dst.nested_nullmap_data->push_back(1);
79
0
                } else {
80
0
                    dst.nested_col->insert_from(*nested_col, start);
81
0
                    dst.nested_nullmap_data->push_back(0);
82
0
                }
83
0
            }
84
0
        }
85
0
        return dst;
86
0
    }
87
};
88
bool extract_column_array_info(const IColumn& src, ColumnArrayExecutionData& data);
89
90
ColumnArrayMutableData create_mutable_data(const IColumn* nested_col, bool is_nullable);
91
92
MutableColumnPtr assemble_column_array(ColumnArrayMutableData& data);
93
94
// array[offset:length]
95
void slice_array(ColumnArrayMutableData& dst, ColumnArrayExecutionData& src,
96
                 const IColumn& offset_column, const IColumn* length_column);
97
98
using ColumnArrayExecutionDatas = std::vector<ColumnArrayExecutionData>;
99
#include "common/compile_check_end.h"
100
} // namespace doris