Coverage Report

Created: 2026-03-19 19:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/olap/collection_statistics.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
#pragma once
18
19
#include <cstdint>
20
#include <string>
21
#include <unordered_map>
22
23
#include "common/be_mock_util.h"
24
#include "olap/olap_common.h"
25
#include "olap/predicate_collector.h"
26
#include "olap/rowset/segment_v2/inverted_index/query/query_info.h"
27
#include "runtime/runtime_state.h"
28
#include "vec/exprs/vexpr_fwd.h"
29
30
namespace doris {
31
#include "common/compile_check_begin.h"
32
33
namespace io {
34
class FileSystem;
35
using FileSystemSPtr = std::shared_ptr<FileSystem>;
36
struct IOContext;
37
} // namespace io
38
39
struct RowSetSplits;
40
41
class Rowset;
42
using RowsetSharedPtr = std::shared_ptr<Rowset>;
43
44
class TabletIndex;
45
class TabletSchema;
46
using TabletSchemaSPtr = std::shared_ptr<TabletSchema>;
47
48
class CollectionStatistics {
49
public:
50
135
    CollectionStatistics() = default;
51
135
    virtual ~CollectionStatistics() = default;
52
53
    Status collect(RuntimeState* state, const std::vector<RowSetSplits>& rs_splits,
54
                   const TabletSchemaSPtr& tablet_schema,
55
                   const vectorized::VExprContextSPtrs& common_expr_ctxs_push_down,
56
                   io::IOContext* io_ctx);
57
58
    MOCK_FUNCTION float get_or_calculate_idf(const std::wstring& lucene_col_name,
59
                                             const std::wstring& term);
60
    MOCK_FUNCTION float get_or_calculate_avg_dl(const std::wstring& lucene_col_name);
61
62
private:
63
    Status extract_collect_info(RuntimeState* state,
64
                                const vectorized::VExprContextSPtrs& common_expr_ctxs_push_down,
65
                                const TabletSchemaSPtr& tablet_schema,
66
                                CollectInfoMap* collect_infos);
67
    Status process_segment(const RowsetSharedPtr& rowset, int32_t seg_id,
68
                           const TabletSchema* tablet_schema, const CollectInfoMap& collect_infos,
69
                           io::IOContext* io_ctx);
70
71
    uint64_t get_term_doc_freq_by_col(const std::wstring& lucene_col_name,
72
                                      const std::wstring& term);
73
    uint64_t get_total_term_cnt_by_col(const std::wstring& lucene_col_name);
74
    uint64_t get_doc_num() const;
75
76
    uint64_t _total_num_docs = 0;
77
    std::unordered_map<std::wstring, uint64_t> _total_num_tokens;
78
    std::unordered_map<std::wstring, std::unordered_map<std::wstring, uint64_t>> _term_doc_freqs;
79
80
    std::unordered_map<std::wstring, float> _avg_dl_by_col;
81
    std::unordered_map<std::wstring, std::unordered_map<std::wstring, float>> _idf_by_col_term;
82
83
    MOCK_DEFINE(friend class BM25SimilarityTest;)
84
    MOCK_DEFINE(friend class CollectionStatisticsTest;)
85
    MOCK_DEFINE(friend class BooleanQueryTest;)
86
    MOCK_DEFINE(friend class OccurBooleanQueryTest;)
87
};
88
using CollectionStatisticsPtr = std::shared_ptr<CollectionStatistics>;
89
90
#include "common/compile_check_end.h"
91
} // namespace doris