/root/doris/be/src/util/counts.h
Line | Count | Source (jump to first uncovered line) |
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 <algorithm> |
21 | | #include <cmath> |
22 | | #include <unordered_map> |
23 | | #include <vector> |
24 | | |
25 | | #include "udf/udf.h" |
26 | | |
27 | | namespace doris { |
28 | | |
29 | | template <typename T> |
30 | | class Counts { |
31 | | public: |
32 | 2.32k | Counts() = default; Unexecuted instantiation: _ZN5doris6CountsIhEC2Ev Unexecuted instantiation: _ZN5doris6CountsIaEC2Ev Line | Count | Source | 32 | 213 | Counts() = default; |
Line | Count | Source | 32 | 1.38k | Counts() = default; |
Line | Count | Source | 32 | 527 | Counts() = default; |
Unexecuted instantiation: _ZN5doris6CountsInEC2Ev Unexecuted instantiation: _ZN5doris6CountsIfEC2Ev Line | Count | Source | 32 | 201 | Counts() = default; |
|
33 | | |
34 | 819 | inline void merge(const Counts* other) { |
35 | 819 | if (other == nullptr || other->_counts.empty()) { |
36 | 0 | return; |
37 | 0 | } |
38 | | |
39 | 1.10k | for (auto& cell : other->_counts) { |
40 | 1.10k | increment(cell.first, cell.second); |
41 | 1.10k | } |
42 | 819 | } Unexecuted instantiation: _ZN5doris6CountsIhE5mergeEPKS1_ Unexecuted instantiation: _ZN5doris6CountsIaE5mergeEPKS1_ _ZN5doris6CountsIsE5mergeEPKS1_ Line | Count | Source | 34 | 12 | inline void merge(const Counts* other) { | 35 | 12 | if (other == nullptr || other->_counts.empty()) { | 36 | 0 | return; | 37 | 0 | } | 38 | | | 39 | 36 | for (auto& cell : other->_counts) { | 40 | 36 | increment(cell.first, cell.second); | 41 | 36 | } | 42 | 12 | } |
_ZN5doris6CountsIiE5mergeEPKS1_ Line | Count | Source | 34 | 501 | inline void merge(const Counts* other) { | 35 | 501 | if (other == nullptr || other->_counts.empty()) { | 36 | 0 | return; | 37 | 0 | } | 38 | | | 39 | 648 | for (auto& cell : other->_counts) { | 40 | 648 | increment(cell.first, cell.second); | 41 | 648 | } | 42 | 501 | } |
_ZN5doris6CountsIlE5mergeEPKS1_ Line | Count | Source | 34 | 235 | inline void merge(const Counts* other) { | 35 | 235 | if (other == nullptr || other->_counts.empty()) { | 36 | 0 | return; | 37 | 0 | } | 38 | | | 39 | 305 | for (auto& cell : other->_counts) { | 40 | 305 | increment(cell.first, cell.second); | 41 | 305 | } | 42 | 235 | } |
Unexecuted instantiation: _ZN5doris6CountsInE5mergeEPKS1_ Unexecuted instantiation: _ZN5doris6CountsIfE5mergeEPKS1_ _ZN5doris6CountsIdE5mergeEPKS1_ Line | Count | Source | 34 | 71 | inline void merge(const Counts* other) { | 35 | 71 | if (other == nullptr || other->_counts.empty()) { | 36 | 0 | return; | 37 | 0 | } | 38 | | | 39 | 120 | for (auto& cell : other->_counts) { | 40 | 120 | increment(cell.first, cell.second); | 41 | 120 | } | 42 | 71 | } |
|
43 | | |
44 | 3.46k | void increment(T key, uint32_t i) { |
45 | 3.46k | auto item = _counts.find(key); |
46 | 3.46k | if (item != _counts.end()) { |
47 | 712 | item->second += i; |
48 | 2.75k | } else { |
49 | 2.75k | _counts.emplace(std::make_pair(key, i)); |
50 | 2.75k | } |
51 | 3.46k | } Unexecuted instantiation: _ZN5doris6CountsIhE9incrementEhj Unexecuted instantiation: _ZN5doris6CountsIaE9incrementEaj _ZN5doris6CountsIsE9incrementEsj Line | Count | Source | 44 | 789 | void increment(T key, uint32_t i) { | 45 | 789 | auto item = _counts.find(key); | 46 | 789 | if (item != _counts.end()) { | 47 | 108 | item->second += i; | 48 | 681 | } else { | 49 | 681 | _counts.emplace(std::make_pair(key, i)); | 50 | 681 | } | 51 | 789 | } |
_ZN5doris6CountsIiE9incrementEij Line | Count | Source | 44 | 1.76k | void increment(T key, uint32_t i) { | 45 | 1.76k | auto item = _counts.find(key); | 46 | 1.76k | if (item != _counts.end()) { | 47 | 483 | item->second += i; | 48 | 1.28k | } else { | 49 | 1.28k | _counts.emplace(std::make_pair(key, i)); | 50 | 1.28k | } | 51 | 1.76k | } |
_ZN5doris6CountsIlE9incrementElj Line | Count | Source | 44 | 572 | void increment(T key, uint32_t i) { | 45 | 572 | auto item = _counts.find(key); | 46 | 572 | if (item != _counts.end()) { | 47 | 59 | item->second += i; | 48 | 513 | } else { | 49 | 513 | _counts.emplace(std::make_pair(key, i)); | 50 | 513 | } | 51 | 572 | } |
Unexecuted instantiation: _ZN5doris6CountsInE9incrementEnj Unexecuted instantiation: _ZN5doris6CountsIfE9incrementEfj _ZN5doris6CountsIdE9incrementEdj Line | Count | Source | 44 | 334 | void increment(T key, uint32_t i) { | 45 | 334 | auto item = _counts.find(key); | 46 | 334 | if (item != _counts.end()) { | 47 | 62 | item->second += i; | 48 | 272 | } else { | 49 | 272 | _counts.emplace(std::make_pair(key, i)); | 50 | 272 | } | 51 | 334 | } |
|
52 | | |
53 | 819 | uint32_t serialized_size() const { |
54 | 819 | return sizeof(uint32_t) + sizeof(T) * _counts.size() + sizeof(uint32_t) * _counts.size(); |
55 | 819 | } Unexecuted instantiation: _ZNK5doris6CountsIhE15serialized_sizeEv Unexecuted instantiation: _ZNK5doris6CountsIaE15serialized_sizeEv _ZNK5doris6CountsIsE15serialized_sizeEv Line | Count | Source | 53 | 12 | uint32_t serialized_size() const { | 54 | 12 | return sizeof(uint32_t) + sizeof(T) * _counts.size() + sizeof(uint32_t) * _counts.size(); | 55 | 12 | } |
_ZNK5doris6CountsIiE15serialized_sizeEv Line | Count | Source | 53 | 501 | uint32_t serialized_size() const { | 54 | 501 | return sizeof(uint32_t) + sizeof(T) * _counts.size() + sizeof(uint32_t) * _counts.size(); | 55 | 501 | } |
_ZNK5doris6CountsIlE15serialized_sizeEv Line | Count | Source | 53 | 235 | uint32_t serialized_size() const { | 54 | 235 | return sizeof(uint32_t) + sizeof(T) * _counts.size() + sizeof(uint32_t) * _counts.size(); | 55 | 235 | } |
Unexecuted instantiation: _ZNK5doris6CountsInE15serialized_sizeEv Unexecuted instantiation: _ZNK5doris6CountsIfE15serialized_sizeEv _ZNK5doris6CountsIdE15serialized_sizeEv Line | Count | Source | 53 | 71 | uint32_t serialized_size() const { | 54 | 71 | return sizeof(uint32_t) + sizeof(T) * _counts.size() + sizeof(uint32_t) * _counts.size(); | 55 | 71 | } |
|
56 | | |
57 | 819 | void serialize(uint8_t* writer) const { |
58 | 819 | uint32_t size = _counts.size(); |
59 | 819 | memcpy(writer, &size, sizeof(uint32_t)); |
60 | 819 | writer += sizeof(uint32_t); |
61 | 1.11k | for (auto& cell : _counts) { |
62 | 1.11k | memcpy(writer, &cell.first, sizeof(T)); |
63 | 1.11k | writer += sizeof(T); |
64 | 1.11k | memcpy(writer, &cell.second, sizeof(uint32_t)); |
65 | 1.11k | writer += sizeof(uint32_t); |
66 | 1.11k | } |
67 | 819 | } Unexecuted instantiation: _ZNK5doris6CountsIhE9serializeEPh Unexecuted instantiation: _ZNK5doris6CountsIaE9serializeEPh _ZNK5doris6CountsIsE9serializeEPh Line | Count | Source | 57 | 12 | void serialize(uint8_t* writer) const { | 58 | 12 | uint32_t size = _counts.size(); | 59 | 12 | memcpy(writer, &size, sizeof(uint32_t)); | 60 | 12 | writer += sizeof(uint32_t); | 61 | 36 | for (auto& cell : _counts) { | 62 | 36 | memcpy(writer, &cell.first, sizeof(T)); | 63 | 36 | writer += sizeof(T); | 64 | 36 | memcpy(writer, &cell.second, sizeof(uint32_t)); | 65 | 36 | writer += sizeof(uint32_t); | 66 | 36 | } | 67 | 12 | } |
_ZNK5doris6CountsIiE9serializeEPh Line | Count | Source | 57 | 501 | void serialize(uint8_t* writer) const { | 58 | 501 | uint32_t size = _counts.size(); | 59 | 501 | memcpy(writer, &size, sizeof(uint32_t)); | 60 | 501 | writer += sizeof(uint32_t); | 61 | 648 | for (auto& cell : _counts) { | 62 | 648 | memcpy(writer, &cell.first, sizeof(T)); | 63 | 648 | writer += sizeof(T); | 64 | 648 | memcpy(writer, &cell.second, sizeof(uint32_t)); | 65 | 648 | writer += sizeof(uint32_t); | 66 | 648 | } | 67 | 501 | } |
_ZNK5doris6CountsIlE9serializeEPh Line | Count | Source | 57 | 235 | void serialize(uint8_t* writer) const { | 58 | 235 | uint32_t size = _counts.size(); | 59 | 235 | memcpy(writer, &size, sizeof(uint32_t)); | 60 | 235 | writer += sizeof(uint32_t); | 61 | 306 | for (auto& cell : _counts) { | 62 | 306 | memcpy(writer, &cell.first, sizeof(T)); | 63 | 306 | writer += sizeof(T); | 64 | 306 | memcpy(writer, &cell.second, sizeof(uint32_t)); | 65 | 306 | writer += sizeof(uint32_t); | 66 | 306 | } | 67 | 235 | } |
Unexecuted instantiation: _ZNK5doris6CountsInE9serializeEPh Unexecuted instantiation: _ZNK5doris6CountsIfE9serializeEPh _ZNK5doris6CountsIdE9serializeEPh Line | Count | Source | 57 | 71 | void serialize(uint8_t* writer) const { | 58 | 71 | uint32_t size = _counts.size(); | 59 | 71 | memcpy(writer, &size, sizeof(uint32_t)); | 60 | 71 | writer += sizeof(uint32_t); | 61 | 120 | for (auto& cell : _counts) { | 62 | 120 | memcpy(writer, &cell.first, sizeof(T)); | 63 | 120 | writer += sizeof(T); | 64 | 120 | memcpy(writer, &cell.second, sizeof(uint32_t)); | 65 | 120 | writer += sizeof(uint32_t); | 66 | 120 | } | 67 | 71 | } |
|
68 | | |
69 | 819 | void unserialize(const uint8_t* type_reader) { |
70 | 819 | uint32_t size; |
71 | 819 | memcpy(&size, type_reader, sizeof(uint32_t)); |
72 | 819 | type_reader += sizeof(uint32_t); |
73 | 1.92k | for (uint32_t i = 0; i < size; ++i) { |
74 | 1.11k | T key; |
75 | 1.11k | uint32_t count; |
76 | 1.11k | memcpy(&key, type_reader, sizeof(T)); |
77 | 1.11k | type_reader += sizeof(T); |
78 | 1.11k | memcpy(&count, type_reader, sizeof(uint32_t)); |
79 | 1.11k | type_reader += sizeof(uint32_t); |
80 | 1.11k | _counts.emplace(std::make_pair(key, count)); |
81 | 1.11k | } |
82 | 819 | } Unexecuted instantiation: _ZN5doris6CountsIhE11unserializeEPKh Unexecuted instantiation: _ZN5doris6CountsIaE11unserializeEPKh _ZN5doris6CountsIsE11unserializeEPKh Line | Count | Source | 69 | 12 | void unserialize(const uint8_t* type_reader) { | 70 | 12 | uint32_t size; | 71 | 12 | memcpy(&size, type_reader, sizeof(uint32_t)); | 72 | 12 | type_reader += sizeof(uint32_t); | 73 | 48 | for (uint32_t i = 0; i < size; ++i) { | 74 | 36 | T key; | 75 | 36 | uint32_t count; | 76 | 36 | memcpy(&key, type_reader, sizeof(T)); | 77 | 36 | type_reader += sizeof(T); | 78 | 36 | memcpy(&count, type_reader, sizeof(uint32_t)); | 79 | 36 | type_reader += sizeof(uint32_t); | 80 | 36 | _counts.emplace(std::make_pair(key, count)); | 81 | 36 | } | 82 | 12 | } |
_ZN5doris6CountsIiE11unserializeEPKh Line | Count | Source | 69 | 501 | void unserialize(const uint8_t* type_reader) { | 70 | 501 | uint32_t size; | 71 | 501 | memcpy(&size, type_reader, sizeof(uint32_t)); | 72 | 501 | type_reader += sizeof(uint32_t); | 73 | 1.14k | for (uint32_t i = 0; i < size; ++i) { | 74 | 648 | T key; | 75 | 648 | uint32_t count; | 76 | 648 | memcpy(&key, type_reader, sizeof(T)); | 77 | 648 | type_reader += sizeof(T); | 78 | 648 | memcpy(&count, type_reader, sizeof(uint32_t)); | 79 | 648 | type_reader += sizeof(uint32_t); | 80 | 648 | _counts.emplace(std::make_pair(key, count)); | 81 | 648 | } | 82 | 501 | } |
_ZN5doris6CountsIlE11unserializeEPKh Line | Count | Source | 69 | 235 | void unserialize(const uint8_t* type_reader) { | 70 | 235 | uint32_t size; | 71 | 235 | memcpy(&size, type_reader, sizeof(uint32_t)); | 72 | 235 | type_reader += sizeof(uint32_t); | 73 | 541 | for (uint32_t i = 0; i < size; ++i) { | 74 | 306 | T key; | 75 | 306 | uint32_t count; | 76 | 306 | memcpy(&key, type_reader, sizeof(T)); | 77 | 306 | type_reader += sizeof(T); | 78 | 306 | memcpy(&count, type_reader, sizeof(uint32_t)); | 79 | 306 | type_reader += sizeof(uint32_t); | 80 | 306 | _counts.emplace(std::make_pair(key, count)); | 81 | 306 | } | 82 | 235 | } |
Unexecuted instantiation: _ZN5doris6CountsInE11unserializeEPKh Unexecuted instantiation: _ZN5doris6CountsIfE11unserializeEPKh _ZN5doris6CountsIdE11unserializeEPKh Line | Count | Source | 69 | 71 | void unserialize(const uint8_t* type_reader) { | 70 | 71 | uint32_t size; | 71 | 71 | memcpy(&size, type_reader, sizeof(uint32_t)); | 72 | 71 | type_reader += sizeof(uint32_t); | 73 | 191 | for (uint32_t i = 0; i < size; ++i) { | 74 | 120 | T key; | 75 | 120 | uint32_t count; | 76 | 120 | memcpy(&key, type_reader, sizeof(T)); | 77 | 120 | type_reader += sizeof(T); | 78 | 120 | memcpy(&count, type_reader, sizeof(uint32_t)); | 79 | 120 | type_reader += sizeof(uint32_t); | 80 | 120 | _counts.emplace(std::make_pair(key, count)); | 81 | 120 | } | 82 | 71 | } |
|
83 | | |
84 | 825 | double get_percentile(std::vector<std::pair<T, uint32_t>>& counts, double position) const { |
85 | 825 | long lower = long(std::floor(position)); |
86 | 825 | long higher = long(std::ceil(position)); |
87 | | |
88 | 825 | auto iter = counts.begin(); |
89 | 1.51k | for (; iter != counts.end() && iter->second < lower + 1; ++iter) |
90 | 692 | ; |
91 | | |
92 | 825 | T lower_key = iter->first; |
93 | 825 | if (higher == lower) { |
94 | 406 | return lower_key; |
95 | 406 | } |
96 | | |
97 | 419 | if (iter->second < higher + 1) { |
98 | 267 | iter++; |
99 | 267 | } |
100 | | |
101 | 419 | T higher_key = iter->first; |
102 | 419 | if (lower_key == higher_key) { |
103 | 152 | return lower_key; |
104 | 152 | } |
105 | | |
106 | 267 | return (higher - position) * lower_key + (position - lower) * higher_key; |
107 | 419 | } Unexecuted instantiation: _ZNK5doris6CountsIhE14get_percentileERSt6vectorISt4pairIhjESaIS4_EEd Unexecuted instantiation: _ZNK5doris6CountsIaE14get_percentileERSt6vectorISt4pairIajESaIS4_EEd _ZNK5doris6CountsIsE14get_percentileERSt6vectorISt4pairIsjESaIS4_EEd Line | Count | Source | 84 | 267 | double get_percentile(std::vector<std::pair<T, uint32_t>>& counts, double position) const { | 85 | 267 | long lower = long(std::floor(position)); | 86 | 267 | long higher = long(std::ceil(position)); | 87 | | | 88 | 267 | auto iter = counts.begin(); | 89 | 688 | for (; iter != counts.end() && iter->second < lower + 1; ++iter) | 90 | 421 | ; | 91 | | | 92 | 267 | T lower_key = iter->first; | 93 | 267 | if (higher == lower) { | 94 | 82 | return lower_key; | 95 | 82 | } | 96 | | | 97 | 185 | if (iter->second < higher + 1) { | 98 | 147 | iter++; | 99 | 147 | } | 100 | | | 101 | 185 | T higher_key = iter->first; | 102 | 185 | if (lower_key == higher_key) { | 103 | 38 | return lower_key; | 104 | 38 | } | 105 | | | 106 | 147 | return (higher - position) * lower_key + (position - lower) * higher_key; | 107 | 185 | } |
_ZNK5doris6CountsIiE14get_percentileERSt6vectorISt4pairIijESaIS4_EEd Line | Count | Source | 84 | 384 | double get_percentile(std::vector<std::pair<T, uint32_t>>& counts, double position) const { | 85 | 384 | long lower = long(std::floor(position)); | 86 | 384 | long higher = long(std::ceil(position)); | 87 | | | 88 | 384 | auto iter = counts.begin(); | 89 | 416 | for (; iter != counts.end() && iter->second < lower + 1; ++iter) | 90 | 32 | ; | 91 | | | 92 | 384 | T lower_key = iter->first; | 93 | 384 | if (higher == lower) { | 94 | 233 | return lower_key; | 95 | 233 | } | 96 | | | 97 | 151 | if (iter->second < higher + 1) { | 98 | 76 | iter++; | 99 | 76 | } | 100 | | | 101 | 151 | T higher_key = iter->first; | 102 | 151 | if (lower_key == higher_key) { | 103 | 75 | return lower_key; | 104 | 75 | } | 105 | | | 106 | 76 | return (higher - position) * lower_key + (position - lower) * higher_key; | 107 | 151 | } |
_ZNK5doris6CountsIlE14get_percentileERSt6vectorISt4pairIljESaIS4_EEd Line | Count | Source | 84 | 59 | double get_percentile(std::vector<std::pair<T, uint32_t>>& counts, double position) const { | 85 | 59 | long lower = long(std::floor(position)); | 86 | 59 | long higher = long(std::ceil(position)); | 87 | | | 88 | 59 | auto iter = counts.begin(); | 89 | 131 | for (; iter != counts.end() && iter->second < lower + 1; ++iter) | 90 | 72 | ; | 91 | | | 92 | 59 | T lower_key = iter->first; | 93 | 59 | if (higher == lower) { | 94 | 32 | return lower_key; | 95 | 32 | } | 96 | | | 97 | 27 | if (iter->second < higher + 1) { | 98 | 18 | iter++; | 99 | 18 | } | 100 | | | 101 | 27 | T higher_key = iter->first; | 102 | 27 | if (lower_key == higher_key) { | 103 | 9 | return lower_key; | 104 | 9 | } | 105 | | | 106 | 18 | return (higher - position) * lower_key + (position - lower) * higher_key; | 107 | 27 | } |
Unexecuted instantiation: _ZNK5doris6CountsInE14get_percentileERSt6vectorISt4pairInjESaIS4_EEd Unexecuted instantiation: _ZNK5doris6CountsIfE14get_percentileERSt6vectorISt4pairIfjESaIS4_EEd _ZNK5doris6CountsIdE14get_percentileERSt6vectorISt4pairIdjESaIS4_EEd Line | Count | Source | 84 | 115 | double get_percentile(std::vector<std::pair<T, uint32_t>>& counts, double position) const { | 85 | 115 | long lower = long(std::floor(position)); | 86 | 115 | long higher = long(std::ceil(position)); | 87 | | | 88 | 115 | auto iter = counts.begin(); | 89 | 282 | for (; iter != counts.end() && iter->second < lower + 1; ++iter) | 90 | 167 | ; | 91 | | | 92 | 115 | T lower_key = iter->first; | 93 | 115 | if (higher == lower) { | 94 | 59 | return lower_key; | 95 | 59 | } | 96 | | | 97 | 56 | if (iter->second < higher + 1) { | 98 | 26 | iter++; | 99 | 26 | } | 100 | | | 101 | 56 | T higher_key = iter->first; | 102 | 56 | if (lower_key == higher_key) { | 103 | 30 | return lower_key; | 104 | 30 | } | 105 | | | 106 | 26 | return (higher - position) * lower_key + (position - lower) * higher_key; | 107 | 56 | } |
|
108 | | |
109 | 825 | double terminate(double quantile) const { |
110 | 825 | if (_counts.empty()) { |
111 | | // Although set null here, but the value is 0.0 and the call method just |
112 | | // get val in aggregate_function_percentile_approx.h |
113 | 0 | return 0.0; |
114 | 0 | } |
115 | | |
116 | 825 | std::vector<std::pair<T, uint32_t>> elems(_counts.begin(), _counts.end()); |
117 | 825 | sort(elems.begin(), elems.end(), |
118 | 2.97k | [](const std::pair<T, uint32_t> l, const std::pair<T, uint32_t> r) { |
119 | 2.97k | return l.first < r.first; |
120 | 2.97k | }); Unexecuted instantiation: _ZZNK5doris6CountsIhE9terminateEdENKUlSt4pairIhjES3_E_clES3_S3_ Unexecuted instantiation: _ZZNK5doris6CountsIaE9terminateEdENKUlSt4pairIajES3_E_clES3_S3_ _ZZNK5doris6CountsIsE9terminateEdENKUlSt4pairIsjES3_E_clES3_S3_ Line | Count | Source | 118 | 1.56k | [](const std::pair<T, uint32_t> l, const std::pair<T, uint32_t> r) { | 119 | 1.56k | return l.first < r.first; | 120 | 1.56k | }); |
_ZZNK5doris6CountsIiE9terminateEdENKUlSt4pairIijES3_E_clES3_S3_ Line | Count | Source | 118 | 475 | [](const std::pair<T, uint32_t> l, const std::pair<T, uint32_t> r) { | 119 | 475 | return l.first < r.first; | 120 | 475 | }); |
_ZZNK5doris6CountsIlE9terminateEdENKUlSt4pairIljES3_E_clES3_S3_ Line | Count | Source | 118 | 467 | [](const std::pair<T, uint32_t> l, const std::pair<T, uint32_t> r) { | 119 | 467 | return l.first < r.first; | 120 | 467 | }); |
Unexecuted instantiation: _ZZNK5doris6CountsInE9terminateEdENKUlSt4pairInjES3_E_clES3_S3_ Unexecuted instantiation: _ZZNK5doris6CountsIfE9terminateEdENKUlSt4pairIfjES3_E_clES3_S3_ _ZZNK5doris6CountsIdE9terminateEdENKUlSt4pairIdjES3_E_clES3_S3_ Line | Count | Source | 118 | 469 | [](const std::pair<T, uint32_t> l, const std::pair<T, uint32_t> r) { | 119 | 469 | return l.first < r.first; | 120 | 469 | }); |
|
121 | | |
122 | 825 | long total = 0; |
123 | 2.16k | for (auto& cell : elems) { |
124 | 2.16k | total += cell.second; |
125 | 2.16k | cell.second = total; |
126 | 2.16k | } |
127 | | |
128 | 825 | long max_position = total - 1; |
129 | 825 | double position = max_position * quantile; |
130 | 825 | return get_percentile(elems, position); |
131 | 825 | } Unexecuted instantiation: _ZNK5doris6CountsIhE9terminateEd Unexecuted instantiation: _ZNK5doris6CountsIaE9terminateEd _ZNK5doris6CountsIsE9terminateEd Line | Count | Source | 109 | 267 | double terminate(double quantile) const { | 110 | 267 | if (_counts.empty()) { | 111 | | // Although set null here, but the value is 0.0 and the call method just | 112 | | // get val in aggregate_function_percentile_approx.h | 113 | 0 | return 0.0; | 114 | 0 | } | 115 | | | 116 | 267 | std::vector<std::pair<T, uint32_t>> elems(_counts.begin(), _counts.end()); | 117 | 267 | sort(elems.begin(), elems.end(), | 118 | 267 | [](const std::pair<T, uint32_t> l, const std::pair<T, uint32_t> r) { | 119 | 267 | return l.first < r.first; | 120 | 267 | }); | 121 | | | 122 | 267 | long total = 0; | 123 | 909 | for (auto& cell : elems) { | 124 | 909 | total += cell.second; | 125 | 909 | cell.second = total; | 126 | 909 | } | 127 | | | 128 | 267 | long max_position = total - 1; | 129 | 267 | double position = max_position * quantile; | 130 | 267 | return get_percentile(elems, position); | 131 | 267 | } |
_ZNK5doris6CountsIiE9terminateEd Line | Count | Source | 109 | 384 | double terminate(double quantile) const { | 110 | 384 | if (_counts.empty()) { | 111 | | // Although set null here, but the value is 0.0 and the call method just | 112 | | // get val in aggregate_function_percentile_approx.h | 113 | 0 | return 0.0; | 114 | 0 | } | 115 | | | 116 | 384 | std::vector<std::pair<T, uint32_t>> elems(_counts.begin(), _counts.end()); | 117 | 384 | sort(elems.begin(), elems.end(), | 118 | 384 | [](const std::pair<T, uint32_t> l, const std::pair<T, uint32_t> r) { | 119 | 384 | return l.first < r.first; | 120 | 384 | }); | 121 | | | 122 | 384 | long total = 0; | 123 | 640 | for (auto& cell : elems) { | 124 | 640 | total += cell.second; | 125 | 640 | cell.second = total; | 126 | 640 | } | 127 | | | 128 | 384 | long max_position = total - 1; | 129 | 384 | double position = max_position * quantile; | 130 | 384 | return get_percentile(elems, position); | 131 | 384 | } |
_ZNK5doris6CountsIlE9terminateEd Line | Count | Source | 109 | 59 | double terminate(double quantile) const { | 110 | 59 | if (_counts.empty()) { | 111 | | // Although set null here, but the value is 0.0 and the call method just | 112 | | // get val in aggregate_function_percentile_approx.h | 113 | 0 | return 0.0; | 114 | 0 | } | 115 | | | 116 | 59 | std::vector<std::pair<T, uint32_t>> elems(_counts.begin(), _counts.end()); | 117 | 59 | sort(elems.begin(), elems.end(), | 118 | 59 | [](const std::pair<T, uint32_t> l, const std::pair<T, uint32_t> r) { | 119 | 59 | return l.first < r.first; | 120 | 59 | }); | 121 | | | 122 | 59 | long total = 0; | 123 | 220 | for (auto& cell : elems) { | 124 | 220 | total += cell.second; | 125 | 220 | cell.second = total; | 126 | 220 | } | 127 | | | 128 | 59 | long max_position = total - 1; | 129 | 59 | double position = max_position * quantile; | 130 | 59 | return get_percentile(elems, position); | 131 | 59 | } |
Unexecuted instantiation: _ZNK5doris6CountsInE9terminateEd Unexecuted instantiation: _ZNK5doris6CountsIfE9terminateEd _ZNK5doris6CountsIdE9terminateEd Line | Count | Source | 109 | 115 | double terminate(double quantile) const { | 110 | 115 | if (_counts.empty()) { | 111 | | // Although set null here, but the value is 0.0 and the call method just | 112 | | // get val in aggregate_function_percentile_approx.h | 113 | 0 | return 0.0; | 114 | 0 | } | 115 | | | 116 | 115 | std::vector<std::pair<T, uint32_t>> elems(_counts.begin(), _counts.end()); | 117 | 115 | sort(elems.begin(), elems.end(), | 118 | 115 | [](const std::pair<T, uint32_t> l, const std::pair<T, uint32_t> r) { | 119 | 115 | return l.first < r.first; | 120 | 115 | }); | 121 | | | 122 | 115 | long total = 0; | 123 | 400 | for (auto& cell : elems) { | 124 | 400 | total += cell.second; | 125 | 400 | cell.second = total; | 126 | 400 | } | 127 | | | 128 | 115 | long max_position = total - 1; | 129 | 115 | double position = max_position * quantile; | 130 | 115 | return get_percentile(elems, position); | 131 | 115 | } |
|
132 | | |
133 | | private: |
134 | | std::unordered_map<T, uint32_t> _counts; |
135 | | }; |
136 | | |
137 | | } // namespace doris |