Coverage Report

Created: 2026-07-14 16:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format/format_common.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 "core/types.h"
21
#include "exec/common/int_exp.h"
22
23
namespace doris {
24
25
struct DecimalScaleParams {
26
    enum ScaleType {
27
        NOT_INIT,
28
        NO_SCALE,
29
        SCALE_UP,
30
        SCALE_DOWN,
31
    };
32
    ScaleType scale_type = ScaleType::NOT_INIT;
33
    int64_t scale_factor = 1;
34
35
    template <PrimitiveType DecimalPrimitiveType>
36
    static inline constexpr typename PrimitiveTypeTraits<DecimalPrimitiveType>::CppType::NativeType
37
4.71k
    get_scale_factor(int32_t n) {
38
4.71k
        if constexpr (DecimalPrimitiveType == TYPE_DECIMAL32) {
39
3.13k
            return common::exp10_i32(n);
40
3.13k
        } else if constexpr (DecimalPrimitiveType == TYPE_DECIMAL64) {
41
1.58k
            return common::exp10_i64(n);
42
1.58k
        } else if constexpr (DecimalPrimitiveType == TYPE_DECIMALV2) {
43
0
            return common::exp10_i128(n);
44
0
        } else if constexpr (DecimalPrimitiveType == TYPE_DECIMAL128I) {
45
0
            return common::exp10_i128(n);
46
0
        } else if constexpr (DecimalPrimitiveType == TYPE_DECIMAL256) {
47
0
            return common::exp10_i256(n);
48
        } else {
49
            static_assert(!sizeof(typename PrimitiveTypeTraits<DecimalPrimitiveType>::CppType),
50
                          "All types must be matched with if constexpr.");
51
        }
52
4.71k
    }
_ZN5doris18DecimalScaleParams16get_scale_factorILNS_13PrimitiveTypeE28EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEi
Line
Count
Source
37
3.13k
    get_scale_factor(int32_t n) {
38
3.13k
        if constexpr (DecimalPrimitiveType == TYPE_DECIMAL32) {
39
3.13k
            return common::exp10_i32(n);
40
        } else if constexpr (DecimalPrimitiveType == TYPE_DECIMAL64) {
41
            return common::exp10_i64(n);
42
        } else if constexpr (DecimalPrimitiveType == TYPE_DECIMALV2) {
43
            return common::exp10_i128(n);
44
        } else if constexpr (DecimalPrimitiveType == TYPE_DECIMAL128I) {
45
            return common::exp10_i128(n);
46
        } else if constexpr (DecimalPrimitiveType == TYPE_DECIMAL256) {
47
            return common::exp10_i256(n);
48
        } else {
49
            static_assert(!sizeof(typename PrimitiveTypeTraits<DecimalPrimitiveType>::CppType),
50
                          "All types must be matched with if constexpr.");
51
        }
52
3.13k
    }
_ZN5doris18DecimalScaleParams16get_scale_factorILNS_13PrimitiveTypeE29EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEi
Line
Count
Source
37
1.58k
    get_scale_factor(int32_t n) {
38
        if constexpr (DecimalPrimitiveType == TYPE_DECIMAL32) {
39
            return common::exp10_i32(n);
40
1.58k
        } else if constexpr (DecimalPrimitiveType == TYPE_DECIMAL64) {
41
1.58k
            return common::exp10_i64(n);
42
        } else if constexpr (DecimalPrimitiveType == TYPE_DECIMALV2) {
43
            return common::exp10_i128(n);
44
        } else if constexpr (DecimalPrimitiveType == TYPE_DECIMAL128I) {
45
            return common::exp10_i128(n);
46
        } else if constexpr (DecimalPrimitiveType == TYPE_DECIMAL256) {
47
            return common::exp10_i256(n);
48
        } else {
49
            static_assert(!sizeof(typename PrimitiveTypeTraits<DecimalPrimitiveType>::CppType),
50
                          "All types must be matched with if constexpr.");
51
        }
52
1.58k
    }
Unexecuted instantiation: _ZN5doris18DecimalScaleParams16get_scale_factorILNS_13PrimitiveTypeE20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEi
Unexecuted instantiation: _ZN5doris18DecimalScaleParams16get_scale_factorILNS_13PrimitiveTypeE30EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEi
Unexecuted instantiation: _ZN5doris18DecimalScaleParams16get_scale_factorILNS_13PrimitiveTypeE35EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEi
53
};
54
55
/**
56
 * Key-Value Cache Helper.
57
 *
58
 * It store a object instance global. User can invoke get method by key and a
59
 * object creator callback. If there is a instance stored in cache, then it will
60
 * return a void pointer of it, otherwise, it will invoke creator callback, create
61
 * a new instance store global, and return it.
62
 *
63
 * The stored objects will be deleted when deconstructing, so user do not need to
64
 * delete the returned pointer.
65
 *
66
 * User can invoke erase method by key to delete data.
67
 *
68
 * @tparam KType is the key type
69
 */
70
template <typename KType>
71
class KVCache {
72
public:
73
257
    KVCache() = default;
74
75
257
    ~KVCache() {
76
257
        for (auto& kv : _storage) {
77
30
            _delete_fn[kv.first](kv.second);
78
30
        }
79
257
    }
80
81
    void erase(const KType& key) {
82
        std::lock_guard<std::mutex> lock(_lock);
83
        auto it = _storage.find(key);
84
        if (it != _storage.end()) {
85
            _delete_fn[key](_storage[key]);
86
            _storage.erase(key);
87
            _delete_fn.erase(key);
88
        }
89
    }
90
91
    template <class T>
92
42
    T* get(const KType& key, const std::function<T*()> create_func, bool* cache_hit = nullptr) {
93
42
        std::lock_guard<std::mutex> lock(_lock);
94
42
        auto it = _storage.find(key);
95
42
        if (it != _storage.end()) {
96
3
            if (cache_hit != nullptr) {
97
1
                *cache_hit = true;
98
1
            }
99
3
            return reinterpret_cast<T*>(it->second);
100
39
        } else {
101
39
            if (cache_hit != nullptr) {
102
11
                *cache_hit = false;
103
11
            }
104
39
            T* rawPtr = create_func();
105
39
            if (rawPtr != nullptr) {
106
30
                _delete_fn[key] = [](void* obj) { delete reinterpret_cast<T*>(obj); };
_ZZN5doris7KVCacheINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE3getIN7roaring12Roaring64MapEEEPT_RKS6_St8functionIFSC_vEEPbENKUlPvE_clESJ_
Line
Count
Source
106
5
                _delete_fn[key] = [](void* obj) { delete reinterpret_cast<T*>(obj); };
Unexecuted instantiation: _ZZN5doris7KVCacheINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE3getIN5phmap22parallel_flat_hash_mapIS6_St10unique_ptrISt6vectorIlSaIlEESt14default_deleteISE_EESt4hashIS6_ESt8equal_toIvESaISt4pairIKS6_SH_EELm8ESt5mutexEEEEPT_RSN_St8functionIFST_vEEPbENKUlPvE_clESZ_
Unexecuted instantiation: _ZZN5doris7KVCacheINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE3getISt6vectorIlSaIlEEEEPT_RKS6_St8functionIFSD_vEEPbENKUlPvE_clESK_
_ZZN5doris7KVCacheINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE3getISt13unordered_mapIS6_St6vectorIlSaIlEESt4hashIS6_ESt8equal_toIS6_ESaISt4pairIKS6_SC_EEEEEPT_RSI_St8functionIFSN_vEEPbENKUlPvE_clEST_
Line
Count
Source
106
10
                _delete_fn[key] = [](void* obj) { delete reinterpret_cast<T*>(obj); };
_ZZN5doris7KVCacheINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE3getINS_6format7iceberg18IcebergTableReader20EqualityDeleteFilterEEEPT_RKS6_St8functionIFSE_vEEPbENKUlPvE_clESL_
Line
Count
Source
106
15
                _delete_fn[key] = [](void* obj) { delete reinterpret_cast<T*>(obj); };
107
30
                _storage[key] = rawPtr;
108
30
            }
109
39
            return rawPtr;
110
39
        }
111
42
    }
_ZN5doris7KVCacheINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE3getIN7roaring12Roaring64MapEEEPT_RKS6_St8functionIFSC_vEEPb
Line
Count
Source
92
12
    T* get(const KType& key, const std::function<T*()> create_func, bool* cache_hit = nullptr) {
93
12
        std::lock_guard<std::mutex> lock(_lock);
94
12
        auto it = _storage.find(key);
95
12
        if (it != _storage.end()) {
96
1
            if (cache_hit != nullptr) {
97
1
                *cache_hit = true;
98
1
            }
99
1
            return reinterpret_cast<T*>(it->second);
100
11
        } else {
101
11
            if (cache_hit != nullptr) {
102
11
                *cache_hit = false;
103
11
            }
104
11
            T* rawPtr = create_func();
105
11
            if (rawPtr != nullptr) {
106
5
                _delete_fn[key] = [](void* obj) { delete reinterpret_cast<T*>(obj); };
107
5
                _storage[key] = rawPtr;
108
5
            }
109
11
            return rawPtr;
110
11
        }
111
12
    }
_ZN5doris7KVCacheINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE3getIN5phmap22parallel_flat_hash_mapIS6_St10unique_ptrISt6vectorIlSaIlEESt14default_deleteISE_EESt4hashIS6_ESt8equal_toIvESaISt4pairIKS6_SH_EELm8ESt5mutexEEEEPT_RSN_St8functionIFST_vEEPb
Line
Count
Source
92
1
    T* get(const KType& key, const std::function<T*()> create_func, bool* cache_hit = nullptr) {
93
1
        std::lock_guard<std::mutex> lock(_lock);
94
1
        auto it = _storage.find(key);
95
1
        if (it != _storage.end()) {
96
0
            if (cache_hit != nullptr) {
97
0
                *cache_hit = true;
98
0
            }
99
0
            return reinterpret_cast<T*>(it->second);
100
1
        } else {
101
1
            if (cache_hit != nullptr) {
102
0
                *cache_hit = false;
103
0
            }
104
1
            T* rawPtr = create_func();
105
1
            if (rawPtr != nullptr) {
106
0
                _delete_fn[key] = [](void* obj) { delete reinterpret_cast<T*>(obj); };
107
0
                _storage[key] = rawPtr;
108
0
            }
109
1
            return rawPtr;
110
1
        }
111
1
    }
Unexecuted instantiation: _ZN5doris7KVCacheINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE3getISt6vectorIlSaIlEEEEPT_RKS6_St8functionIFSD_vEEPb
_ZN5doris7KVCacheINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE3getISt13unordered_mapIS6_St6vectorIlSaIlEESt4hashIS6_ESt8equal_toIS6_ESaISt4pairIKS6_SC_EEEEEPT_RSI_St8functionIFSN_vEEPb
Line
Count
Source
92
13
    T* get(const KType& key, const std::function<T*()> create_func, bool* cache_hit = nullptr) {
93
13
        std::lock_guard<std::mutex> lock(_lock);
94
13
        auto it = _storage.find(key);
95
13
        if (it != _storage.end()) {
96
1
            if (cache_hit != nullptr) {
97
0
                *cache_hit = true;
98
0
            }
99
1
            return reinterpret_cast<T*>(it->second);
100
12
        } else {
101
12
            if (cache_hit != nullptr) {
102
0
                *cache_hit = false;
103
0
            }
104
12
            T* rawPtr = create_func();
105
12
            if (rawPtr != nullptr) {
106
10
                _delete_fn[key] = [](void* obj) { delete reinterpret_cast<T*>(obj); };
107
10
                _storage[key] = rawPtr;
108
10
            }
109
12
            return rawPtr;
110
12
        }
111
13
    }
_ZN5doris7KVCacheINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE3getINS_6format7iceberg18IcebergTableReader20EqualityDeleteFilterEEEPT_RKS6_St8functionIFSE_vEEPb
Line
Count
Source
92
16
    T* get(const KType& key, const std::function<T*()> create_func, bool* cache_hit = nullptr) {
93
16
        std::lock_guard<std::mutex> lock(_lock);
94
16
        auto it = _storage.find(key);
95
16
        if (it != _storage.end()) {
96
1
            if (cache_hit != nullptr) {
97
0
                *cache_hit = true;
98
0
            }
99
1
            return reinterpret_cast<T*>(it->second);
100
15
        } else {
101
15
            if (cache_hit != nullptr) {
102
0
                *cache_hit = false;
103
0
            }
104
15
            T* rawPtr = create_func();
105
15
            if (rawPtr != nullptr) {
106
15
                _delete_fn[key] = [](void* obj) { delete reinterpret_cast<T*>(obj); };
107
15
                _storage[key] = rawPtr;
108
15
            }
109
15
            return rawPtr;
110
15
        }
111
16
    }
112
113
private:
114
    using DeleteFn = void (*)(void*);
115
116
    std::mutex _lock;
117
    std::unordered_map<KType, DeleteFn> _delete_fn;
118
    std::unordered_map<KType, void*> _storage;
119
};
120
121
class ShardedKVCache {
122
public:
123
46
    ShardedKVCache(uint32_t num_shards) : _num_shards(num_shards) {
124
46
        _shards = new (std::nothrow) KVCache<std::string>*[_num_shards];
125
303
        for (uint32_t i = 0; i < _num_shards; i++) {
126
257
            _shards[i] = new KVCache<std::string>();
127
257
        }
128
46
    }
129
130
46
    ~ShardedKVCache() {
131
303
        for (uint32_t i = 0; i < _num_shards; i++) {
132
257
            delete _shards[i];
133
257
        }
134
46
        delete[] _shards;
135
46
    }
136
137
    template <class T>
138
    T* get(const std::string& key, const std::function<T*()> create_func,
139
42
           bool* cache_hit = nullptr) {
140
42
        return _shards[_get_idx(key)]->get(key, create_func, cache_hit);
141
42
    }
_ZN5doris14ShardedKVCache3getIN7roaring12Roaring64MapEEEPT_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt8functionIFS5_vEEPb
Line
Count
Source
139
12
           bool* cache_hit = nullptr) {
140
12
        return _shards[_get_idx(key)]->get(key, create_func, cache_hit);
141
12
    }
_ZN5doris14ShardedKVCache3getIN5phmap22parallel_flat_hash_mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt10unique_ptrISt6vectorIlSaIlEESt14default_deleteISD_EESt4hashIS9_ESt8equal_toIvESaISt4pairIKS9_SG_EELm8ESt5mutexEEEEPT_RSM_St8functionIFSS_vEEPb
Line
Count
Source
139
1
           bool* cache_hit = nullptr) {
140
1
        return _shards[_get_idx(key)]->get(key, create_func, cache_hit);
141
1
    }
Unexecuted instantiation: _ZN5doris14ShardedKVCache3getISt6vectorIlSaIlEEEEPT_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt8functionIFS6_vEEPb
_ZN5doris14ShardedKVCache3getISt13unordered_mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt6vectorIlSaIlEESt4hashIS8_ESt8equal_toIS8_ESaISt4pairIKS8_SB_EEEEEPT_RSH_St8functionIFSM_vEEPb
Line
Count
Source
139
13
           bool* cache_hit = nullptr) {
140
13
        return _shards[_get_idx(key)]->get(key, create_func, cache_hit);
141
13
    }
_ZN5doris14ShardedKVCache3getINS_6format7iceberg18IcebergTableReader20EqualityDeleteFilterEEEPT_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt8functionIFS7_vEEPb
Line
Count
Source
139
16
           bool* cache_hit = nullptr) {
140
16
        return _shards[_get_idx(key)]->get(key, create_func, cache_hit);
141
16
    }
142
143
private:
144
42
    uint32_t _get_idx(const std::string& key) const {
145
42
        return (uint32_t)std::hash<std::string>()(key) % _num_shards;
146
42
    }
147
148
    uint32_t _num_shards;
149
    KVCache<std::string>** _shards = nullptr;
150
};
151
152
} // namespace doris