ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
//! The storage side of a range query, behind the `sqlx` feature: the comparisons a
//! [`TimeRangeFilter`] and a [`TimeRangedFilter`] cross into, and the crossings that get them there.
//!
//! ```text
//! TimeRangeFilter                       SqlTimeRangeComparison<Db>
//!   overlaps: { … }        ──►            ("…_start_secs", "…_start_nanos") <= (?, ?)
//!                                     AND ("…_end_secs",   "…_end_nanos")   >= (?, ?)
//!   start: { gte: … }      ──►            ("…_start_secs", "…_start_nanos") >= (?, ?)
//! ```
//!
//! # THE THREE INTERVAL WORDS, HALF-OPEN AND HAND-DERIVED
//!
//! Each is TWO inequalities joined by the conjunction this family already threads, and each
//! inequality is one seat of the column against one end of the operand. The column seat is a
//! [`Timestamp`], which is TWO columns, so every one of them renders as a ROW VALUE — the form
//! [`push_operand_cmp`](crate::comparison::sql::push_operand_cmp) selects on the operand's own
//! width, with nothing here judging one.
//!
//! | word | operand | first conjunct | second conjunct | strictness |
//! |---|---|---|---|---|
//! | `contains` | an instant `t` | `start <= t` | `end > t` | mixed |
//! | `contains` | a span `[a, b)` | `start <= a` | `end >= b` | neither |
//! | `overlaps` | a span `[a, b)` | `start < b` | `end > a` | both |
//! | `within` | a span `[a, b)` | `start >= a` | `end <= b` | neither |
//!
//! **The strictness column is the half-openness, and every cell of it is derived rather than
//! chosen.** A stretch is `[start, end)` — closed at the start, open at the end — so:
//!
//! * `contains` an INSTANT is MEMBERSHIP of that set, which admits `t == start` and refuses
//!   `t == end`. Mixed, and the mix IS the definition.
//! * `contains` a SPAN compares LIKE boundaries — closed start against closed start, open end
//!   against open end — and coincident like boundaries are contained, so neither is strict.
//!   `[0, 10)` contains `[0, 10)`.
//! * `within` is that comparison read from the other end, so it inherits the same answer.
//! * `overlaps` is INTERSECTION, and an intersection of width zero is empty — so both are strict
//!   and `[0, 10)` does not meet `[10, 20)`. This is the one word an interval's openness changes,
//!   and it is the one a closed reading gets silently wrong.
//!
//! The table is `mediagraph`'s (`types/time/timerange/mod.rs:519`) and the operators are what its
//! own lowering renders (`comparison.rs:294-311`); this file reproduces them rather than deriving a
//! second opinion.
//!
//! `overlaps` is also the CROSSED pair — the operand's END against the column's start — which is the
//! other half of why the words are lowered here rather than left to a caller's component filters.
//!
//! # ONE impl for every dialect, and that is a POSITIVE finding
//!
//! The claim is [`SqlScalarComparison`]'s own, restated for these six conjuncts: the SQL is
//! identical in SQLite, PostgreSQL and MySQL, and so are the bounds.
//!
//! * **The spelling is not a new one, and that is the load-bearing half.** Every conjunct here is
//!   [`push_operand_cmp`](crate::comparison::sql::push_operand_cmp) at a `Timestamp` operand, which
//!   is the SAME call a BARE instant column already makes: an instant's `SEGMENTS` are two, so
//!   `TimestampFilter`'s `gte` renders `("at_secs", "at_nanos") >= (?, ?)` today. So the row-value
//!   form's three-engine standing is inherited rather than claimed afresh — that function's own note
//!   records it measured on SQLite, PostgreSQL and MySQL for [`SqlKeyIn`]'s compound key. The
//!   interval words add CONJUNCTS, not a spelling.
//! * **The bounds.** `Timestamp: Carrier<Db>` is the whole requirement, and that row is generic over
//!   every dialect carrying an `i64` and an `i32` — which all three do.
//!
//! A fourth dialect is checked against those two statements. One whose row-value ordering differed
//! in either respect would need a concrete impl of its own.
//!
//! [`SqlKeyIn`]: crate::comparison::sql::SqlKeyIn
//!
//! # ONE address arrives, and the parts divide it
//!
//! [`SqlTimeRangeComparison`] frames `start` and `end` beneath whatever it was handed, so a range at
//! `heard` reaches `heard_start_*` and `heard_end_*`. [`SqlTimeRangedComparison`] applies the RANGE
//! at `at` UNCHANGED — flattening is exactly that — and pushes one segment for the payload, which is
//! the addressing this house's `storage` module already writes into its `SEGMENTS`.
//!
//! [`SqlScalarComparison`]: crate::comparison::sql::SqlScalarComparison
//! [`TimeRangeFilter`]: super::TimeRangeFilter
//! [`TimeRangedFilter`]: super::TimeRangedFilter

