be/src/exprs/function/search/function_search_leaf.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 <cstdint> |
21 | | #include <memory> |
22 | | #include <roaring/roaring.hh> |
23 | | #include <string> |
24 | | #include <utility> |
25 | | |
26 | | #include "common/status.h" |
27 | | #include "core/data_type/data_type.h" |
28 | | #include "storage/index/index_iterator.h" |
29 | | #include "storage/index/index_query_context.h" |
30 | | #include "storage/index/inverted/query/engine/bit_set_query/bit_set_query.h" |
31 | | #include "storage/index/inverted/query/engine/query.h" |
32 | | #include "storage/index/inverted/query/logical/node.h" |
33 | | #include "storage/index/inverted/query/spi/index_source.h" |
34 | | |
35 | | namespace doris { |
36 | | |
37 | | // What a leaf needs from the query it is part of. |
38 | | struct SearchLeafContext { |
39 | | std::shared_ptr<segment_v2::IndexQueryContext> context; |
40 | | uint32_t num_rows = 0; |
41 | | // Whether the query scores its rows; clauses that only add to the score matter only then. |
42 | | bool scoring = true; |
43 | | }; |
44 | | |
45 | | // Compiles one lowered leaf on its bound text or scalar index. |
46 | | class SearchLeafCompiler { |
47 | | public: |
48 | 249 | virtual ~SearchLeafCompiler() = default; |
49 | | |
50 | | virtual Status compile(const index_query::logical::Node& leaf, const SearchLeafContext& ctx, |
51 | | segment_v2::inverted_index::query_v2::QueryPtr* out) = 0; |
52 | | }; |
53 | | |
54 | | // Compiles a leaf into the lazy query_v2 query the engine evaluates on the field's bound source, |
55 | | // after the source resolved the leaf's terms in one dictionary batch. |
56 | | class LazyLeafCompiler final : public SearchLeafCompiler { |
57 | | public: |
58 | | LazyLeafCompiler(std::wstring field, std::string binding_key, |
59 | | index_query::IndexSourcePtr source); |
60 | | |
61 | | Status compile(const index_query::logical::Node& leaf, const SearchLeafContext& ctx, |
62 | | segment_v2::inverted_index::query_v2::QueryPtr* out) override; |
63 | | |
64 | | private: |
65 | | std::wstring _field; |
66 | | std::string _binding_key; |
67 | | index_query::IndexSourcePtr _source; |
68 | | }; |
69 | | |
70 | | // Answers a comparison leaf from a scalar (BKD) index through its iterator. |
71 | | // Unsupported leaves and invalid values fail the query. |
72 | | class ScalarLeafCompiler final : public SearchLeafCompiler { |
73 | | public: |
74 | | ScalarLeafCompiler(segment_v2::IndexIterator* iterator, DataTypePtr column_type, |
75 | | std::string stored_field_name); |
76 | | |
77 | | Status compile(const index_query::logical::Node& leaf, const SearchLeafContext& ctx, |
78 | | segment_v2::inverted_index::query_v2::QueryPtr* out) override; |
79 | | |
80 | | private: |
81 | | segment_v2::IndexIterator* _iterator; |
82 | | DataTypePtr _column_type; |
83 | | std::string _stored_field_name; |
84 | | }; |
85 | | |
86 | | } // namespace doris |