Coverage Report

Created: 2026-08-15 21:01

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/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
98
    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
873
    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
873
        return cast_type_to_either<DataTypeUInt8, DataTypeInt8, DataTypeInt16, DataTypeInt32,
116
873
                                   DataTypeInt64, DataTypeInt128, DataTypeFloat32, DataTypeFloat64,
117
873
                                   DataTypeIPv4, DataTypeIPv6, DataTypeString, DataTypeDateV2,
118
873
                                   DataTypeDateTimeV2, DataTypeTimeStampNs, DataTypeDecimal32,
119
873
                                   DataTypeDecimal64, DataTypeDecimal128, DataTypeDecimal256>(
120
873
                type, std::forward<F>(f));
121
873
    }
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
        ColumnPtr null_map;
137
        // RealColumnType is the real type of the column, as there may be ColumnString64, but the result column will not be ColumnString64
138
139
        using OutputColumnType = Type::ColumnType;
140
        using RealColumnType = std::conditional_t<std::is_same_v<DictDataTypeString64, Type>,
141
                                                  ColumnString64, OutputColumnType>;
142
        RealColumnType::Ptr column;
143
13.8k
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE2EEEE3getEv
Line
Count
Source
143
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE3EEEE3getEv
Line
Count
Source
143
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE4EEEE3getEv
Line
Count
Source
143
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE5EEEE3getEv
Line
Count
Source
143
2.64k
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE6EEEE3getEv
Line
Count
Source
143
84
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE7EEEE3getEv
Line
Count
Source
143
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE8EEEE3getEv
Line
Count
Source
143
320
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE9EEEE3getEv
Line
Count
Source
143
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv4EE3getEv
Line
Count
Source
143
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv6EE3getEv
Line
Count
Source
143
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeStringEE3getEv
Line
Count
Source
143
8.19k
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS0_20DictDataTypeString64EE3getEv
Line
Count
Source
143
27
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeDateV2EE3getEv
Line
Count
Source
143
78
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_18DataTypeDateTimeV2EE3getEv
Line
Count
Source
143
1.30k
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_19DataTypeTimeStampNsEE3getEv
Line
Count
Source
143
203
        const RealColumnType* get() const { return column.get(); }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEEE3getEv
_ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEEE3getEv
Line
Count
Source
143
246
        const RealColumnType* get() const { return column.get(); }
_ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEEE3getEv
Line
Count
Source
143
244
        const RealColumnType* get() const { return column.get(); }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEEE3getEv
