Coverage Report

Created: 2026-03-13 05:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/dictionary.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
18
#pragma once
19
20
#include <memory>
21
#include <type_traits>
22
#include <unordered_map>
23
#include <utility>
24
#include <vector>
25
26
#include "core/assert_cast.h"
27
#include "core/column/column.h"
28
#include "core/column/column_string.h"
29
#include "core/data_type/data_type.h"
30
#include "core/data_type/data_type_date_or_datetime_v2.h"
31
#include "core/data_type/data_type_date_time.h"
32
#include "core/data_type/data_type_ipv4.h"
33
#include "core/data_type/data_type_ipv6.h"
34
#include "core/data_type/data_type_number.h"
35
#include "core/data_type/data_type_string.h"
36
#include "core/types.h"
37
#include "exprs/function/cast_type_to_either.h"
38
39
namespace doris {
40
class MemTrackerLimiter;
41
}
42
class DictionaryFactory;
43
namespace doris {
44
/*
45
 * Dictionary implementation in Doris that provides key-value mapping functionality
46
 * Currently only supports in-memory dictionary storage
47
 */
48
49
const static std::string DICT_DATA_ERROR_TAG = "[INVALID_DICT_MARK]";
50
51
struct DictionaryAttribute {
52
    const std::string name; // value name
53
    const DataTypePtr type; // value type
54
};
55
56
// Abstract base class IDictionary that only stores values. Keys are maintained by specific derived classes
57
// IDictionary serves as the foundation for dictionary implementations where:
58
// - Only values are stored at the base level
59
// - Key management is delegated to derived classes
60
// - Provides interface for dictionary operations
61
class IDictionary {
62
public:
63
    IDictionary(std::string name, std::vector<DictionaryAttribute> values);
64
    virtual ~IDictionary();
65
50
    std::string dict_name() const { return _dict_name; }
66
67
    // Returns the result column, throws an exception if there is an issue
68
    // attribute_type , key_type must be no nullable type
69
    virtual ColumnPtr get_column(const std::string& attribute_name,
70
                                 const DataTypePtr& attribute_type, const ColumnPtr& key_column,
71
                                 const DataTypePtr& key_type) const = 0;
72
73
    // Returns multiple result columns, throws an exception if there is an issue
74
    // The default implementation calls get_column. If a more performant implementation is needed, this method can be overridden
75
    virtual ColumnPtrs get_columns(const std::vector<std::string>& attribute_names,
76
                                   const DataTypes& attribute_types, const ColumnPtr& key_column,
77
0
                                   const DataTypePtr& key_type) const {
78
0
        ColumnPtrs columns;
79
0
        for (size_t i = 0; i < attribute_names.size(); ++i) {
80
0
            columns.push_back(
81
0
                    get_column(attribute_names[i], attribute_types[i], key_column, key_type));
82
0
        }
83
0
        return columns;
84
0
    }
85
86
    // Compared to get_column and get_columns, supports multiple key columns and multiple value columns
87
    // The default implementation only supports one key column, such as IPAddressDictionary, HashMapDictionary
88
    // If support for multiple key columns is needed, this method can be overridden
89
    virtual ColumnPtrs get_tuple_columns(const std::vector<std::string>& attribute_names,
90
                                         const DataTypes& attribute_types,
91
                                         const ColumnPtrs& key_columns,
92
0
                                         const DataTypes& key_types) const {
93
0
        if (key_types.size() != 1) {
94
0
            throw doris::Exception(ErrorCode::INTERNAL_ERROR,
95
0
                                   "Dictionary {} does not support multiple key columns",
96
0
                                   dict_name());
97
0
        }
98
0
        return get_columns(attribute_names, attribute_types, key_columns[0], key_types[0]);
99
0
    }
100
101
    bool has_attribute(const std::string& name) const;
102
103
    // will return a non-nullable type
104
    DataTypePtr get_attribute_type(const std::string& name) const;
105
    size_t attribute_index(const std::string& name) const;
106
107
    bool attribute_is_nullable(size_t idx) const;
108
109
    std::variant<std::false_type, std::true_type> attribute_nullable_variant(size_t idx) const;
110
111
    template <typename F>
112
787
    static bool cast_type(const IDataType* type, F&& f) {
113
        // The data types supported by cast_type must be consistent with the AttributeData below.
114
787
        return cast_type_to_either<DataTypeUInt8, DataTypeInt8, DataTypeInt16, DataTypeInt32,
115
787
                                   DataTypeInt64, DataTypeInt128, DataTypeFloat32, DataTypeFloat64,
116
787
                                   DataTypeIPv4, DataTypeIPv6, DataTypeString, DataTypeDateV2,
117
787
                                   DataTypeDateTimeV2, DataTypeDecimal32, DataTypeDecimal64,
118
787
                                   DataTypeDecimal128, DataTypeDecimal256>(type,
119
787
                                                                           std::forward<F>(f));
120
787
    }
121
122
    virtual size_t allocated_bytes() const;
123
124
protected:
125
    friend class DictionaryFactory;
126
127
    // Only used to distinguish from DataTypeString, used for ColumnWithType
128
    struct DictDataTypeString64 {
129
        using ColumnType = ColumnString;
130
    };
131
132
    template <typename Type>
133
    struct ColumnWithType {
134
        // OutputColumnType is used as the result column type
135
        ColumnPtr null_map;
136
        // RealColumnType is the real type of the column, as there may be ColumnString64, but the result column will not be ColumnString64
137
138
        using OutputColumnType = Type::ColumnType;
139
        using RealColumnType = std::conditional_t<std::is_same_v<DictDataTypeString64, Type>,
140
                                                  ColumnString64, OutputColumnType>;
141
        RealColumnType::Ptr column;
142
16.3k
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE2EEEE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE3EEEE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE4EEEE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE5EEEE3getEv
Line
Count
Source
142
3.36k
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE6EEEE3getEv
Line
Count
Source
142
84
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE7EEEE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE8EEEE3getEv
Line
Count
Source
142
343
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE9EEEE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv4EE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv6EE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeStringEE3getEv
Line
Count
Source
142
6.78k
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS0_20DictDataTypeString64EE3getEv
Line
Count
Source
142
3.21k
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeDateV2EE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_18DataTypeDateTimeV2EE3getEv
Line
Count
Source
142
1.40k
        const RealColumnType* get() const { return column.get(); }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEEE3getEv
_ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEEE3getEv
Line
Count
Source
142
265
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEEE3getEv
Line
Count
Source
142
264
        const RealColumnType* get() const { return column.get(); }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEEE3getEv
143
144
18.2k
        const ColumnUInt8* get_null_map() const {
145
18.2k
            if (!null_map) {
146
14.4k
                return nullptr;
147
14.4k
            }
148
3.80k
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
18.2k
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE2EEEE12get_null_mapEv
Line
Count
Source
144
78
        const ColumnUInt8* get_null_map() const {
145
78
            if (!null_map) {
146
78
                return nullptr;
147
78
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE3EEEE12get_null_mapEv
Line
Count
Source
144
78
        const ColumnUInt8* get_null_map() const {
145
78
            if (!null_map) {
146
78
                return nullptr;
147
78
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE4EEEE12get_null_mapEv
Line
Count
Source
144
78
        const ColumnUInt8* get_null_map() const {
145
78
            if (!null_map) {
146
78
                return nullptr;
147
78
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE5EEEE12get_null_mapEv
Line
Count
Source
144
4.43k
        const ColumnUInt8* get_null_map() const {
145
4.43k
            if (!null_map) {
146
2.25k
                return nullptr;
147
2.25k
            }
148
2.17k
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
4.43k
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE6EEEE12get_null_mapEv
Line
Count
Source
144
82
        const ColumnUInt8* get_null_map() const {
145
82
            if (!null_map) {
146
82
                return nullptr;
147
82
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
82
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE7EEEE12get_null_mapEv
Line
Count
Source
144
78
        const ColumnUInt8* get_null_map() const {
145
78
            if (!null_map) {
146
78
                return nullptr;
147
78
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE8EEEE12get_null_mapEv
Line
Count
Source
144
343
        const ColumnUInt8* get_null_map() const {
145
343
            if (!null_map) {
146
343
                return nullptr;
147
343
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
343
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE9EEEE12get_null_mapEv
Line
Count
Source
144
78
        const ColumnUInt8* get_null_map() const {
145
78
            if (!null_map) {
146
78
                return nullptr;
147
78
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv4EE12get_null_mapEv
Line
Count
Source
144
78
        const ColumnUInt8* get_null_map() const {
145
78
            if (!null_map) {
146
78
                return nullptr;
147
78
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv6EE12get_null_mapEv
Line
Count
Source
144
78
        const ColumnUInt8* get_null_map() const {
145
78
            if (!null_map) {
146
78
                return nullptr;
147
78
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeStringEE12get_null_mapEv
Line
Count
Source
144
7.58k
        const ColumnUInt8* get_null_map() const {
145
7.58k
            if (!null_map) {
146
5.95k
                return nullptr;
147
5.95k
            }
148
1.62k
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
7.58k
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS0_20DictDataTypeString64EE12get_null_mapEv
Line
Count
Source
144
3.21k
        const ColumnUInt8* get_null_map() const {
145
3.21k
            if (!null_map) {
146
3.21k
                return nullptr;
147
3.21k
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
3.21k
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeDateV2EE12get_null_mapEv
Line
Count
Source
144
78
        const ColumnUInt8* get_null_map() const {
145
78
            if (!null_map) {
146
78
                return nullptr;
147
78
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_18DataTypeDateTimeV2EE12get_null_mapEv
Line
Count
Source
144
1.40k
        const ColumnUInt8* get_null_map() const {
145
1.40k
            if (!null_map) {
146
1.40k
                return nullptr;
147
1.40k
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
1.40k
        }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEEE12get_null_mapEv
_ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEEE12get_null_mapEv
Line
Count
Source
144
265
        const ColumnUInt8* get_null_map() const {
145
265
            if (!null_map) {
146
265
                return nullptr;
147
265
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
265
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEEE12get_null_mapEv
Line
Count
Source
144
264
        const ColumnUInt8* get_null_map() const {
145
264
            if (!null_map) {
146
264
                return nullptr;
147
264
            }
148
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
149
264
        }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEEE12get_null_mapEv
150
    };
151
152
    // res_real_column : result column (get_column result)
153
    // res_null : if value is null, will set res_null to true
154
    // value_column : corresponding value column, non-nullable
155
    // value_null_column : corresponding value null map, if the original value is non-nullable, it will be nullptr
156
    // value_idx : index in the value column
157
    template <bool value_is_nullable, typename ResultColumnType>
158
    ALWAYS_INLINE static void set_value_data(ResultColumnType* res_real_column, UInt8& res_null,
159
                                             const auto* value_column,
160
                                             const ColumnUInt8* value_null_column,
161
56.0k
                                             const size_t& value_idx) {
162
56.0k
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
51
            if (value_null_column->get_element(value_idx)) {
165
25
                res_null = true;
166
25
                res_real_column->insert_default();
167
25
                return;
168
25
            }
169
51
        }
170
4.48k
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
4.48k
            StringRef str_ref = value_column->get_data_at(value_idx);
173
4.48k
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
51.5k
        } else {
175
51.5k
            res_real_column->insert_value(value_column->get_element(value_idx));
176
51.5k
        }
177
56.0k
    }
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE2EEES4_EEvPT0_RhPKT1_PKS4_RKm
Line
Count
Source
161
4.29k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
4.29k
        } else {
175
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
176
4.29k
        }
177
4.29k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE2EEES4_EEvPT0_RhPKT1_PKS4_RKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE3EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
161
4.29k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
4.29k
        } else {
175
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
176
4.29k
        }
177
4.29k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE3EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE4EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
161
4.29k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
4.29k
        } else {
175
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
176
4.29k
        }
177
4.29k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE4EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE5EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
161
4.31k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
4.31k
        } else {
175
4.31k
            res_real_column->insert_value(value_column->get_element(value_idx));
176
4.31k
        }
177
4.31k
    }
_ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE5EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
161
37
                                             const size_t& value_idx) {
162
37
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
37
            if (value_null_column->get_element(value_idx)) {
165
18
                res_null = true;
166
18
                res_real_column->insert_default();
167
18
                return;
168
18
            }
169
37
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
37
        } else {
175
37
            res_real_column->insert_value(value_column->get_element(value_idx));
176
37
        }
177
37
    }
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE6EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
161
4.32k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
4.32k
        } else {
175
4.32k
            res_real_column->insert_value(value_column->get_element(value_idx));
176
4.32k
        }
177
4.32k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE6EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE7EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
161
4.29k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
4.29k
        } else {
175
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
176
4.29k
        }
177
4.29k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE7EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE8EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
161
4.29k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
4.29k
        } else {
175
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
176
4.29k
        }
177
4.29k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE8EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE9EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
161
4.29k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
4.29k
        } else {
175
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
176
4.29k
        }
177
4.29k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE9EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE36EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
161
4.29k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
4.29k
        } else {
175
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
176
4.29k
        }
177
4.29k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE36EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE37EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
161
4.29k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
4.29k
        } else {
175
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
176
4.29k
        }
177
4.29k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE37EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_9ColumnStrIjEES3_EEvPT0_RhPKT1_PKNS_12ColumnVectorILNS_13PrimitiveTypeE2EEERKm
Line
Count
Source
161
2.90k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
2.90k
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
2.90k
            StringRef str_ref = value_column->get_data_at(value_idx);
173
2.90k
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
        } else {
175
            res_real_column->insert_value(value_column->get_element(value_idx));
176
        }
177
2.90k
    }
_ZN5doris11IDictionary14set_value_dataILb1ENS_9ColumnStrIjEES3_EEvPT0_RhPKT1_PKNS_12ColumnVectorILNS_13PrimitiveTypeE2EEERKm
Line
Count
Source
161
14
                                             const size_t& value_idx) {
162
14
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
14
            if (value_null_column->get_element(value_idx)) {
165
7
                res_null = true;
166
7
                res_real_column->insert_default();
167
7
                return;
168
7
            }
169
14
        }
170
14
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
14
            StringRef str_ref = value_column->get_data_at(value_idx);
173
14
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
        } else {
175
            res_real_column->insert_value(value_column->get_element(value_idx));
176
        }
177
14
    }
_ZN5doris11IDictionary14set_value_dataILb0ENS_9ColumnStrIjEENS2_ImEEEEvPT0_RhPKT1_PKNS_12ColumnVectorILNS_13PrimitiveTypeE2EEERKm
Line
Count
Source
161
1.57k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
1.57k
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
1.57k
            StringRef str_ref = value_column->get_data_at(value_idx);
173
1.57k
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
        } else {
175
            res_real_column->insert_value(value_column->get_element(value_idx));
176
        }
177
1.57k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_9ColumnStrIjEENS2_ImEEEEvPT0_RhPKT1_PKNS_12ColumnVectorILNS_13PrimitiveTypeE2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE25EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
161
4.29k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
4.29k
        } else {
175
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
176
4.29k
        }
177
4.29k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE25EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE26EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
161
4.29k
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
4.29k
        } else {
175
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
176
4.29k
        }
177
4.29k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE26EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb0ENS_13ColumnDecimalILNS_13PrimitiveTypeE28EEES4_EEvPT0_RhPKT1_PKNS_12ColumnVectorILS3_2EEERKm
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_13ColumnDecimalILNS_13PrimitiveTypeE28EEES4_EEvPT0_RhPKT1_PKNS_12ColumnVectorILS3_2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_13ColumnDecimalILNS_13PrimitiveTypeE29EEES4_EEvPT0_RhPKT1_PKNS_12ColumnVectorILS3_2EEERKm
Line
Count
Source
161
2
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
2
        } else {
175
2
            res_real_column->insert_value(value_column->get_element(value_idx));
176
2
        }
177
2
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_13ColumnDecimalILNS_13PrimitiveTypeE29EEES4_EEvPT0_RhPKT1_PKNS_12ColumnVectorILS3_2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_13ColumnDecimalILNS_13PrimitiveTypeE30EEES4_EEvPT0_RhPKT1_PKNS_12ColumnVectorILS3_2EEERKm
Line
Count
Source
161
2
                                             const size_t& value_idx) {
162
        if constexpr (value_is_nullable) {
163
            // if the value is null, set the result column to null
164
            if (value_null_column->get_element(value_idx)) {
165
                res_null = true;
166
                res_real_column->insert_default();
167
                return;
168
            }
169
        }
170
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
171
            // If it is a string column, use get_data_at to avoid copying
172
            StringRef str_ref = value_column->get_data_at(value_idx);
173
            res_real_column->insert_data(str_ref.data, str_ref.size);
174
2
        } else {
175
2
            res_real_column->insert_value(value_column->get_element(value_idx));
176
2
        }
177
2
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_13ColumnDecimalILNS_13PrimitiveTypeE30EEES4_EEvPT0_RhPKT1_PKNS_12ColumnVectorILS3_2EEERKm
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb0ENS_13ColumnDecimalILNS_13PrimitiveTypeE35EEES4_EEvPT0_RhPKT1_PKNS_12ColumnVectorILS3_2EEERKm
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_13ColumnDecimalILNS_13PrimitiveTypeE35EEES4_EEvPT0_RhPKT1_PKNS_12ColumnVectorILS3_2EEERKm
178
179
    /// TODO: Add support for more data types ,such as Array, Map, etc.
180
    using ValueData =
181
            std::variant<ColumnWithType<DataTypeUInt8>, ColumnWithType<DataTypeInt8>,
182
                         ColumnWithType<DataTypeInt16>, ColumnWithType<DataTypeInt32>,
183
                         ColumnWithType<DataTypeInt64>, ColumnWithType<DataTypeInt128>,
184
185
                         ColumnWithType<DataTypeFloat32>, ColumnWithType<DataTypeFloat64>,
186
187
                         ColumnWithType<DataTypeIPv4>, ColumnWithType<DataTypeIPv6>,
188
189
                         ColumnWithType<DataTypeString>, ColumnWithType<DictDataTypeString64>,
190
191
                         ColumnWithType<DataTypeDateV2>, ColumnWithType<DataTypeDateTimeV2>,
192
193
                         ColumnWithType<DataTypeDecimal32>, ColumnWithType<DataTypeDecimal64>,
194
                         ColumnWithType<DataTypeDecimal128>, ColumnWithType<DataTypeDecimal256>>;
195
196
    void load_values(const std::vector<ColumnPtr>& values_column);
197
198
    // _value_data is used to store the data of value columns.
199
    std::vector<ValueData> _values_data;
200
    std::string _dict_name;
201
    std::vector<DictionaryAttribute> _attributes;
202
    // A mapping from attribute names to their corresponding indices.
203
    std::unordered_map<std::string, size_t> _name_to_attributes_index;
204
205
    // mem_tracker comes from DictionaryFactory. If _mem_tracker is nullptr, it means it is in UT.
206
    std::shared_ptr<MemTrackerLimiter> _mem_tracker;
207
};
208
209
using DictionaryPtr = std::shared_ptr<IDictionary>;
210
211
} // namespace doris