use core::fmt::{self, Display};

use crate::{
  At, Backend, Carrier, ColumnKind, ComplexComparison, CompositeComparison, Timestamp,
  ToDatabaseComparison, TryFromFilter,
  comparison::sql::{SqlConjunction, SqlScalarComparison, push_operand_cmp},
};

use super::{
  Contained, TimeRange, TimeRangeFilter, TimeRangedFilter,
  storage::{DATA, END, SEGMENTS, START},
};

#[cfg(all(test, feature = "sqlite"))]
mod tests;

/// [`TimeRangeFilter`](super::TimeRangeFilter)'s storage-side twin: the three interval words, and the
/// two ends.
///
/// # The interval words are held as OPERANDS rather than as comparisons, and the shape is honest
///
/// A component facet crosses into a whole [`SqlScalarComparison`] because the client sent a whole
/// filter — eight slots, any of which may be set. An interval word is ONE operand and lowers to two
/// fixed inequalities, so there is nothing for a comparison kind to hold: what a `SqlTimeRange`
/// comparison needs from `overlaps` is the stretch, and the two conjuncts are written out below.
///
/// Generic over the BACKEND and not one type per backend, for the reason its parts are: every seat
/// is a [`Timestamp`], whose carrier row spans all three dialects.
pub struct SqlTimeRangeComparison<Db> {
  overlaps: Option<TimeRange>,
  contains: Option<Contained>,
  within: Option<TimeRange>,
  start: SqlScalarComparison<Timestamp, Db>,
  end: SqlScalarComparison<Timestamp, Db>,
}

impl<Db> SqlTimeRangeComparison<Db> {
  /// The empty comparison — no operator set on any facet.
  #[inline]
  #[must_use]
  pub const fn new() -> Self {
    Self {
      overlaps: None,
      contains: None,
      within: None,
      start: SqlScalarComparison::new(),
      end: SqlScalarComparison::new(),
    }
  }

  /// The stretch the column must MEET, where one was asked for.
  #[inline]
  #[must_use]
  pub const fn overlaps(&self) -> Option<&TimeRange> {
    self.overlaps.as_ref()
  }

  /// The position or stretch the column must HOLD, where one was asked for.
  ///
  /// Two shapes at one slot — see [`Contained`], where the argument is the family's.
  #[inline]
  #[must_use]
  pub const fn contains(&self) -> Option<&Contained> {
    self.contains.as_ref()
  }

  /// The stretch the column must be INSIDE, where one was asked for.
  #[inline]
  #[must_use]
  pub const fn within(&self) -> Option<&TimeRange> {
    self.within.as_ref()
  }

  /// The operators over the first instant's two columns.
  #[inline]
  #[must_use]
  pub const fn start(&self) -> &SqlScalarComparison<Timestamp, Db> {
    &self.start
  }