144
145
15.7k
        const ColumnUInt8* get_null_map() const {
146
15.7k
            if (!null_map) {
147
11.9k
                return nullptr;
148
11.9k
            }
149
3.89k
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
15.7k
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE2EEEE12get_null_mapEv
Line
Count
Source
145
78
        const ColumnUInt8* get_null_map() const {
146
78
            if (!null_map) {
147
78
                return nullptr;
148
78
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE3EEEE12get_null_mapEv
Line
Count
Source
145
78
        const ColumnUInt8* get_null_map() const {
146
78
            if (!null_map) {
147
78
                return nullptr;
148
78
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE4EEEE12get_null_mapEv
Line
Count
Source
145
78
        const ColumnUInt8* get_null_map() const {
146
78
            if (!null_map) {
147
78
                return nullptr;
148
78
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE5EEEE12get_null_mapEv
Line
Count
Source
145
3.61k
        const ColumnUInt8* get_null_map() const {
146
3.61k
            if (!null_map) {
147
1.62k
                return nullptr;
148
1.62k
            }
149
1.99k
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
3.61k
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE6EEEE12get_null_mapEv
Line
Count
Source
145
82
        const ColumnUInt8* get_null_map() const {
146
82
            if (!null_map) {
147
82
                return nullptr;
148
82
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
82
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE7EEEE12get_null_mapEv
Line
Count
Source
145
78
        const ColumnUInt8* get_null_map() const {
146
78
            if (!null_map) {
147
78
                return nullptr;
148
78
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE8EEEE12get_null_mapEv
Line
Count
Source
145
320
        const ColumnUInt8* get_null_map() const {
146
320
            if (!null_map) {
147
320
                return nullptr;
148
320
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
320
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeNumberILNS_13PrimitiveTypeE9EEEE12get_null_mapEv
Line
Count
Source
145
78
        const ColumnUInt8* get_null_map() const {
146
78
            if (!null_map) {
147
78
                return nullptr;
148
78
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv4EE12get_null_mapEv
Line
Count
Source
145
78
        const ColumnUInt8* get_null_map() const {
146
78
            if (!null_map) {
147
78
                return nullptr;
148
78
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_12DataTypeIPv6EE12get_null_mapEv
Line
Count
Source
145
78
        const ColumnUInt8* get_null_map() const {
146
78
            if (!null_map) {
147
78
                return nullptr;
148
78
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeStringEE12get_null_mapEv
Line
Count
Source
145
8.92k
        const ColumnUInt8* get_null_map() const {
146
8.92k
            if (!null_map) {
147
7.43k
                return nullptr;
148
7.43k
            }
149
1.49k
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
8.92k
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS0_20DictDataTypeString64EE12get_null_mapEv
Line
Count
Source
145
27
        const ColumnUInt8* get_null_map() const {
146
27
            if (!null_map) {
147
27
                return nullptr;
148
27
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
27
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_14DataTypeDateV2EE12get_null_mapEv
Line
Count
Source
145
78
        const ColumnUInt8* get_null_map() const {
146
78
            if (!null_map) {
147
78
                return nullptr;
148
78
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
78
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_18DataTypeDateTimeV2EE12get_null_mapEv
Line
Count
Source
145
1.30k
        const ColumnUInt8* get_null_map() const {
146
1.30k
            if (!null_map) {
147
1.30k
                return nullptr;
148
1.30k
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
1.30k
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_19DataTypeTimeStampNsEE12get_null_mapEv
Line
Count
Source
145
403
        const ColumnUInt8* get_null_map() const {
146
403
            if (!null_map) {
147
0
                return nullptr;
148
0
            }
149
403
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
403
        }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEEE12get_null_mapEv
_ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEEE12get_null_mapEv
Line
Count
Source
145
246
        const ColumnUInt8* get_null_map() const {
146
246
            if (!null_map) {
147
246
                return nullptr;
148
246
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
246
        }
_ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEEE12get_null_mapEv
Line
Count
Source
145
244
        const ColumnUInt8* get_null_map() const {
146
244
            if (!null_map) {
147
244
                return nullptr;
148
244
            }
149
0
            return assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(null_map.get());
150
244
        }
Unexecuted instantiation: _ZNK5doris11IDictionary14ColumnWithTypeINS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEEE12get_null_mapEv
151
    };
152
153
    // res_real_column : result column (get_column result)
154
    // res_null : if value is null, will set res_null to true
155
    // value_column : corresponding value column, non-nullable
156
    // value_null_column : corresponding value null map, if the original value is non-nullable, it will be nullptr
157
    // value_idx : index in the value column
158
    template <bool value_is_nullable, typename ResultColumnType>
159
    ALWAYS_INLINE static void set_value_data(ResultColumnType* res_real_column, UInt8& res_null,
160
                                             const auto* value_column,
161
                                             const ColumnUInt8* value_null_column,
162
56.0k
                                             const size_t& value_idx) {
163
56.0k
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
54
            if (value_null_column->get_element(value_idx)) {
166
25
                res_null = true;
167
25
                res_real_column->insert_default();
168
25
                return;
169
25
            }
170
54
        }
171
4.48k
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
4.48k
            StringRef str_ref = value_column->get_data_at(value_idx);
174
4.48k
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
51.5k
        } else {
176
51.5k
            res_real_column->insert_value(value_column->get_element(value_idx));
177
51.5k
        }
178
56.0k
    }
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE2EEES4_EEvPT0_RhPKT1_PKS4_RKm
Line
Count
Source
162
4.29k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
4.29k
        } else {
176
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
177
4.29k
        }
178
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
162
4.29k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
4.29k
        } else {
176
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
177
4.29k
        }
178
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
162
4.29k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
4.29k
        } else {
176
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
177
4.29k
        }
178
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
162
4.31k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
4.31k
        } else {
176
4.31k
            res_real_column->insert_value(value_column->get_element(value_idx));
177
4.31k
        }
178
4.31k
    }
_ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE5EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
162
37
                                             const size_t& value_idx) {
163
37
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
37
            if (value_null_column->get_element(value_idx)) {
166
18
                res_null = true;
167
18
                res_real_column->insert_default();
168
18
                return;
169
18
            }
170
37
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
37
        } else {
176
37
            res_real_column->insert_value(value_column->get_element(value_idx));
177
37
        }
178
37
    }
_ZN5doris11IDictionary14set_value_dataILb0ENS_12ColumnVectorILNS_13PrimitiveTypeE6EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
162
4.32k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
4.32k
        } else {
176
4.32k
            res_real_column->insert_value(value_column->get_element(value_idx));
177
4.32k
        }
178
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
162
4.29k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
4.29k
        } else {
176
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
177
4.29k
        }
178
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
162
4.29k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
4.29k
        } else {
176
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
177
4.29k
        }
178
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
162
4.29k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
4.29k
        } else {
176
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
177
4.29k
        }
178
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
162
4.29k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
4.29k
        } else {
176
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
177
4.29k
        }
178
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
162
4.29k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
4.29k
        } else {
176
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
177
4.29k
        }
178
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
162
3.02k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
3.02k
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
3.02k
            StringRef str_ref = value_column->get_data_at(value_idx);
174
3.02k
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
        } else {
176
            res_real_column->insert_value(value_column->get_element(value_idx));
177
        }
178
3.02k
    }
_ZN5doris11IDictionary14set_value_dataILb1ENS_9ColumnStrIjEES3_EEvPT0_RhPKT1_PKNS_12ColumnVectorILNS_13PrimitiveTypeE2EEERKm
Line
Count
Source
162
14
                                             const size_t& value_idx) {
163
14
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
14
            if (value_null_column->get_element(value_idx)) {
166
7
                res_null = true;
167
7
                res_real_column->insert_default();
168
7
                return;
169
7
            }
170
14
        }
171
14
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
14
            StringRef str_ref = value_column->get_data_at(value_idx);
174
14
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
        } else {
176
            res_real_column->insert_value(value_column->get_element(value_idx));
177
        }
178
14
    }
_ZN5doris11IDictionary14set_value_dataILb0ENS_9ColumnStrIjEENS2_ImEEEEvPT0_RhPKT1_PKNS_12ColumnVectorILNS_13PrimitiveTypeE2EEERKm
Line
Count
Source
162
1.44k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
1.44k
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
1.44k
            StringRef str_ref = value_column->get_data_at(value_idx);
174
1.44k
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
        } else {
176
            res_real_column->insert_value(value_column->get_element(value_idx));
177
        }
178
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
162
4.29k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
4.29k
        } else {
176
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
177
4.29k
        }
178
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
162
4.29k
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
4.29k
        } else {
176
4.29k
            res_real_column->insert_value(value_column->get_element(value_idx));
177
4.29k
        }
178
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
_ZN5doris11IDictionary14set_value_dataILb1ENS_12ColumnVectorILNS_13PrimitiveTypeE43EEES4_EEvPT0_RhPKT1_PKNS2_ILS3_2EEERKm
Line
Count
Source
162
3
                                             const size_t& value_idx) {
163
3
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
3
            if (value_null_column->get_element(value_idx)) {
166
0
                res_null = true;
167
0
                res_real_column->insert_default();
168
0
                return;
169
0
            }
170
3
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
3
        } else {
176
3
            res_real_column->insert_value(value_column->get_element(value_idx));
177
3
        }
178
3
    }
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
162
2
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
2
        } else {
176
2
            res_real_column->insert_value(value_column->get_element(value_idx));
177
2
        }
178
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
162
2
                                             const size_t& value_idx) {
163
        if constexpr (value_is_nullable) {
164
            // if the value is null, set the result column to null
165
            if (value_null_column->get_element(value_idx)) {
166
                res_null = true;
167
                res_real_column->insert_default();
168
                return;
169
            }
170
        }
171
        if constexpr (std::is_same_v<ResultColumnType, ColumnString>) {
172
            // If it is a string column, use get_data_at to avoid copying
173
            StringRef str_ref = value_column->get_data_at(value_idx);
174
            res_real_column->insert_data(str_ref.data, str_ref.size);
175
2
        } else {
176
2
            res_real_column->insert_value(value_column->get_element(value_idx));
177
2
        }
178
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
179
180
    /// TODO: Add support for more data types ,such as Array, Map, etc.
181
    using ValueData =
182
            std::variant<ColumnWithType<DataTypeUInt8>, ColumnWithType<DataTypeInt8>,
183
                         ColumnWithType<DataTypeInt16>, ColumnWithType<DataTypeInt32>,
184
                         ColumnWithType<DataTypeInt64>, ColumnWithType<DataTypeInt128>,
185
186
                         ColumnWithType<DataTypeFloat32>, ColumnWithType<DataTypeFloat64>,
187
188
                         ColumnWithType<DataTypeIPv4>, ColumnWithType<DataTypeIPv6>,
189
190
                         ColumnWithType<DataTypeString>, ColumnWithType<DictDataTypeString64>,
191
192
                         ColumnWithType<DataTypeDateV2>, ColumnWithType<DataTypeDateTimeV2>,
193
                         ColumnWithType<DataTypeTimeStampNs>,
194
195
                         ColumnWithType<DataTypeDecimal32>, ColumnWithType<DataTypeDecimal64>,
196
                         ColumnWithType<DataTypeDecimal128>, ColumnWithType<DataTypeDecimal256>>;
197
198
    void load_values(const std::vector<ColumnPtr>& values_column);
199
200
    // _value_data is used to store the data of value columns.
201
    std::vector<ValueData> _values_data;
202
    std::string _dict_name;
203
    std::vector<DictionaryAttribute> _attributes;
204
    // A mapping from attribute names to their corresponding indices.
205
    std::unordered_map<std::string, size_t> _name_to_attributes_index;
206
207
    // mem_tracker comes from DictionaryFactory. If _mem_tracker is nullptr, it means it is in UT.
208
    std::shared_ptr<MemTrackerLimiter> _mem_tracker;
209
};
210
211
using DictionaryPtr = std::shared_ptr<IDictionary>;
212
213
} // namespace doris