Coverage Report

Created: 2024-11-18 10:37

/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
19
          _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) {}
31
32
struct EnumClassHash {
33
    template <typename T>
34
17.4k
    std::size_t operator()(T t) const {
35
17.4k
        return static_cast<std::size_t>(t);
36
17.4k
    }
37
};
38
39
// Helper class used to get KeyCoder
40
class KeyCoderResolver {
41
public:
42
1
    ~KeyCoderResolver() {
43
19
        for (auto& iter : _coder_map) {
44
19
            delete iter.second;
45
19
        }
46
1
    }
47
48
17.4k
    static KeyCoderResolver* instance() {
49
17.4k
        static KeyCoderResolver s_instance;
50
17.4k
        return &s_instance;
51
17.4k
    }
52
53
17.4k
    KeyCoder* get_coder(FieldType field_type) const {
54
17.4k
        auto it = _coder_map.find(field_type);
55
17.4k
        if (it != _coder_map.end()) {
56
17.3k
            return it->second;
57
17.3k
        }
58
15
        return nullptr;
59
17.4k
    }
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
    }
84
85
    template <FieldType field_type>
86
19
    void add_mapping() {
87
19
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
19
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE1EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE3EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE5EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE6EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE7EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE8EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE9EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE15EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE14EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE16EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE13EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE17EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE26EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE24EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE28EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE29EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE31EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE32EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
_ZN5doris16KeyCoderResolver11add_mappingILNS_9FieldTypeE33EEEvv
Line
Count
Source
86
1
    void add_mapping() {
87
1
        _coder_map.emplace(field_type, new KeyCoder(KeyCoderTraits<field_type>()));
88
1
    }
89
90
    std::unordered_map<FieldType, KeyCoder*, EnumClassHash> _coder_map;
91
};
92
93
17.4k
const KeyCoder* get_key_coder(FieldType type) {
94
17.4k
    return KeyCoderResolver::instance()->get_coder(type);
95
17.4k
}
96
97
} // namespace doris