  /// The operators over the last instant's two columns.
  #[inline]
  #[must_use]
  pub const fn end(&self) -> &SqlScalarComparison<Timestamp, Db> {
    &self.end
  }

  /// How many conjuncts the three interval words contribute — TWO apiece, because each word IS two
  /// inequalities.
  #[inline]
  const fn interval_conjuncts(&self) -> usize {
    2 * (self.overlaps.is_some() as usize
      + self.contains.is_some() as usize
      + self.within.is_some() as usize)
  }
}

/// The lowering: the three words' six possible conjuncts, then each end's own comparison one segment
/// below.
impl<Db> ComplexComparison<Db> for SqlTimeRangeComparison<Db>
where
  Db: sqlx::Database + for<'q> Backend<Builder<'q> = SqlConjunction<'q, Db>, Buffer: Display>,
  Timestamp: Carrier<Db> + ColumnKind,
{
  #[inline]
  fn conjuncts(&self) -> usize {
    self.interval_conjuncts()
      + ComplexComparison::<Db>::conjuncts(&self.start)
      + ComplexComparison::<Db>::conjuncts(&self.end)
  }

  /// Threading ONE accumulator through all five facets is what makes them guard one stretch: the
  /// conjuncts join with ` AND `, so a row satisfies this comparison when every word it was asked is
  /// true of the same four columns.
  ///
  /// The two seats are framed HERE and the operand's own end is chosen per conjunct, which is the
  /// crossing `overlaps` needs: its first conjunct compares the START column against the operand's
  /// END.
  fn apply<'q>(
    &'q self,
    at: At<'_>,
    mut builder: Db::Builder<'q>,
  ) -> Result<Db::Builder<'q>, Db::Error> {
    let start = at.frame(START);
    let end = at.frame(END);

    // `overlaps(q)` — the two half-open extents intersect: `start < q.end AND end > q.start`.
    // STRICT on both sides: an intersection of width zero is empty, so abutting stretches do not
    // meet.
    if let Some(operand) = &self.overlaps {
      push_operand_cmp(builder.open(), start.at(), " < ", &operand.end(), false);
      push_operand_cmp(builder.open(), end.at(), " > ", &operand.start(), false);
    }
    // `contains(q)` — TWO SHAPES, and the strictness differs between them because one is MEMBERSHIP
    // of a half-open set and the other compares like boundaries. See this module's table.
    match &self.contains {
      // An INSTANT: `start <= t AND end > t` — the open end is what refuses `t == end`.
      Some(Contained::Instant(at)) => {
        push_operand_cmp(builder.open(), start.at(), " <= ", at, false);
        push_operand_cmp(builder.open(), end.at(), " > ", at, false);
      }
      // A SPAN: `start <= q.start AND end >= q.end` — like boundaries, so neither is strict.
      Some(Contained::Span(span)) => {
        push_operand_cmp(builder.open(), start.at(), " <= ", &span.start(), false);
        push_operand_cmp(builder.open(), end.at(), " >= ", &span.end(), false);
      }
      None => {}
    }
    // `within(q)` — the column is inside `q`: `start >= q.start AND end <= q.end`.
    if let Some(operand) = &self.within {
      push_operand_cmp(builder.open(), start.at(), " >= ", &operand.start(), false);
      push_operand_cmp(builder.open(), end.at(), " <= ", &operand.end(), false);
    }

    let builder = self.start.apply(start.at(), builder)?;

    self.end.apply(end.at(), builder)
  }
}

/// The one place the four columns a stretch spans are stated, read by the predicate and by whatever
/// emits the DDL — and it is the storage module's `SEGMENTS`, not a second list.
impl<Db> CompositeComparison<Db> for SqlTimeRangeComparison<Db>
where
  Db: sqlx::Database + for<'q> Backend<Builder<'q> = SqlConjunction<'q, Db>, Buffer: Display>,
  Timestamp: Carrier<Db> + ColumnKind,
{
  const SEGMENTS: &'static [crate::ColumnShape] = SEGMENTS;
}

