/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/rowset/segment_v2/inverted_index/query/query_info.h" |
26 | | #include "runtime/runtime_state.h" |
27 | | #include "vec/exprs/vexpr_fwd.h" |
28 | | |
29 | | namespace doris { |
30 | | #include "common/compile_check_begin.h" |
31 | | |
32 | | namespace io { |
33 | | class FileSystem; |
34 | | using FileSystemSPtr = std::shared_ptr<FileSystem>; |
35 | | } // namespace io |
36 | | |
37 | | struct RowSetSplits; |
38 | | |
39 | | class TabletIndex; |
40 | | class TabletSchema; |
41 | | using TabletSchemaSPtr = std::shared_ptr<TabletSchema>; |
42 | | |
43 | | struct TermInfoComparer { |
44 | 8 | bool operator()(const segment_v2::TermInfo& lhs, const segment_v2::TermInfo& rhs) const { |
45 | 8 | return lhs.term < rhs.term; |
46 | 8 | } |
47 | | }; |
48 | | |
49 | | class CollectInfo { |
50 | | public: |
51 | | std::set<segment_v2::TermInfo, TermInfoComparer> term_infos; |
52 | | const TabletIndex* index_meta = nullptr; |
53 | | }; |
54 | | |
55 | | class CollectionStatistics { |
56 | | public: |
57 | 38 | CollectionStatistics() = default; |
58 | 38 | virtual ~CollectionStatistics() = default; |
59 | | |
60 | | Status collect(RuntimeState* state, const std::vector<RowSetSplits>& rs_splits, |
61 | | const TabletSchemaSPtr& tablet_schema, |
62 | | const vectorized::VExprContextSPtrs& common_expr_ctxs_push_down); |
63 | | |
64 | | MOCK_FUNCTION float get_or_calculate_idf(const std::wstring& lucene_col_name, |
65 | | const std::wstring& term); |
66 | | MOCK_FUNCTION float get_or_calculate_avg_dl(const std::wstring& lucene_col_name); |
67 | | |
68 | | private: |
69 | | Status extract_collect_info(RuntimeState* state, |
70 | | const vectorized::VExprContextSPtrs& common_expr_ctxs_push_down, |
71 | | const TabletSchemaSPtr& tablet_schema, |
72 | | std::unordered_map<std::wstring, CollectInfo>* collect_infos); |
73 | | Status process_segment(const std::string& seg_path, const io::FileSystemSPtr& fs, |
74 | | const TabletSchema* tablet_schema, |
75 | | const std::unordered_map<std::wstring, CollectInfo>& collect_infos); |
76 | | |
77 | | uint64_t get_term_doc_freq_by_col(const std::wstring& lucene_col_name, |
78 | | const std::wstring& term); |
79 | | uint64_t get_total_term_cnt_by_col(const std::wstring& lucene_col_name); |
80 | | uint64_t get_doc_num() const; |
81 | | |
82 | | uint64_t _total_num_docs = 0; |
83 | | std::unordered_map<std::wstring, uint64_t> _total_num_tokens; |
84 | | std::unordered_map<std::wstring, std::unordered_map<std::wstring, uint64_t>> _term_doc_freqs; |
85 | | |
86 | | std::unordered_map<std::wstring, float> _avg_dl_by_col; |
87 | | std::unordered_map<std::wstring, std::unordered_map<std::wstring, float>> _idf_by_col_term; |
88 | | |
89 | | MOCK_DEFINE(friend class BM25SimilarityTest;) |
90 | | MOCK_DEFINE(friend class CollectionStatisticsTest;) |
91 | | MOCK_DEFINE(friend class BooleanQueryTest;) |
92 | | }; |
93 | | using CollectionStatisticsPtr = std::shared_ptr<CollectionStatistics>; |
94 | | |
95 | | #include "common/compile_check_end.h" |
96 | | } // namespace doris |