Coverage Report

Created: 2026-03-16 21:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/complex_hash_map_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 <utility>
22
#include <vector>
23
24
#include "common/status.h"
25
#include "core/block/columns_with_type_and_name.h"
26
#include "core/column/column.h"
27
#include "core/data_type/data_type.h"
28
#include "core/data_type/data_type_nullable.h"
29
#include "core/data_type/data_type_string.h"
30
#include "exprs/function/complex_dict_hash_map.h"
31
#include "exprs/function/dictionary.h"
32
33
namespace doris {
34
35
// ComplexHashMapDictionary is a dictionary used to store multiple keys and multiple values
36
// Currently, it is in a relatively simple state. In the future, it will reuse the hashmap of hashjoin
37
// In fact, you can think of this class as a hashjoin that will not be cleared (but the specific hashmap used is different from that used by hashjoin)
38
class ComplexHashMapDictionary : public IDictionary {
39
public:
40
    ComplexHashMapDictionary(std::string name, std::vector<DictionaryAttribute> attributes)
41
688
            : IDictionary(std::move(name), std::move(attributes)) {}
42
43
    ~ComplexHashMapDictionary() override;
44
    static DictionaryPtr create_complex_hash_map_dict(const std::string& name,
45
                                                      const ColumnPtrs& key_columns,
46
                                                      const DataTypes& key_types,
47
688
                                                      const ColumnsWithTypeAndName& values_data) {
48
688
        std::vector<DictionaryAttribute> attributes;
49
688
        std::vector<ColumnPtr> values_column;
50
694
        for (const auto& att : values_data) {
51
694
            attributes.push_back({att.name, att.type});
52
694
            values_column.push_back(att.column);
53
694
        }
54
688
        auto dict = std::make_shared<ComplexHashMapDictionary>(name, attributes);
55
688
        dict->load_data(key_columns, key_types, values_column);
56
688
        return dict;
57
688
    }
58
59
    ColumnPtr get_column(const std::string& attribute_name, const DataTypePtr& attribute_type,
60
1.01k
                         const ColumnPtr& key_column, const DataTypePtr& key_type) const override {
61
1.01k
        return get_tuple_columns({attribute_name}, {attribute_type}, {key_column}, {key_type})[0];
62
1.01k
    }
63
64
    ColumnPtrs get_tuple_columns(const std::vector<std::string>& attribute_names,
65
                                 const DataTypes& attribute_types, const ColumnPtrs& key_columns,
66
                                 const DataTypes& key_types) const override;
67
68
    size_t allocated_bytes() const override;
69
70
private:
71
    void load_data(const ColumnPtrs& key_columns, const DataTypes& key_types,
72
                   const std::vector<ColumnPtr>& values_column);
73
74
    ColumnPtr get_single_value_column(const IColumn::Selector& value_index, const NullMap& null_map,
75
                                      const std::string& attribute_name,
76
                                      const DataTypePtr& attribute_type) const;
77
78
    void init_find_hash_map(DictionaryHashMapMethod& find_hash_map_method,
79
                            const DataTypes& key_types) const;
80
81
    DictionaryHashMapMethod _hash_map_method;
82
83
    // Used to save key columns, because some types of hashmaps do not hold key columns, such as MethodStringNoCache
84
    ColumnPtrs _key_columns;
85
};
86
87
inline DictionaryPtr create_complex_hash_map_dict_from_column(
88
        const std::string& name, const ColumnsWithTypeAndName& key_data,
89
12
        const ColumnsWithTypeAndName& values_data) {
90
12
    ColumnPtrs key_columns;
91
12
    DataTypes key_types;
92
16
    for (const auto& key : key_data) {
93
16
        if (key.column->is_nullable()) {
94
0
            throw doris::Exception(ErrorCode::INTERNAL_ERROR,
95
0
                                   "ComplexHashMapDictionary key column should not be nullable");
96
0
        }
97
16
        key_columns.push_back(key.column);
98
16
        key_types.push_back(key.type);
99
16
    }
100
12
    auto dict = ComplexHashMapDictionary::create_complex_hash_map_dict(name, key_columns, key_types,
101
12
                                                                       values_data);
102
12
    return dict;
103
12
}
104
} // namespace doris