impl<Db> Default for SqlTimeRangeComparison<Db> {
  #[inline]
  fn default() -> Self {
    Self::new()
  }
}

/// Written out rather than derived, for the reason this crate's own comparison kinds write theirs
/// out: a derive would bound `Db`, which is a marker no dialect type implements anything for.
impl<Db> fmt::Debug for SqlTimeRangeComparison<Db> {
  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    f.debug_struct("SqlTimeRangeComparison")
      .field("overlaps", &self.overlaps)
      .field("contains", &self.contains)
      .field("within", &self.within)
      .field("start", &self.start)
      .field("end", &self.end)
      .finish()
  }
}

impl<Db> Clone for SqlTimeRangeComparison<Db> {
  fn clone(&self) -> Self {
    Self {
      overlaps: self.overlaps,
      contains: self.contains,
      within: self.within,
      start: self.start.clone(),
      end: self.end.clone(),
    }
  }
}

impl<Db> PartialEq for SqlTimeRangeComparison<Db> {
  fn eq(&self, other: &Self) -> bool {
    self.overlaps == other.overlaps
      && self.contains == other.contains
      && self.within == other.within
      && self.start == other.start
      && self.end == other.end
  }
}

/// Every SQL dialect takes the range filter to the range comparison, and the storage type is
/// [`Timestamp`] — the ONE type all four columns hold, so one word covers them.
impl<Db> ToDatabaseComparison<Timestamp, Db> for TimeRangeFilter
where
  Db: sqlx::Database + for<'q> Backend<Builder<'q> = SqlConjunction<'q, Db>, Buffer: Display>,
  Timestamp: Carrier<Db> + ColumnKind,
{
  type Comparison = SqlTimeRangeComparison<Db>;
}

/// The crossing, and the only route into a [`SqlTimeRangeComparison`].
///
/// [`Infallible`](core::convert::Infallible), and it is a PROOF rather than an optimism. Both halves
/// are unable to refuse: an interval operand is a [`TimeRange`] that has already been through
/// [`TimeRange::new`], and each component filter crosses into `SqlScalarComparison<Timestamp, _>`
/// through `Timestamp: TryFrom<Timestamp>` — std's reflexive blanket, whose error IS
/// `Infallible`. So the arm cannot be taken and no failure mode is published that this crossing has
/// not got.
impl<Db> TryFromFilter<TimeRangeFilter> for SqlTimeRangeComparison<Db> {
  type Error = core::convert::Infallible;

  fn try_from_filter(filter: TimeRangeFilter) -> Result<Self, Self::Error> {
    // Destructured rather than read through the getters, so a slot added to the filter tomorrow is
    // an `E0027` here instead of a facet silently not crossing.
    let TimeRangeFilter {
      overlaps,
      contains,
      within,
      start,
      end,
    } = filter;

    // A component slot is OPTIONAL on the wire, and an absent one asks nothing — which is the empty
    // filter.
    Ok(Self {
      overlaps: overlaps.map(Into::into),
      contains: contains.map(Into::into),
      within: within.map(Into::into),
      start: SqlScalarComparison::try_from_filter(start.unwrap_or_default())?,
      end: SqlScalarComparison::try_from_filter(end.unwrap_or_default())?,
    })
  }
}

