Coverage Report

Created: 2025-06-20 14:56

/root/doris/be/src/olap/key_coder.cpp
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
#include "olap/key_coder.h"
19
20
#include <cstddef>
21
#include <unordered_map>
22
#include <utility>
23
24
namespace doris {
25
26
template <typename TraitsType>
27
KeyCoder::KeyCoder(TraitsType traits)
28
        : _full_encode_ascending(traits.full_encode_ascending),
29
          _encode_ascending(traits.encode_ascending),
30
44
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE1EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE3EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE5EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE6EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE7EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE8EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE9EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE15EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE14EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE16EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE13EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE17EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE26EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE24EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE28EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE29EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE31EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE32EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE33EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE37EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE38EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
_ZN5doris8KeyCoderC2INS_14KeyCoderTraitsILNS_9FieldTypeE39EvEEEET_
Line
Count
Source
30
2
          _decode_ascending(traits.decode_ascending) {}
31
32
struct EnumClassHash {
33
    template <typename T>
34
64.2k
    std::size_t operator()(T t) const {
35
64.2k
        return static_cast<std::size_t>(t);
36
64.2k
    }
37
};
38
39
// Helper class used to get KeyCoder
40
class KeyCoderResolver {
41
public:
42
2
    ~KeyCoderResolver() {
43
44
        for (auto& iter : _coder_map) {
44
44
            delete iter.second;
45
44
        }
46
2
    }
47
48
64.1k
    static KeyCoderResolver* instance() {
49
64.1k
        static KeyCoderResolver s_instance;
50
64.1k
        return &s_instance;
51
64.1k
    }
52
53
64.1k
    KeyCoder* get_coder(FieldType field_type) const {
54
64.1k
        auto it = _coder_map.find(field_type);
55
64.1k
        if (it != _coder_map.end()) {
56
64.1k
            return it->second;
57
64.1k
        }
58
48
        return nullptr;
59
64.1k
    }
60
61
private:
62
2
    KeyCoderResolver() {
63
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_TINYINT>();
64
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_SMALLINT>();
65
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_INT>();
66
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_UNSIGNED_INT>();
67
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_BIGINT>();
68
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_UNSIGNED_BIGINT>();
69
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_LARGEINT>();
70
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_DATETIME>();
71
72
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_DATE>();
73
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_DECIMAL>();
74
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_CHAR>();
75
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_VARCHAR>();
76
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_STRING>();
77
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_BOOL>();
78
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_DATEV2>();
79
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_DATETIMEV2>();
80
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_DECIMAL32>();
81
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_DECIMAL64>();
82
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_DECIMAL128I>();
83
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_DECIMAL256>();
84
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_IPV4>();
85
2
        add_mapping<FieldType::OLAP_FIELD_TYPE_IPV6>();
86
2
    }
87
88
    template <FieldType field_type>
89
44
    void add_mapping() {
90
44
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
44
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE1EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE3EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE5EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE6EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE7EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE8EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE9EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE15EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE14EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE16EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE13EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE17EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE26EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE24EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE28EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE29EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE31EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE32EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE33EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE37EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE38EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE39EEEvv
Line
Count
Source
89
2
    void add_mapping() {
90
2
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
91
2
    }
92
93
    std::unordered_map<FieldType, KeyCoder*, EnumClassHash> _coder_map;
94
};
95
96
64.1k
const KeyCoder* get_key_coder(FieldType type) {
97
64.1k
    return KeyCoderResolver::instance()->get_coder(type);
98
64.1k
}
99
100
} // namespace doris