index/inverted_index/search/
predicate.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::collections::HashSet;
16
17use crate::Bytes;
18
19/// Enumerates types of predicates for value filtering.
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub enum Predicate {
22    /// Predicate for matching values in a list.
23    InList(InListPredicate),
24
25    /// Predicate for matching values within a range.
26    Range(RangePredicate),
27
28    /// Predicate for matching values against a regex pattern.
29    RegexMatch(RegexMatchPredicate),
30}
31
32/// `InListPredicate` contains a list of acceptable values. A value needs to match at least
33/// one of the elements (logical OR semantic) for the predicate to be satisfied.
34#[derive(Debug, Clone, PartialEq, Eq)]
35pub struct InListPredicate {
36    /// List of acceptable values.
37    pub list: HashSet<Bytes>,
38}
39
40/// `Bound` is a sub-component of a range, representing a single-sided limit that could be inclusive or exclusive.
41#[derive(Debug, Clone, PartialEq, Eq)]
42pub struct Bound {
43    /// Whether the bound is inclusive or exclusive.
44    pub inclusive: bool,
45    /// The value of the bound.
46    pub value: Bytes,
47}
48
49/// `Range` defines a single continuous range which can optionally have a lower and/or upper limit.
50/// Both the lower and upper bounds must be satisfied for the range condition to be true.
51#[derive(Debug, Clone, PartialEq, Eq)]
52pub struct Range {
53    /// The lower bound of the range.
54    pub lower: Option<Bound>,
55    /// The upper bound of the range.
56    pub upper: Option<Bound>,
57}
58
59/// `RangePredicate` encapsulates a range condition that must be satisfied
60/// for the predicate to hold true (logical AND semantic between the bounds).
61#[derive(Debug, Clone, PartialEq, Eq)]
62pub struct RangePredicate {
63    /// The range condition.
64    pub range: Range,
65}
66
67/// `RegexMatchPredicate` encapsulates a single regex pattern. A value must match
68/// the pattern for the predicate to be satisfied.
69#[derive(Debug, Clone, PartialEq, Eq)]
70pub struct RegexMatchPredicate {
71    /// The regex pattern.
72    pub pattern: String,
73}