Coverage Report

Created: 2026-10-19 09:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/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/data_type/data_type_timestamp_ns.h"
37
#include "core/types.h"
38
#include "exprs/function/cast_type_to_either.h"
39
40
namespace doris {
41
class MemTrackerLimiter;
42
}
43
class DictionaryFactory;
44
namespace doris {
45
/*
46
 * Dictionary implementation in Doris that provides key-value mapping functionality
47
 * Currently only supports in-memory dictionary storage
48
 */
49
50
const static std::string DICT_DATA_ERROR_TAG = "[INVALID_DICT_MARK]";
51
52
struct DictionaryAttribute {
53
    const std::string name; // value name
54
    const DataTypePtr type; // value type
55
};
56
57
// Abstract base class IDictionary that only stores values. Keys are maintained by specific derived classes
58
// IDictionary serves as the foundation for dictionary implementations where:
59
// - Only values are stored at the base level
60
// - Key management is delegated to derived classes
61
// - Provides interface for dictionary operations
62
class IDictionary {
63
public:
64
    IDictionary(std::string name, std::vector<DictionaryAttribute> values);
65
    virtual ~IDictionary();
66
5
    std::string dict_name() const { return _dict_name; }
67
68
    // Returns the result column, throws an exception if there is an issue
69
    // attribute_type , key_type must be no nullable type
70
    virtual ColumnPtr get_column(const std::string& attribute_name,
71
                                 const DataTypePtr& attribute_type, const ColumnPtr& key_column,
72
                                 const DataTypePtr& key_type) const = 0;
73
74
    // Returns multiple result columns, throws an exception if there is an issue
75
    // The default implementation calls get_column. If a more performant implementation is needed, this method can be overridden
76
    virtual ColumnPtrs get_columns(const std::vector<std::string>& attribute_names,
77
                                   const DataTypes& attribute_types, const ColumnPtr& key_column,
78
0
                                   const DataTypePtr& key_type) const {
79
0
        ColumnPtrs columns;
80
0
        for (size_t i = 0; i < attribute_names.size(); ++i) {
81
0
            columns.push_back(
82
0
                    get_column(attribute_names[i], attribute_types[i], key_column, key_type));
83
0
        }
84
0
        return columns;
85
0
    }
86
87
    // Compared to get_column and get_columns, supports multiple key columns and multiple value columns
88
    // The default implementation only supports one key column, such as IPAddressDictionary, HashMapDictionary
89
    // If support for multiple key columns is needed, this method can be overridden
90
    virtual ColumnPtrs get_tuple_columns(const std::vector<std::string>& attribute_names,
91
                                         const DataTypes& attribute_types,
92
                                         const ColumnPtrs& key_columns,
93
0
                                         const DataTypes& key_types) const {
94
0
        if (key_types.size() != 1) {
95
0
            throw doris::Exception(ErrorCode::INTERNAL_ERROR,
96
0
                                   "Dictionary {} does not support multiple key columns",
97
0
                                   dict_name());
98
0
        }
99
0
        return get_columns(attribute_names, attribute_types, key_columns[0], key_types[0]);
100
0
    }
101
102
    bool has_attribute(const std::string& name) const;
103
104
    // will return a non-nullable type
105
    DataTypePtr get_attribute_type(const std::string& name) const;
106
    size_t attribute_index(const std::string& name) const;
107
108
    bool attribute_is_nullable(size_t idx) const;
109
110
    std::variant<std::false_type, std::true_type> attribute_nullable_variant(size_t idx) const;
111
112
    template <typename F>
113
700
    static bool cast_type(const IDataType* type, F&& f) {
114
        // The data types supported by cast_type must be consistent with the AttributeData below.
115
700
        return cast_type_to_either<DataTypeUInt8, DataTypeInt8, DataTypeInt16, DataTypeInt32,
116
700
                                   DataTypeInt64, DataTypeInt128, DataTypeFloat32, DataTypeFloat64,
117
700
                                   DataTypeIPv4, DataTypeIPv6, DataTypeString, DataTypeDateV2,
118
700
                                   DataTypeDateTimeV2, DataTypeTimeStampNs, DataTypeDecimal32,
119
700
                                   DataTypeDecimal64, DataTypeDecimal128, DataTypeDecimal256>(
120
700
                type, std::forward<F>(f));
121
700
    }
122
123
    virtual size_t allocated_bytes() const;
124
125
protected:
126
    friend class DictionaryFactory;
127
128
    // Only used to distinguish from DataTypeString, used for ColumnWithType
129
    struct DictDataTypeString64 {
130
        using ColumnType = ColumnString;
131
    };
132
133
    template <typename Type>
134
    struct ColumnWithType {
135
        // OutputColumnType is used as the result column type
136
        using OutputColumnType = Type::ColumnType;
137
        ColumnPtr column;
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
        using RealColumnType = std::conditional_t<std::is_same_v<DictDataTypeString64, Type>,
141
                                                  ColumnString64, OutputColumnType>;
142
1.04k
        const RealColumnType* get() const {
143
1.04k
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
1.04k
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE2EEEE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const {
143
78
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE3EEEE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const {
143
78
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE4EEEE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const {
143
78
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE5EEEE3getEv
Line
Count
Source
142
97
        const RealColumnType* get() const {
143
97
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
97
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE6EEEE3getEv
Line
Count
Source
142
84
        const RealColumnType* get() const {
143
84
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
84
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE7EEEE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const {
143
78
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE8EEEE3getEv
Line
Count
Source
142
79
        const RealColumnType* get() const {
143
79
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
79
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE9EEEE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const {
143
78
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv4EE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const {
143
78
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv6EE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const {
143
78
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeStringEE3getEv
Line
Count
Source
142
55
        const RealColumnType* get() const {
143
55
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
55
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS0_20DictDataTypeString64EE3getEv
Line
Count
Source
142
27
        const RealColumnType* get() const {
143
27
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
27
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeDateV2EE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const {
143
78
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_18DataTypeDateTimeV2EE3getEv
Line
Count
Source
142
78
        const RealColumnType* get() const {
143
78
            return assert_cast<const RealColumnType*, TypeCheckOnRelease::DISABLE>(column.get());
144
78
        }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_19DataTypeTimeStampNsEE3getEv
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEEE3getEv
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEEE3getEv
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEEE3getEv
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEEE3getEv
145
146
1.04k
        const ColumnUInt8* get_null_map() const {
147
1.04k
            if (!null_map) {
148
1.03k
                return nullptr;
149
1.03k
            }
150
8
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
1.04k
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE2EEEE12get_null_mapEv
Line
Count
Source
146
78
        const ColumnUInt8* get_null_map() const {
147
78
            if (!null_map) {
148
78
                return nullptr;
149
78
            }
150
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE3EEEE12get_null_mapEv
Line
Count
Source
146
78
        const ColumnUInt8* get_null_map() const {
147
78
            if (!null_map) {
148
78
                return nullptr;
149
78
            }
150
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE4EEEE12get_null_mapEv
Line
Count
Source
146
78
        const ColumnUInt8* get_null_map() const {
147
78
            if (!null_map) {
148
78
                return nullptr;
149
78
            }
150
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE5EEEE12get_null_mapEv
Line
Count
Source
146
97
        const ColumnUInt8* get_null_map() const {
147
97
            if (!null_map) {
148
89
                return nullptr;
149
89
            }
150
8
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
97
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE6EEEE12get_null_mapEv
Line
Count
Source
146
82
        const ColumnUInt8* get_null_map() const {
147
82
            if (!null_map) {
148
82
                return nullptr;
149
82
            }
150
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
82
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE7EEEE12get_null_mapEv
Line
Count
Source
146
78
        const ColumnUInt8* get_null_map() const {
147
78
            if (!null_map) {
148
78
                return nullptr;
149
78
            }
150
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE8EEEE12get_null_mapEv
Line
Count
Source
146
79
        const ColumnUInt8* get_null_map() const {
147
79
            if (!null_map) {
148
79
                return nullptr;
149
79
            }
150
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
79
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE9EEEE12get_null_mapEv
Line
Count
Source
146
78
        const ColumnUInt8* get_null_map() const {
147
78
            if (!null_map) {
148
78
                return nullptr;
149
78
            }
150
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv4EE12get_null_mapEv
Line
Count
Source
146
78
        const ColumnUInt8* get_null_map() const {
147
78
            if (!null_map) {
148
78
                return nullptr;
149
78
            }
150
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv6EE12get_null_mapEv
Line
Count
Source
146
78
        const ColumnUInt8* get_null_map() const {
147
78
            if (!null_map) {
148
78
                return nullptr;
149
78
            }
150
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeStringEE12get_null_mapEv
Line
Count
Source
146
55
        const ColumnUInt8* get_null_map() const {
147
55
            if (!null_map) {
148
55
                return nullptr;
149
55
            }
150
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
55
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS0_20DictDataTypeString64EE12get_null_mapEv
Line
Count
Source
146
27
        const ColumnUInt8* get_null_map() const {
147
27
            if (!null_map) {
148
27
                return nullptr;
149
27
            }
150
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
27
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeDateV2EE12get_null_mapEv
Line
Count
Source
146
78
        const ColumnUInt8* get_null_map() const {
147
78
            if (!null_map) {
148
78
                return nullptr;
149
78
            }
150
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_18DataTypeDateTimeV2EE12get_null_mapEv
Line
Count
Source
146
78
        const ColumnUInt8* get_null_map() const {
147
78
            if (!null_map) {
148
78
                return nullptr;
149
78
            }
150
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
151
78
        }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_19DataTypeTimeStampNsEE12get_null_mapEv
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEEE12get_null_mapEv
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEEE12get_null_mapEv
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEEE12get_null_mapEv
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEEE12get_null_mapEv
152
    };
153
154
    // res_real_column : result column (get_column result)
155
    // res_null : if value is null, will set res_null to true
156
    // value_column : corresponding value column, non-nullable
157
    // value_null_column : corresponding value null map, if the original value is non-nullable, it will be nullptr
158
    // value_idx : index in the value column
159
    template <bool value_is_nullable, typename ResultColumnType>
160
    ALWAYS_INLINE static void set_value_data(ResultColumnType* res_real_column, UInt8& res_null,
161
                                             const auto* value_column,
162
                                             const ColumnUInt8* value_null_column,
163
55.8k
                                             const size_t& value_idx) {
164
55.8k
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
19
            if (value_null_column->get_element(value_idx)) {
167
9
                res_null = true;
168
9
                res_real_column->insert_default();
169
9
                return;
170
9
            }
171
19
        }
172
4.31k
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
4.31k
            StringRef str_ref = value_column->get_data_at(value_idx);
175
4.31k
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
51.5k
        } else {
177
51.5k
            res_real_column->insert_value(value_column->get_element(value_idx));
178
51.5k
        }
179
55.8k
    }
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE2EEES4_EEvPT0_RhPKT1_PKS4_RKm
Line
Count
Source
163
4.29k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
            StringRef str_ref = value_column->get_data_at(value_idx);
175
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
4.29k
        } else {
177
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
178
4.29k
        }
179
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
163
4.29k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
            StringRef str_ref = value_column->get_data_at(value_idx);
175
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
4.29k
        } else {
177
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
178
4.29k
        }
179
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
163
4.29k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
            StringRef str_ref = value_column->get_data_at(value_idx);
175
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
4.29k
        } else {
177
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
178
4.29k
        }
179
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
163
4.30k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
            StringRef str_ref = value_column->get_data_at(value_idx);
175
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
4.30k
        } else {
177
4.30k
            res_real_column->insert_value(value_column->get_element(value_idx));
178
4.30k
        }
179
4.30k
    }
_ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE5EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
163
19
                                             const size_t& value_idx) {
164
19
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
19
            if (value_null_column->get_element(value_idx)) {
167
9
                res_null = true;
168
9
                res_real_column->insert_default();
169
9
                return;
170
9
            }
171
19
        }
172
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
            StringRef str_ref = value_column->get_data_at(value_idx);
175
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
19
        } else {
177
19
            res_real_column->insert_value(value_column->get_element(value_idx));
178
19
        }
179
19
    }
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE6EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
163
4.32k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
            StringRef str_ref = value_column->get_data_at(value_idx);
175
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
4.32k
        } else {
177
4.32k
            res_real_column->insert_value(value_column->get_element(value_idx));
178
4.32k
        }
179
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
163
4.29k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
            StringRef str_ref = value_column->get_data_at(value_idx);
175
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
4.29k
        } else {
177
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
178
4.29k
        }
179
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
163
4.29k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
            StringRef str_ref = value_column->get_data_at(value_idx);
175
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
4.29k
        } else {
177
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
178
4.29k
        }
179
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
163
4.29k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
            StringRef str_ref = value_column->get_data_at(value_idx);
175
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
4.29k
        } else {
177
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
178
4.29k
        }
179
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
163
4.29k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
            StringRef str_ref = value_column->get_data_at(value_idx);
175
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
4.29k
        } else {
177
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
178
4.29k
        }
179
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
163
4.29k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
            StringRef str_ref = value_column->get_data_at(value_idx);
175
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
4.29k
        } else {
177
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
178
4.29k
        }
179
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
163
2.86k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
2.86k
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
2.86k
            StringRef str_ref = value_column->get_data_at(value_idx);
175
2.86k
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
        } else {
177
            res_real_column->insert_value(value_column->get_element(value_idx));
178
        }
179
2.86k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_9ColumnStrIjEES3_EEvPT0_RhPKT1_PKNS_12ColumnVectorILNS_13PrimitiveTypeE2EEERKm
_ZN5doris11IDictionary14set_value_dataILb0ENS_9ColumnStrIjEENS2_ImEEEEvPT0_RhPKT1_PKNS_12ColumnVectorILNS_13PrimitiveTypeE2EEERKm
Line
Count
Source
163
1.44k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
1.44k
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
1.44k
            StringRef str_ref = value_column->get_data_at(value_idx);
175
1.44k
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
        } else {
177
            res_real_column->insert_value(value_column->get_element(value_idx));
178
        }
179
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
163
4.29k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
            StringRef str_ref = value_column->get_data_at(value_idx);
175
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
4.29k
        } else {
177
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
178
4.29k
        }
179
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
163
4.29k
                                             const size_t& value_idx) {
164
        if constexpr (value_is_nullable) {
165
            // if the value is null, set the result column to null
166
            if (value_null_column->get_element(value_idx)) {
167
                res_null = true;
168
                res_real_column->insert_default();
169
                return;
170
            }
171
        }
172
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
173
            // If it is a string column, use get_data_at to avoid copying
174
            StringRef str_ref = value_column->get_data_at(value_idx);
175
            res_real_column->insert_data(str_ref.data, str_ref.size);
176
4.29k
        } else {
177
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
178
4.29k
        }
179
4.29k
    }
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE26EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE43EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE43EEES4_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
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb0ENS_13ColumnDecimalILNS_13PrimitiveTypeE29EEES4_EEvPT0_RhPKT1_PKNS_12ColumnVectorILS3_2EEERKm
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb1ENS_13ColumnDecimalILNS_13PrimitiveTypeE29EEES4_EEvPT0_RhPKT1_PKNS_12ColumnVectorILS3_2EEERKm
Unexecuted instantiation: _ZN5doris11IDictionary14set_value_dataILb0ENS_13ColumnDecimalILNS_13PrimitiveTypeE30EEES4_EEvPT0_RhPKT1_PKNS_12ColumnVectorILS3_2EEERKm
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
180
181
    /// TODO: Add support for more data types ,such as Array, Map, etc.
182
    using ValueData =
183
            std::variant<ColumnWithType<DataTypeUInt8>, ColumnWithType<DataTypeInt8>,
184
                         ColumnWithType<DataTypeInt16>, ColumnWithType<DataTypeInt32>,
185
                         ColumnWithType<DataTypeInt64>, ColumnWithType<DataTypeInt128>,
186
187
                         ColumnWithType<DataTypeFloat32>, ColumnWithType<DataTypeFloat64>,
188
189
                         ColumnWithType<DataTypeIPv4>, ColumnWithType<DataTypeIPv6>,
190
191
                         ColumnWithType<DataTypeString>, ColumnWithType<DictDataTypeString64>,
192
193
                         ColumnWithType<DataTypeDateV2>, ColumnWithType<DataTypeDateTimeV2>,
194
                         ColumnWithType<DataTypeTimeStampNs>,
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
212
using DictionaryPtr = std::shared_ptr<IDictionary>;
213
214
} // namespace doris