Coverage Report

Created: 2024-11-22 21:49

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