graphrecords_query/operations/argument/
constant.rs1use crate::{
2 AttributeName, Explain, FailureKind, FailureKindValue, IndexValue, Mask, Position, QueryResult,
3 Scalar, ValueDomain,
4 element::Preserving,
5 execution::EvaluationCache,
6 explain::ExplainFormatter,
7 index::Positional,
8 operations::{Alignment, ArgumentSource, Lookup, Prepare, SourceDomain},
9 optimizer::{Estimate, Estimated, PlanIdentity, PlanInputs, Stats},
10};
11use graphrecords_core::{
12 GraphRecord,
13 graphrecord::{EdgeIndex, GraphRecordAttribute, GraphRecordValue},
14};
15use std::{
16 fmt::{self, Write},
17 hash::{Hash, Hasher},
18};
19
20impl Explain for GraphRecordValue {
21 fn describe<'a>(&'a self, formatter: &mut ExplainFormatter<'a, '_>) -> fmt::Result {
22 write!(formatter, "{self}")
23 }
24}
25
26impl PlanIdentity for GraphRecordValue {
27 fn identity_eq(&self, other: &Self) -> bool {
28 self == other
29 }
30
31 fn identity_hash<H: Hasher>(&self, state: &mut H) {
32 self.hash(state);
33 }
34}
35
36impl PlanInputs for GraphRecordValue {}
37
38impl Prepare for GraphRecordValue {
39 type Prepared<'a> = QueryResult<Self>;
40
41 fn prepare<'a>(
42 &'a self,
43 _graphrecord: &'a GraphRecord,
44 _cache: &'a EvaluationCache<'a>,
45 ) -> QueryResult<Self::Prepared<'a>> {
46 Ok(Ok(self.clone()))
47 }
48}
49
50impl Estimated for GraphRecordValue {
51 fn estimate(&self, _stats: &Stats) -> Estimate {
52 Estimate::singleton()
53 }
54}
55
56impl SourceDomain for GraphRecordValue {
57 type ValueDomain = Scalar;
58}
59
60impl<A, V> ArgumentSource<A, V> for GraphRecordValue
61where
62 A: Alignment,
63 for<'a> V: ValueDomain<Value<'a> = Self>,
64{
65 type Retention = Preserving;
66
67 fn lookup<'a, 'prepared>(
68 prepared: &'prepared Self::Prepared<'a>,
69 _address: &A::Address<'a>,
70 ) -> Lookup<'prepared, QueryResult<V::Value<'a>>>
71 where
72 Self: 'a,
73 {
74 Lookup::Present(prepared)
75 }
76}
77
78impl Explain for bool {
79 fn describe<'a>(&'a self, formatter: &mut ExplainFormatter<'a, '_>) -> fmt::Result {
80 write!(formatter, "{self}")
81 }
82}
83
84impl PlanIdentity for bool {
85 fn identity_eq(&self, other: &Self) -> bool {
86 self == other
87 }
88
89 fn identity_hash<H: Hasher>(&self, state: &mut H) {
90 self.hash(state);
91 }
92}
93
94impl PlanInputs for bool {}
95
96impl Prepare for bool {
97 type Prepared<'a> = QueryResult<Self>;
98
99 fn prepare<'a>(
100 &'a self,
101 _graphrecord: &'a GraphRecord,
102 _cache: &'a EvaluationCache<'a>,
103 ) -> QueryResult<Self::Prepared<'a>> {
104 Ok(Ok(*self))
105 }
106}
107
108impl Estimated for bool {
109 fn estimate(&self, _stats: &Stats) -> Estimate {
110 Estimate {
111 selectivity: Some(if *self { 1.0 } else { 0.0 }),
112 ..Estimate::singleton()
113 }
114 }
115}
116
117impl SourceDomain for bool {
118 type ValueDomain = Mask;
119}
120
121impl<A, V> ArgumentSource<A, V> for bool
122where
123 A: Alignment,
124 for<'a> V: ValueDomain<Value<'a> = Self>,
125{
126 type Retention = Preserving;
127
128 fn lookup<'a, 'prepared>(
129 prepared: &'prepared Self::Prepared<'a>,
130 _address: &A::Address<'a>,
131 ) -> Lookup<'prepared, QueryResult<V::Value<'a>>>
132 where
133 Self: 'a,
134 {
135 Lookup::Present(prepared)
136 }
137}
138
139impl Explain for GraphRecordAttribute {
140 fn describe<'a>(&'a self, formatter: &mut ExplainFormatter<'a, '_>) -> fmt::Result {
141 write!(formatter, "{self}")
142 }
143}
144
145impl PlanIdentity for GraphRecordAttribute {
146 fn identity_eq(&self, other: &Self) -> bool {
147 self == other
148 }
149
150 fn identity_hash<H: Hasher>(&self, state: &mut H) {
151 self.hash(state);
152 }
153}
154
155impl PlanInputs for GraphRecordAttribute {}
156
157impl Prepare for GraphRecordAttribute {
158 type Prepared<'a> = QueryResult<Self>;
159
160 fn prepare<'a>(
161 &'a self,
162 _graphrecord: &'a GraphRecord,
163 _cache: &'a EvaluationCache<'a>,
164 ) -> QueryResult<Self::Prepared<'a>> {
165 Ok(Ok(self.clone()))
166 }
167}
168
169impl Estimated for GraphRecordAttribute {
170 fn estimate(&self, _stats: &Stats) -> Estimate {
171 Estimate::singleton()
172 }
173}
174
175impl SourceDomain for GraphRecordAttribute {
176 type ValueDomain = AttributeName;
177}
178
179impl<A, V> ArgumentSource<A, V> for GraphRecordAttribute
180where
181 A: Alignment,
182 for<'a> V: ValueDomain<Value<'a> = Self>,
183{
184 type Retention = Preserving;
185
186 fn lookup<'a, 'prepared>(
187 prepared: &'prepared Self::Prepared<'a>,
188 _address: &A::Address<'a>,
189 ) -> Lookup<'prepared, QueryResult<V::Value<'a>>>
190 where
191 Self: 'a,
192 {
193 Lookup::Present(prepared)
194 }
195}
196
197impl Explain for EdgeIndex {
198 fn describe<'a>(&'a self, formatter: &mut ExplainFormatter<'a, '_>) -> fmt::Result {
199 write!(formatter, "{self}")
200 }
201}
202
203impl PlanIdentity for EdgeIndex {
204 fn identity_eq(&self, other: &Self) -> bool {
205 self == other
206 }
207
208 fn identity_hash<H: Hasher>(&self, state: &mut H) {
209 self.hash(state);
210 }
211}
212
213impl PlanInputs for EdgeIndex {}
214
215impl Prepare for EdgeIndex {
216 type Prepared<'a> = QueryResult<Self>;
217
218 fn prepare<'a>(
219 &'a self,
220 _graphrecord: &'a GraphRecord,
221 _cache: &'a EvaluationCache<'a>,
222 ) -> QueryResult<Self::Prepared<'a>> {
223 Ok(Ok(*self))
224 }
225}
226
227impl Estimated for EdgeIndex {
228 fn estimate(&self, _stats: &Stats) -> Estimate {
229 Estimate::singleton()
230 }
231}
232
233impl SourceDomain for EdgeIndex {
234 type ValueDomain = IndexValue<Self>;
235}
236
237impl<A, V> ArgumentSource<A, V> for EdgeIndex
238where
239 A: Alignment,
240 for<'a> V: ValueDomain<Value<'a> = Self>,
241{
242 type Retention = Preserving;
243
244 fn lookup<'a, 'prepared>(
245 prepared: &'prepared Self::Prepared<'a>,
246 _address: &A::Address<'a>,
247 ) -> Lookup<'prepared, QueryResult<V::Value<'a>>>
248 where
249 Self: 'a,
250 {
251 Lookup::Present(prepared)
252 }
253}
254
255impl Explain for Position {
256 fn describe<'a>(&'a self, formatter: &mut ExplainFormatter<'a, '_>) -> fmt::Result {
257 write!(formatter, "{self}")
258 }
259}
260
261impl PlanIdentity for Position {
262 fn identity_eq(&self, other: &Self) -> bool {
263 self == other
264 }
265
266 fn identity_hash<H: Hasher>(&self, state: &mut H) {
267 self.hash(state);
268 }
269}
270
271impl PlanInputs for Position {}
272
273impl Prepare for Position {
274 type Prepared<'a> = QueryResult<Self>;
275
276 fn prepare<'a>(
277 &'a self,
278 _graphrecord: &'a GraphRecord,
279 _cache: &'a EvaluationCache<'a>,
280 ) -> QueryResult<Self::Prepared<'a>> {
281 Ok(Ok(*self))
282 }
283}
284
285impl Estimated for Position {
286 fn estimate(&self, _stats: &Stats) -> Estimate {
287 Estimate::singleton()
288 }
289}
290
291impl SourceDomain for Position {
292 type ValueDomain = IndexValue<Positional>;
293}
294
295impl<A, V> ArgumentSource<A, V> for Position
296where
297 A: Alignment,
298 for<'a> V: ValueDomain<Value<'a> = Self>,
299{
300 type Retention = Preserving;
301
302 fn lookup<'a, 'prepared>(
303 prepared: &'prepared Self::Prepared<'a>,
304 _address: &A::Address<'a>,
305 ) -> Lookup<'prepared, QueryResult<V::Value<'a>>>
306 where
307 Self: 'a,
308 {
309 Lookup::Present(prepared)
310 }
311}
312
313impl Explain for FailureKind {
314 fn describe<'a>(&'a self, formatter: &mut ExplainFormatter<'a, '_>) -> fmt::Result {
315 write!(formatter, "{self}")
316 }
317}
318
319impl PlanIdentity for FailureKind {
320 fn identity_eq(&self, other: &Self) -> bool {
321 self == other
322 }
323
324 fn identity_hash<H: Hasher>(&self, state: &mut H) {
325 self.hash(state);
326 }
327}
328
329impl PlanInputs for FailureKind {}
330
331impl Prepare for FailureKind {
332 type Prepared<'a> = QueryResult<Self>;
333
334 fn prepare<'a>(
335 &'a self,
336 _graphrecord: &'a GraphRecord,
337 _cache: &'a EvaluationCache<'a>,
338 ) -> QueryResult<Self::Prepared<'a>> {
339 Ok(Ok(*self))
340 }
341}
342
343impl Estimated for FailureKind {
344 fn estimate(&self, _stats: &Stats) -> Estimate {
345 Estimate::singleton()
346 }
347}
348
349impl SourceDomain for FailureKind {
350 type ValueDomain = FailureKindValue;
351}
352
353impl<A, V> ArgumentSource<A, V> for FailureKind
354where
355 A: Alignment,
356 for<'a> V: ValueDomain<Value<'a> = Self>,
357{
358 type Retention = Preserving;
359
360 fn lookup<'a, 'prepared>(
361 prepared: &'prepared Self::Prepared<'a>,
362 _address: &A::Address<'a>,
363 ) -> Lookup<'prepared, QueryResult<V::Value<'a>>>
364 where
365 Self: 'a,
366 {
367 Lookup::Present(prepared)
368 }
369}