Coverage Report

Created: 2026-08-21 17:02

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
162
    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
930
    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
930
        return cast_type_to_either<DataTypeUInt8, DataTypeInt8, DataTypeInt16, DataTypeInt32,
115
930
                                   DataTypeInt64, DataTypeInt128, DataTypeFloat32, DataTypeFloat64,
116
930
                                   DataTypeIPv4, DataTypeIPv6, DataTypeString, DataTypeDateV2,
117
930
                                   DataTypeDateTimeV2, DataTypeDecimal32, DataTypeDecimal64,
118
930
                                   DataTypeDecimal128, DataTypeDecimal256>(type,
119
930
                                                                           std::forward<F>(f));
120
930
    }
121
122
    virtual size_t allocated_bytes() const;
123
124
149
    void set_commit_time_ms(int64_t ts) { _commit_time_ms = ts; }
125
16
    int64_t commit_time_ms() const { return _commit_time_ms; }
126
127
protected:
128
    friend class DictionaryFactory;
129
130
    // Only used to distinguish from DataTypeString, used for ColumnWithType
131
    struct DictDataTypeString64 {
132
        using ColumnType = ColumnString;
133
    };
134
135
    template <typename Type>
136
    struct ColumnWithType {
137
        // OutputColumnType is used as the result column type
138
        ColumnPtr null_map;
139
        // RealColumnType is the real type of the column, as there may be ColumnString64, but the result column will not be ColumnString64
140
141
        using OutputColumnType = Type::ColumnType;
142
        using RealColumnType = std::conditional_t<std::is_same_v<DictDataTypeString64, Type>,
143
                                                  ColumnString64, OutputColumnType>;
144
        RealColumnType::Ptr column;
145
12.1k
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE2EEEE3getEv
Line
Count
Source
145
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE3EEEE3getEv
Line
Count
Source
145
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE4EEEE3getEv
Line
Count
Source
145
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE5EEEE3getEv
Line
Count
Source
145
2.31k
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE6EEEE3getEv
Line
Count
Source
145
84
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE7EEEE3getEv
Line
Count
Source
145
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE8EEEE3getEv
Line
Count
Source
145
290
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE9EEEE3getEv
Line
Count
Source
145
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv4EE3getEv
Line
Count
Source
145
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv6EE3getEv
Line
Count
Source
145
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeStringEE3getEv
Line
Count
Source
145
7.19k
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS0_20DictDataTypeString64EE3getEv
Line
Count
Source
145
27
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeDateV2EE3getEv
Line
Count
Source
145
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_18DataTypeDateTimeV2EE3getEv
Line
Count
Source
145
1.14k
        const RealColumnType* get() const { return column.get(); }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEEE3getEv
_ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEEE3getEv
Line
Count
Source
145
213
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEEE3getEv
Line
Count
Source
145
212
        const RealColumnType* get() const { return column.get(); }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEEE3getEv
146
147
13.5k
        const ColumnUInt8* get_null_map() const {
148
13.5k
            if (!null_map) {
149
10.5k
                return nullptr;
150
10.5k
            }
151
3.04k
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
13.5k
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE2EEEE12get_null_mapEv
Line
Count
Source
147
78
        const ColumnUInt8* get_null_map() const {
148
78
            if (!null_map) {
149
78
                return nullptr;
150
78
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE3EEEE12get_null_mapEv
Line
Count
Source
147
78
        const ColumnUInt8* get_null_map() const {
148
78
            if (!null_map) {
149
78
                return nullptr;
150
78
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE4EEEE12get_null_mapEv
Line
Count
Source
147
78
        const ColumnUInt8* get_null_map() const {
148
78
            if (!null_map) {
149
78
                return nullptr;
150
78
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE5EEEE12get_null_mapEv
Line
Count
Source
147
3.16k
        const ColumnUInt8* get_null_map() const {
148
3.16k
            if (!null_map) {
149
1.42k
                return nullptr;
150
1.42k
            }
151
1.74k
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
3.16k
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE6EEEE12get_null_mapEv
Line
Count
Source
147
82
        const ColumnUInt8* get_null_map() const {
148
82
            if (!null_map) {
149
82
                return nullptr;
150
82
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
82
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE7EEEE12get_null_mapEv
Line
Count
Source
147
78
        const ColumnUInt8* get_null_map() const {
148
78
            if (!null_map) {
149
78
                return nullptr;
150
78
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE8EEEE12get_null_mapEv
Line
Count
Source
147
290
        const ColumnUInt8* get_null_map() const {
148
290
            if (!null_map) {
149
290
                return nullptr;
150
290
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
290
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE9EEEE12get_null_mapEv
Line
Count
Source
147
78
        const ColumnUInt8* get_null_map() const {
148
78
            if (!null_map) {
149
78
                return nullptr;
150
78
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv4EE12get_null_mapEv
Line
Count
Source
147
78
        const ColumnUInt8* get_null_map() const {
148
78
            if (!null_map) {
149
78
                return nullptr;
150
78
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv6EE12get_null_mapEv
Line
Count
Source
147
78
        const ColumnUInt8* get_null_map() const {
148
78
            if (!null_map) {
149
78
                return nullptr;
150
78
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeStringEE12get_null_mapEv
Line
Count
Source
147
7.82k
        const ColumnUInt8* get_null_map() const {
148
7.82k
            if (!null_map) {
149
6.52k
                return nullptr;
150
6.52k
            }
151
1.29k
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
7.82k
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS0_20DictDataTypeString64EE12get_null_mapEv
Line
Count
Source
147
27
        const ColumnUInt8* get_null_map() const {
148
27
            if (!null_map) {
149
27
                return nullptr;
150
27
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
27
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeDateV2EE12get_null_mapEv
Line
Count
Source
147
78
        const ColumnUInt8* get_null_map() const {
148
78
            if (!null_map) {
149
78
                return nullptr;
150
78
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_18DataTypeDateTimeV2EE12get_null_mapEv
Line
Count
Source
147
1.14k
        const ColumnUInt8* get_null_map() const {
148
1.14k
            if (!null_map) {
149
1.14k
                return nullptr;
150
1.14k
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
1.14k
        }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEEE12get_null_mapEv
_ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEEE12get_null_mapEv
Line
Count
Source
147
213
        const ColumnUInt8* get_null_map() const {
148
213
            if (!null_map) {
149
213
                return nullptr;
150
213
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
213
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEEE12get_null_mapEv
Line
Count
Source
147
212
        const ColumnUInt8* get_null_map() const {
148
212
            if (!null_map) {
149
212
                return nullptr;
150
212
            }
151
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
152
212
        }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEEE12get_null_mapEv
153
    };
154
155
    // res_real_column : result column (get_column result)
156
    // res_null : if value is null, will set res_null to true
157
    // value_column : corresponding value column, non-nullable
158
    // value_null_column : corresponding value null map, if the original value is non-nullable, it will be nullptr
159
    // value_idx : index in the value column
160
    template <bool value_is_nullable, typename ResultColumnType>
161
    ALWAYS_INLINE static void set_value_data(ResultColumnType* res_real_column, UInt8& res_null,
162
                                             const auto* value_column,
163
                                             const ColumnUInt8* value_null_column,
164
56.0k
                                             const size_t& value_idx) {
165
56.0k
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
51
            if (value_null_column->get_element(value_idx)) {
168
25
                res_null = true;
169
25
                res_real_column->insert_default();
170
25
                return;
171
25
            }
172
51
        }
173
4.48k
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
4.48k
            StringRef str_ref = value_column->get_data_at(value_idx);
176
4.48k
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
51.5k
        } else {
178
51.5k
            res_real_column->insert_value(value_column->get_element(value_idx));
179
51.5k
        }
180
56.0k
    }
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE2EEES4_EEvPT0_RhPKT1_PKS4_RKm
Line
Count
Source
164
4.29k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
4.29k
        } else {
178
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
179
4.29k
        }
180
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
164
4.29k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
4.29k
        } else {
178
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
179
4.29k
        }
180
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
164
4.29k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
4.29k
        } else {
178
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
179
4.29k
        }
180
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
164
4.31k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
4.31k
        } else {
178
4.31k
            res_real_column->insert_value(value_column->get_element(value_idx));
179
4.31k
        }
180
4.31k
    }
_ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE5EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
164
37
                                             const size_t& value_idx) {
165
37
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
37
            if (value_null_column->get_element(value_idx)) {
168
18
                res_null = true;
169
18
                res_real_column->insert_default();
170
18
                return;
171
18
            }
172
37
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
37
        } else {
178
37
            res_real_column->insert_value(value_column->get_element(value_idx));
179
37
        }
180
37
    }
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE6EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
164
4.32k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
4.32k
        } else {
178
4.32k
            res_real_column->insert_value(value_column->get_element(value_idx));
179
4.32k
        }
180
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
164
4.29k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
4.29k
        } else {
178
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
179
4.29k
        }
180
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
164
4.29k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
4.29k
        } else {
178
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
179
4.29k
        }
180
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
164
4.29k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
4.29k
        } else {
178
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
179
4.29k
        }
180
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
164
4.29k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
4.29k
        } else {
178
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
179
4.29k
        }
180
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
164
4.29k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
4.29k
        } else {
178
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
179
4.29k
        }
180
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
164
3.02k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
3.02k
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
3.02k
            StringRef str_ref = value_column->get_data_at(value_idx);
176
3.02k
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
        } else {
178
            res_real_column->insert_value(value_column->get_element(value_idx));
179
        }
180
3.02k
    }
_ZN5doris11IDictionary14set_value_dataILb1ENS_9ColumnStrIjEES3_EEvPT0_RhPKT1_PKNS_12ColumnVectorILNS_13PrimitiveTypeE2EEERKm
Line
Count
Source
164
14
                                             const size_t& value_idx) {
165
14
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
14
            if (value_null_column->get_element(value_idx)) {
168
7
                res_null = true;
169
7
                res_real_column->insert_default();
170
7
                return;
171
7
            }
172
14
        }
173
14
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
14
            StringRef str_ref = value_column->get_data_at(value_idx);
176
14
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
        } else {
178
            res_real_column->insert_value(value_column->get_element(value_idx));
179
        }
180
14
    }
_ZN5doris11IDictionary14set_value_dataILb0ENS_9ColumnStrIjEENS2_ImEEEEvPT0_RhPKT1_PKNS_12ColumnVectorILNS_13PrimitiveTypeE2EEERKm
Line
Count
Source
164
1.44k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
1.44k
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
1.44k
            StringRef str_ref = value_column->get_data_at(value_idx);
176
1.44k
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
        } else {
178
            res_real_column->insert_value(value_column->get_element(value_idx));
179
        }
180
1.44k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_9ColumnStrIjEENS2_ImEEEEvPT0_RhPKT1_PKNS_12ColumnVectorILNS_13PrimitiveTypeE2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE25EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
164
4.29k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
4.29k
        } else {
178
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
179
4.29k
        }
180
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
164
4.29k
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
4.29k
        } else {
178
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
179
4.29k
        }
180
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
164
2
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
2
        } else {
178
2
            res_real_column->insert_value(value_column->get_element(value_idx));
179
2
        }
180
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
164
2
                                             const size_t& value_idx) {
165
        if constexpr (value_is_nullable) {
166
            // if the value is null, set the result column to null
167
            if (value_null_column->get_element(value_idx)) {
168
                res_null = true;
169
                res_real_column->insert_default();
170
                return;
171
            }
172
        }
173
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
174
            // If it is a string column, use get_data_at to avoid copying
175
            StringRef str_ref = value_column->get_data_at(value_idx);
176
            res_real_column->insert_data(str_ref.data, str_ref.size);
177
2
        } else {
178
2
            res_real_column->insert_value(value_column->get_element(value_idx));
179
2
        }
180
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
181
182
    /// TODO: Add support for more data types ,such as Array, Map, etc.
183
    using ValueData =
184
            std::variant<ColumnWithType<DataTypeUInt8>, ColumnWithType<DataTypeInt8>,
185
                         ColumnWithType<DataTypeInt16>, ColumnWithType<DataTypeInt32>,
186
                         ColumnWithType<DataTypeInt64>, ColumnWithType<DataTypeInt128>,
187
188
                         ColumnWithType<DataTypeFloat32>, ColumnWithType<DataTypeFloat64>,
189
190
                         ColumnWithType<DataTypeIPv4>, ColumnWithType<DataTypeIPv6>,
191
192
                         ColumnWithType<DataTypeString>, ColumnWithType<DictDataTypeString64>,
193
194
                         ColumnWithType<DataTypeDateV2>, ColumnWithType<DataTypeDateTimeV2>,
195
196
                         ColumnWithType<DataTypeDecimal32>, ColumnWithType<DataTypeDecimal64>,
197
                         ColumnWithType<DataTypeDecimal128>, ColumnWithType<DataTypeDecimal256>>;
198
199
    void load_values(const std::vector<ColumnPtr>& values_column);
200
201
    // _value_data is used to store the data of value columns.
202
    std::vector<ValueData> _values_data;
203
    std::string _dict_name;
204
    std::vector<DictionaryAttribute> _attributes;
205
    // A mapping from attribute names to their corresponding indices.
206
    std::unordered_map<std::string, size_t> _name_to_attributes_index;
207
208
    // mem_tracker comes from DictionaryFactory. If _mem_tracker is nullptr, it means it is in UT.
209
    std::shared_ptr<MemTrackerLimiter> _mem_tracker;
210
211
    // set by DictionaryFactory at commit time, used for TTL-based GC
212
    int64_t _commit_time_ms = 0;
213
};
214
215
using DictionaryPtr = std::shared_ptr<IDictionary>;
216
217
} // namespace doris