Coverage Report

Created: 2026-05-08 18:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/predicate_collector.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 <memory>
21
#include <set>
22
#include <string>
23
#include <unordered_map>
24
25
#include "common/status.h"
26
#include "exprs/vexpr_fwd.h"
27
#include "gen_cpp/Exprs_types.h"
28
#include "runtime/runtime_state.h"
29
#include "storage/index/inverted/query/query_info.h"
30
31
namespace doris {
32
33
class VSlotRef;
34
class TabletIndex;
35
class TabletSchema;
36
using TabletSchemaSPtr = std::shared_ptr<TabletSchema>;
37
38
struct TermInfoComparer {
39
58
    bool operator()(const segment_v2::TermInfo& lhs, const segment_v2::TermInfo& rhs) const {
40
58
        return lhs.term < rhs.term;
41
58
    }
42
};
43
44
struct CollectInfo {
45
    std::set<segment_v2::TermInfo, TermInfoComparer> term_infos;
46
    std::shared_ptr<const TabletIndex> owned_index_meta;
47
    const TabletIndex* index_meta = nullptr;
48
};
49
using CollectInfoMap = std::unordered_map<std::wstring, CollectInfo>;
50
51
class PredicateCollector {
52
public:
53
56
    virtual ~PredicateCollector() = default;
54
55
    virtual Status collect(RuntimeState* state, const TabletSchemaSPtr& tablet_schema,
56
                           const VExprSPtr& expr, CollectInfoMap* collect_infos) = 0;
57
58
protected:
59
    VSlotRef* find_slot_ref(const VExprSPtr& expr) const;
60
    std::string build_field_name(int32_t col_unique_id, const std::string& suffix_path) const;
61
};
62
63
class MatchPredicateCollector : public PredicateCollector {
64
public:
65
    Status collect(RuntimeState* state, const TabletSchemaSPtr& tablet_schema,
66
                   const VExprSPtr& expr, CollectInfoMap* collect_infos) override;
67
};
68
69
class SearchPredicateCollector : public PredicateCollector {
70
public:
71
    Status collect(RuntimeState* state, const TabletSchemaSPtr& tablet_schema,
72
                   const VExprSPtr& expr, CollectInfoMap* collect_infos) override;
73
74
private:
75
    enum class ClauseTypeCategory { NON_TOKENIZED, TOKENIZED, COMPOUND };
76
77
    Status collect_from_clause(const TSearchClause& clause, RuntimeState* state,
78
                               const TabletSchemaSPtr& tablet_schema,
79
                               CollectInfoMap* collect_infos);
80
    Status collect_from_leaf(const TSearchClause& clause, RuntimeState* state,
81
                             const TabletSchemaSPtr& tablet_schema, CollectInfoMap* collect_infos);
82
    bool is_score_query_type(const std::string& clause_type) const;
83
    ClauseTypeCategory get_clause_type_category(const std::string& clause_type) const;
84
};
85
86
using PredicateCollectorPtr = std::unique_ptr<PredicateCollector>;
87
88
} // namespace doris