Coverage Report

Created: 2026-03-19 11:17

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
35
    bool operator()(const segment_v2::TermInfo& lhs, const segment_v2::TermInfo& rhs) const {
40
35
        return lhs.term < rhs.term;
41
35
    }
42
};
43
44
struct CollectInfo {
45
    std::set<segment_v2::TermInfo, TermInfoComparer> term_infos;
46
    const TabletIndex* index_meta = nullptr;
47
};
48
using CollectInfoMap = std::unordered_map<std::wstring, CollectInfo>;
49
50
class PredicateCollector {
51
public:
52
48
    virtual ~PredicateCollector() = default;
53
54
    virtual Status collect(RuntimeState* state, const TabletSchemaSPtr& tablet_schema,
55
                           const VExprSPtr& expr, CollectInfoMap* collect_infos) = 0;
56
57
protected:
58
    VSlotRef* find_slot_ref(const VExprSPtr& expr) const;
59
    std::string build_field_name(int32_t col_unique_id, const std::string& suffix_path) const;
60
};
61
62
class MatchPredicateCollector : public PredicateCollector {
63
public:
64
    Status collect(RuntimeState* state, const TabletSchemaSPtr& tablet_schema,
65
                   const VExprSPtr& expr, CollectInfoMap* collect_infos) override;
66
};
67
68
class SearchPredicateCollector : public PredicateCollector {
69
public:
70
    Status collect(RuntimeState* state, const TabletSchemaSPtr& tablet_schema,
71
                   const VExprSPtr& expr, CollectInfoMap* collect_infos) override;
72
73
private:
74
    enum class ClauseTypeCategory { NON_TOKENIZED, TOKENIZED, COMPOUND };
75
76
    Status collect_from_clause(const TSearchClause& clause, RuntimeState* state,
77
                               const TabletSchemaSPtr& tablet_schema,
78
                               CollectInfoMap* collect_infos);
79
    Status collect_from_leaf(const TSearchClause& clause, RuntimeState* state,
80
                             const TabletSchemaSPtr& tablet_schema, CollectInfoMap* collect_infos);
81
    bool is_score_query_type(const std::string& clause_type) const;
82
    ClauseTypeCategory get_clause_type_category(const std::string& clause_type) const;
83
};
84
85
using PredicateCollectorPtr = std::unique_ptr<PredicateCollector>;
86
87
} // namespace doris