/// [`TimeRangedFilter`](super::TimeRangedFilter)'s storage-side twin: the stretch's whole comparison,
/// and the payload's own beside it.
///
/// # THREE parameters, and the first is the PAYLOAD TYPE rather than its comparison
///
/// `C` is what the payload half IS — the shape every wrapping comparison here takes. `P` is the
/// payload's own Rust type, and it is carried for exactly [`SqlCompositeEdgeComparison`]'s reason:
/// a composite comparison has to state the columns it spans, and a WIDTH is a property of the value
/// rather than of the comparison. `SqlDetectedLanguageComparison` needs no such parameter because it
/// is concrete and can read one `const`; this kind is generic over the payload, so the payload has
/// to arrive as a type for its `SEGMENTS` to be readable at all.
///
/// It costs a caller one type argument and buys the `flatten` face: without it there is no
/// [`CompositeComparison`] row and a declaration could not lay a timed payload's columns out in its
/// holder's namespace.
///
/// [`SqlCompositeEdgeComparison`]: crate::comparison::sql::SqlCompositeEdgeComparison
pub struct SqlTimeRangedComparison<P, C, Db> {
  range: SqlTimeRangeComparison<Db>,
  data: C,
  // `fn() -> P` so the payload contributes no auto-trait or variance obligation — the shape every
  // reading parameter in this crate's filter family takes, for its reason.
  payload: core::marker::PhantomData<fn() -> P>,
}

impl<P, C, Db> SqlTimeRangedComparison<P, C, Db> {
  /// The empty comparison — no operator set on either half.
  #[inline]
  #[must_use]
  pub fn new() -> Self
  where
    C: Default,
  {
    Self {
      range: SqlTimeRangeComparison::new(),
      data: C::default(),
      payload: core::marker::PhantomData,
    }
  }

  /// The stretch's whole comparison — four columns, and every question this house asks of them.
  #[inline]
  #[must_use]
  pub const fn range(&self) -> &SqlTimeRangeComparison<Db> {
    &self.range
  }

  /// The payload's own comparison.
  #[inline]
  #[must_use]
  pub const fn data(&self) -> &C {
    &self.data
  }
}

/// The lowering: the range at the address it was given, then the payload one segment below.
///
/// Threading one accumulator through both is what makes the two facets guard ONE timed payload all
/// the way down — the claim the driving lane measures on a live engine, where a track carrying
/// Chinese in one span and the first minute in another must NOT answer *Chinese in the first
/// minute*.
impl<P, C, Db> ComplexComparison<Db> for SqlTimeRangedComparison<P, C, Db>
where
  Db: sqlx::Database + for<'q> Backend<Builder<'q> = SqlConjunction<'q, Db>, Buffer: Display>,
  Timestamp: Carrier<Db> + ColumnKind,
  C: ComplexComparison<Db>,
{
  #[inline]
  fn conjuncts(&self) -> usize {
    ComplexComparison::<Db>::conjuncts(&self.range) + ComplexComparison::<Db>::conjuncts(&self.data)
  }

  /// The range is applied at `at` UNCHANGED — flattening is exactly that — and the payload one
  /// segment below it.
  fn apply<'q>(
    &'q self,
    at: At<'_>,
    builder: Db::Builder<'q>,
  ) -> Result<Db::Builder<'q>, Db::Error> {
    let builder = self.range.apply(at, builder)?;
    let data = at.frame(DATA);

    self.data.apply(data.at(), builder)
  }
}

/// The one place the columns a timed payload spans are stated — [`TimeRanged<P>`]'s own
/// `ColumnKind` row, read rather than restated, which is what the `P` parameter is FOR.
///
/// [`TimeRanged<P>`]: super::TimeRanged
impl<P, C, Db> CompositeComparison<Db> for SqlTimeRangedComparison<P, C, Db>
where
  Db: sqlx::Database + for<'q> Backend<Builder<'q> = SqlConjunction<'q, Db>, Buffer: Display>,
  Timestamp: Carrier<Db> + ColumnKind,
  C: ComplexComparison<Db>,
  P: ColumnKind,
{
  const SEGMENTS: &'static [crate::ColumnShape] = <super::TimeRanged<P> as ColumnKind>::SEGMENTS;
}

impl<P, C: Default, Db> Default for SqlTimeRangedComparison<P, C, Db> {
  #[inline]
  fn default() -> Self {
    Self::new()
  }
}

