1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//! [`FieldPredicate<T>`] — the per-field predicate payload carried inside
//! [`BasicPredicate::Field`](super::BasicPredicate::Field).
//!
//! Each `FieldPredicate` carries three pieces of information so it can
//! be walked by both in-memory evaluators (sassi's own `evaluate`) AND
//! external walkers (downstream SQL emitters in djogi, predicate-plan
//! debug formatters):
//!
//! 1. The **field name** (`field_name`) — the column / serde key.
//! 2. The **operator marker** (`op` of type [`LookupOp`]) — informational
//! in sassi proper but load-bearing for SQL emitters that dispatch on
//! op kind.
//! 3. The **operand value(s)** (`value`) — type-erased as
//! `Arc<dyn Any + Send + Sync>`; downstream walkers downcast via
//! `Any::downcast_ref` to inspect. Layout depends on `op` (see
//! [`LookupOp`] documentation).
//!
//! Plus a pre-built evaluation closure (`eval`) for the fast-path
//! in-memory walk — captured at construction so `evaluate` never has
//! to re-dispatch on op + value type at runtime.
use Any;
use Arc;
/// Lookup operator marker. Used for diagnostics + by SQL-emitting
/// downstream consumers (e.g., djogi's `Q<T>` walker) to choose the
/// right SQL construction. Also tells walkers what the
/// [`FieldPredicate::value`] payload contains:
///
/// | Op | `value` payload |
/// |---|---|
/// | `Eq`, `Neq`, `Gt`, `Gte`, `Lt`, `Lte` | `Arc<V>` |
/// | `In`, `NotIn` | `Arc<Vec<V>>` |
/// | `Between` | `Arc<(V, V)>` |
/// | `IsNull`, `IsNotNull` | `Arc<()>` (no operand) |
/// | `Contains`, `IContains`, `StartsWith`, `IStartsWith`, `EndsWith`, `IEndsWith`, `IExact` | `Arc<String>` |
///
/// Marked `#[non_exhaustive]` so adding new ops in a future release does not
/// break downstream matchers.
/// Single-field predicate. Carries the field name, operator marker, the
/// type-erased operand value, and a pre-built evaluation closure.
///
/// Construction is via the `Field<T, V>` lookup methods (see
/// [`Field::eq`](crate::cacheable::Field), `gt`, `contains`, etc.). The
/// closure-capture pattern keeps `FieldPredicate<T>` `'static` (no
/// borrows of the construction-time value) and `Send + Sync` provided
/// the captured value is `Send + Sync`.
///
/// All fields are private. Use [`field_name`](Self::field_name),
/// [`op`](Self::op), [`value`](Self::value), and
/// [`value_as`](Self::value_as) to access. Internal evaluation is
/// driven by `BasicPredicate::evaluate` walking the enclosing predicate
/// tree; consumers do not call into `FieldPredicate` directly.