Coverage Report

Created: 2025-04-25 18:46

/root/doris/be/src/util/quantile_state.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 <stddef.h>
21
#include <stdint.h>
22
23
#include <algorithm>
24
#include <memory>
25
#include <vector>
26
27
#include "common/exception.h"
28
#include "slice.h"
29
30
namespace doris {
31
32
class TDigest;
33
34
const static int QUANTILE_STATE_EXPLICIT_NUM = 2048;
35
const static int QUANTILE_STATE_COMPRESSION_MIN = 2048;
36
const static int QUANTILE_STATE_COMPRESSION_MAX = 10000;
37
38
enum QuantileStateType {
39
    EMPTY = 0,
40
    SINGLE = 1,   // single element
41
    EXPLICIT = 2, // more than one elements,stored in vector
42
    TDIGEST = 3   // TDIGEST object
43
};
44
45
class QuantileState {
46
public:
47
    QuantileState();
48
    explicit QuantileState(float compression);
49
    explicit QuantileState(const Slice& slice);
50
23
    QuantileState& operator=(const QuantileState& other) noexcept = default;
51
46.5k
    QuantileState(const QuantileState& other) noexcept = default;
52
0
    QuantileState& operator=(QuantileState&& other) noexcept = default;
53
41.6k
    QuantileState(QuantileState&& other) noexcept = default;
54
55
    void set_compression(float compression);
56
    bool deserialize(const Slice& slice);
57
    size_t serialize(uint8_t* dst) const;
58
    void merge(const QuantileState& other);
59
    void add_value(const double& value);
60
    void clear();
61
    bool is_valid(const Slice& slice);
62
    size_t get_serialized_size();
63
    double get_value_by_percentile(float percentile) const;
64
    double get_explicit_value_by_percentile(float percentile) const;
65
#ifdef BE_TEST
66
0
    std::string to_string() const {
67
0
        throw Status::NotSupported("QuantileState::to_string() not implemented");
68
0
    }
69
#endif
70
216k
    ~QuantileState() = default;
71
72
private:
73
    QuantileStateType _type = EMPTY;
74
    std::shared_ptr<TDigest> _tdigest_ptr;
75
    double _single_data;
76
    std::vector<double> _explicit_data;
77
    float _compression;
78
};
79
80
} // namespace doris