Skip to main content

icydb_core/db/query/predicate/
ast.rs

1use crate::value::Value;
2
3use super::coercion::CoercionSpec;
4
5///
6/// Predicate AST
7///
8/// Pure, schema-agnostic representation of query predicates.
9/// This layer contains no type validation, index logic, or execution
10/// semantics. All interpretation occurs in later passes:
11///
12/// - normalization
13/// - validation (schema-aware)
14/// - planning
15/// - execution
16///
17
18///
19/// CompareOp
20///
21
22#[derive(Clone, Copy, Debug, Eq, PartialEq)]
23pub enum CompareOp {
24    Eq,
25    Ne,
26    Lt,
27    Lte,
28    Gt,
29    Gte,
30    In,
31    NotIn,
32    AnyIn,
33    AllIn,
34    Contains,
35    StartsWith,
36    EndsWith,
37}
38
39///
40/// ComparePredicate
41///
42
43#[derive(Clone, Debug, Eq, PartialEq)]
44pub struct ComparePredicate {
45    pub field: String,
46    pub op: CompareOp,
47    pub value: Value,
48    pub coercion: CoercionSpec,
49}
50
51///
52/// Predicate
53///
54
55#[derive(Clone, Debug, Eq, PartialEq)]
56pub enum Predicate {
57    True,
58    False,
59    And(Vec<Self>),
60    Or(Vec<Self>),
61    Not(Box<Self>),
62    Compare(ComparePredicate),
63    IsNull {
64        field: String,
65    },
66    IsMissing {
67        field: String,
68    },
69    IsEmpty {
70        field: String,
71    },
72    IsNotEmpty {
73        field: String,
74    },
75    MapContainsKey {
76        field: String,
77        key: Value,
78        coercion: CoercionSpec,
79    },
80    MapContainsValue {
81        field: String,
82        value: Value,
83        coercion: CoercionSpec,
84    },
85    MapContainsEntry {
86        field: String,
87        key: Value,
88        value: Value,
89        coercion: CoercionSpec,
90    },
91}