1use crate::catalog::CatalogType;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum Filter {
6 And(Vec<Filter>),
7 Or(Vec<Filter>),
8 Leaf(Comparison),
9}
10
11#[derive(Debug, Clone, PartialEq, Eq)]
14pub enum Comparison {
15 Compare {
17 column: String,
18 op: CompareOp,
19 value: String,
20 },
21 Set {
23 column: String,
24 op: SetOp,
25 values: Vec<String>,
26 },
27 NullCheck { column: String, is_null: bool },
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
33pub enum CompareOp {
34 Eq,
35 NotEq,
36 Gt,
37 Gte,
38 Lt,
39 Lte,
40 Like,
41 StartsWith,
42 EndsWith,
43}
44
45#[derive(Debug, Clone, Copy, PartialEq, Eq)]
47pub enum SetOp {
48 In,
49 NotIn,
50}
51
52impl CompareOp {
53 pub fn supported_by(&self, data_type: &CatalogType) -> bool {
55 match self {
56 Self::Eq | Self::NotEq => data_type.supports_equality(),
57 Self::Gt | Self::Gte | Self::Lt | Self::Lte => data_type.supports_ordering(),
58 Self::Like | Self::StartsWith | Self::EndsWith => data_type.supports_text_pattern(),
59 }
60 }
61
62 pub fn name(&self) -> &'static str {
64 match self {
65 Self::Eq => "==",
66 Self::NotEq => "!=",
67 Self::Gt => "=gt=",
68 Self::Gte => "=ge=",
69 Self::Lt => "=lt=",
70 Self::Lte => "=le=",
71 Self::Like => "=like=",
72 Self::StartsWith => "=starts=",
73 Self::EndsWith => "=ends=",
74 }
75 }
76}
77
78impl SetOp {
79 pub fn supported_by(&self, data_type: &CatalogType) -> bool {
81 data_type.supports_set()
82 }
83
84 pub fn name(&self) -> &'static str {
86 match self {
87 Self::In => "=in=",
88 Self::NotIn => "=out=",
89 }
90 }
91}