impl<P, C: fmt::Debug, Db> fmt::Debug for SqlTimeRangedComparison<P, C, Db> {
  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    f.debug_struct("SqlTimeRangedComparison")
      .field("range", &self.range)
      .field("data", &self.data)
      .finish()
  }
}

impl<P, C: Clone, Db> Clone for SqlTimeRangedComparison<P, C, Db> {
  fn clone(&self) -> Self {
    Self {
      range: self.range.clone(),
      data: self.data.clone(),
      payload: core::marker::PhantomData,
    }
  }
}

impl<P, C: PartialEq, Db> PartialEq for SqlTimeRangedComparison<P, C, Db> {
  fn eq(&self, other: &Self) -> bool {
    self.range == other.range && self.data == other.data
  }
}

/// **THE ROUTING ROW, and it reaches every payload whose filter routes on its own type.**
///
/// The storage type is `TimeRanged<P>` rather than the pair `(Timestamp, V)`
/// [`DetectedLanguageFilter`](crate::DetectedLanguageFilter)'s row spells, and the divergence is
/// argued rather than inherited. A pair names how the columns are BOUND; this kind also has to know
/// how many there ARE, and a width is the DOMAIN type's — so a routing row producing
/// `SqlTimeRangedComparison<P, …>` from `(Timestamp, V)` alone cannot name `P` at all. Spelling the
/// storage type as `TimeRanged<P>` is what carries both facts, and it is honest: a timed payload
/// column IS stored as a timed payload.
///
/// **What it does NOT reach is a payload whose own filter routes on a PAIR** — a detection, whose row
/// is `ToDatabaseComparison<(String, Score), _>`. Such a column is reached by NAMING the comparison,
/// which is how every composite-element party in this crate is reached today and for the same reason:
/// see [`SqlCompositeEdgeComparison`](crate::comparison::sql::SqlCompositeEdgeComparison), whose own
/// note records that it is named rather than routed. The driving lane names both.
impl<TF, P, Db> ToDatabaseComparison<super::TimeRanged<P>, Db> for TimeRangedFilter<TF>
where
  Db: sqlx::Database + for<'q> Backend<Builder<'q> = SqlConjunction<'q, Db>, Buffer: Display>,
  Timestamp: Carrier<Db> + ColumnKind,
  TF: ToDatabaseComparison<P, Db>,
  P: ColumnKind,
{
  type Comparison = SqlTimeRangedComparison<P, TF::Comparison, Db>;
}

/// The crossing, and the only route into a [`SqlTimeRangedComparison`].
///
/// The error is the PAYLOAD's, unwrapped rather than boxed in a variant of this house's own: the
/// range half is provably infallible — see [`SqlTimeRangeComparison`]'s row — so every refusal this
/// crossing can produce is one the payload family already names, and widening it here would publish
/// a failure mode that does not exist. It is the same reduction
/// [`SqlDetectedLanguageComparison`](crate::SqlDetectedLanguageComparison) makes when it reuses
/// [`LanguageIdCrossingError`](crate::LanguageIdCrossingError).
impl<P, TF, C, Db> TryFromFilter<TimeRangedFilter<TF>> for SqlTimeRangedComparison<P, C, Db>
where
  TF: Default,
  C: TryFromFilter<TF>,
{
  type Error = C::Error;

  fn try_from_filter(filter: TimeRangedFilter<TF>) -> Result<Self, Self::Error> {
    // Destructured for `SqlTimeRangeComparison`'s reason: a facet added tomorrow is `E0027` here.
    let TimeRangedFilter { range, data } = filter;

    let range = SqlTimeRangeComparison::try_from_filter(range.unwrap_or_default())
      .unwrap_or_else(|infallible| match infallible {});

    Ok(Self {
      range,
      data: C::try_from_filter(data.unwrap_or_default())?,
      payload: core::marker::PhantomData,
    })
  }
}