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
//! The AGGREGATE declaration's model — the three parts every aggregation has, read off a grammar
//! and held until the emission arrives.
//!
//! ```ignore
//! #[ingraph::aggregate(
//! upstream(node = "demux::Track"),
//! group(codec = "codec"),
//! measure(count = counting, bytes(fold = summing, from = "size")),
//! poll(recount, every = "10m", light),
//! sqlite,
//! )]
//! pub struct CodecCensus {
//! #[ingraph(group)] codec: Codec,
//! #[ingraph(measure)] count: ingraph::Count,
//! #[ingraph(measure)] bytes: u64,
//! }
//! ```
//!
//! # The grammar NAMES the sentence, and the sentence is `SELECT count(*) FROM t GROUP BY codec`
//!
//! `upstream(…)` is the `FROM`, [`GROUP`] is the `GROUP BY`, and [`MEASURE`] is the aggregate
//! functions. The two words beside them are the ones SQL has no room for and a running system
//! cannot do without: the CLOCK that decides when the answer is recomputed, and the STORE the
//! answer lands in.
//!
//! # It consumes TABLES rather than messages, which is the whole safety argument
//!
//! The framework's delivery correctness is at-least-once plus keyed replace, so duplicates are
//! NORMAL operation — fan-out clones per edge, a rewind re-delivering the unacked tail, a retry
//! re-sending — and no app-visible message id exists to dedup on. An incremental `count += 1`
//! cannot inherit that theorem. So a trigger reads the upstream's ROWS, groups them, folds each
//! group and upserts one row per group: immune to duplicates by construction, self-healing on every
//! tick, and deletion-correct for free, a removed upstream row simply ceasing to be counted.
//!
//! # THE MODEL IS HERE AND THE EMISSION IS BESIDE IT
//!
//! The grammar in `ingraph-derive` builds this model and every rule a declaration can break is
//! refused there by name; the front end then MOUNTS it — the `(group…, measure…)` columns, keyed by
//! the group projection, handed to the ordinary record pass — and hands both halves back as
//! [`Mounted`], which is what expands. Sentences stay the front end's, sentences being the front
//! end's; what belongs here is the model, and beside it in [`emit`] the one thing a record cannot
//! say: what a group's rows fold into.
/// The head block that names the GROUP columns, and the field marker that wears the same word.
///
/// ONE word in two positions, which is [`MEASURE`]'s shape too and the house's own: `searchable` is
/// a full-text declaration's field marker and an entry inside a `vector`'s `knn(…)`, meaning the
/// same thing in both. The block says WHERE a group column is read from, the marker says WHAT THE
/// FIELD IS, and a declaration whose two halves disagree is refused by name rather than resolved by
/// precedence.
pub const GROUP: &str = "group";
/// The head block that names the MEASURE columns, and the field marker that wears the same word.
///
/// The word `fold` was unavailable AS A BLOCK WORD — `semantics(fold(…))` is set-similarity
/// combination, one grammar over — and the collective spelling the design sketch carried (`census`)
/// was settled against the house register by the grammar task: every block word in this family
/// names WHAT AN ENTRY IS (`upstream`, `lineage`, `poll`, `graphql`, `group`), never what the
/// declaration as a whole amounts to, and a census is the whole. So the block takes the entry's own
/// noun, and takes it in the singular, which is `upstream(<field> = "…")`'s rule for a block holding
/// N entries.
///
/// **`fold` returns one grain in as a PROPERTY of an entry** — `measure(<field>(fold = …, from =
/// "…"))` — and that is not the collision the block word dodged. A property word is read inside one
/// entry of one block, where the set-similarity word is an entry of `semantics(…)`; neither reader
/// can see the other's position, and what the word means in both is the same thing said about a
/// different subject.
pub const MEASURE: &str = "measure";
/// A validated aggregate declaration.
///
/// PLAIN, for the reason every model in this crate has plain fields: the derive today and a
/// manifest front end later reach the same emitter.
///
/// # Three fields are TOKENS, and the passthrough is the journal's law rather than laziness
///
/// [`triggers`](Self::triggers), [`stores`](Self::stores) and [`graphql`](Self::graphql) are the
/// words this declaration shares with the RECORD grammar, and they are carried UNINTERPRETED. The
/// aggregate's storage IS a record's — the emission mints the `(group…, measure…)` row shape and
/// hands it to the record pass, which is `#[ingraph::journal]`'s pattern verbatim — so reading a
/// database block, a `table = "…"` or a `poll(…)` entry here would be a SECOND authority for one
/// vocabulary, and two authorities for one vocabulary is how the two of them drift.
///
/// What the front end knows about them is only which WORDS start one, which it needs anyway to
/// refuse a declaration that names no clock. Their teeth arrive with the record pass, at the same
/// expansion that spends them.
/// One GROUP column: a field of this declaration, and the upstream field it is read out of.
/// One MEASURE column: a field of this declaration, what folds a group's rows into it, and the
/// upstream column that fold is handed.
/// WHAT FOLDS a group's rows into one measure column.
///
/// # The axis is CLOSED on the framework's side and OPEN past it
///
/// A bare word is one of the framework's own shipped folds, and that vocabulary is closed because a
/// word is a promise this crate can write the whole binding — which it can only keep for a fold it
/// SHIPS. A QUOTED PATH is every other fold there is: a type the declaring crate wrote, named the
/// way this grammar names every type it did not mint, with no vocabulary to be admitted to.
///
/// That is the round's own law read at one more position — MINT BARE, REFER QUOTED — and it is why
/// the two forms are one enum rather than two words: an author choosing between a shipped fold and
/// their own is choosing a value for one entry, not writing a different entry.
///
/// The axis is about the fold's ORIGIN and about nothing else, so it is orthogonal to the entry's
/// two spellings: both halves are written the same way at `fold = …` inside the full form, and the
/// sugar `<field> = <fold>` takes both too — where the fold [`owes`](Self::owed) the entry no
/// column, which is the one thing the short spelling has no seat to say.
///
/// # The SHIPPED SPELLINGS are the design's, and the house register disagrees with them
///
/// Every other closed VALUE vocabulary in this grammar is a bare short NOUN — `semantics(fold(sum))`
/// and `fold(max)`, `dedup(hash)` and `dedup(eq)`, the five tracing levels, the four execution
/// worlds — and `counting`/`summing` are the first gerunds in it. The design law one grammar over
/// (*a key names the KIND of the value it takes*; same kind, different reach, one word) would make
/// this position's word for a total `sum`, which is the word `semantics(fold(…))` already spells a
/// fold with.
///
/// The names stand as the closed design wrote them: the design reserved the BLOCK word for the
/// grammar task's census and named these two itself, and the fold seam that mints the citizens is
/// its own task. The measurement is recorded here rather than acted on, and it is one line to act
/// on — [`SHIPPED`](Self::SHIPPED) and [`shipped`](Self::shipped) are the whole of it.
/// WHETHER A FOLD OWES ITS ENTRY A COLUMN — the axis the `from` seat is checked against.
///
/// # It exists because the framework's knowledge of a fold is the SHIPPED half and stops there
///
/// A word this crate ships is a fold this crate wrote, so what it reads is a fact rather than a
/// guess: `counting` answers how many rows there are and looks at none of them, `summing` adds up
/// one column's values. Those two facts are what let the grammar refuse a `counting` that names a
/// column and a `summing` that names none — one mistake apiece, caught at the declaration rather
/// than at a fold handed the wrong slice.
///
/// A QUOTED path is a type this crate never saw. Refusing it either way would be the framework
/// deciding on the declaring crate's behalf, so the third answer says so and neither refusal fires.
pub use Mounted;