1use reifydb_value::{util::hash::Hash128, value::row_number::RowNumber};
5
6use crate::{
7 key::{
8 operator::{
9 state::{GroupId, KeyspaceId},
10 traits::Keyspace,
11 },
12 typed::{
13 BoundedKey, DenseKey, KeyLayout,
14 direction::{Asc, Desc, Direction, KeyField},
15 layout::{KeyColumn, KeyColumnType, KeyLayout, KeyValue, KeyValues},
16 },
17 },
18 metrics::heap::HeapSize,
19};
20
21#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
22pub struct AccumulatorKey {
23 pub group: Desc<GroupId>,
24}
25
26#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
27pub struct BufferKey {
28 pub group: Desc<GroupId>,
29}
30
31#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
32pub struct RunningKey {
33 pub group: Desc<GroupId>,
34}
35
36#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
37pub struct CountKey {
38 pub group: Desc<GroupId>,
39}
40
41#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
42pub struct SessionKey {
43 pub group: Desc<GroupId>,
44}
45
46#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
47pub struct RollingMetaKey {
48 pub group: Desc<GroupId>,
49}
50
51#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
52pub struct EngineMetaKey {
53 pub group: Desc<GroupId>,
54}
55
56#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
57pub struct EmitKey {
58 pub group: Desc<GroupId>,
59 pub row: Asc<RowNumber>,
60}
61
62#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
63pub struct RowIndexKey {
64 pub group: Desc<GroupId>,
65 pub row: Asc<RowNumber>,
66}
67
68#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
69pub struct WindowMetaKey {
70 pub group: Desc<GroupId>,
71 pub window: Desc<Hash128>,
72}
73
74#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
75pub struct WindowMetaSuffix {
76 pub window: Desc<Hash128>,
77}
78
79#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
80pub struct GuestAccumulatorKey {
81 pub group: Desc<GroupId>,
82 pub slot: Asc<[u8; 16]>,
83}
84
85#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
86pub struct GuestBufferKey {
87 pub group: Desc<GroupId>,
88 pub slot: Asc<[u8; 16]>,
89}
90
91#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
92pub struct GuestRunningKey {
93 pub group: Desc<GroupId>,
94 pub slot: Asc<[u8; 16]>,
95}
96
97#[derive(Clone, Copy, Debug, PartialEq, Eq)]
98pub struct Accumulator;
99
100impl Keyspace for Accumulator {
101 const ID: KeyspaceId = KeyspaceId::ACCUMULATOR;
102 const NAME: &'static str = "ACCUMULATOR";
103 const RANGE_CACHED: bool = true;
104
105 type GroupedKey = AccumulatorKey;
106 type Suffix = ();
107
108 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
109 (key.group.0, ())
110 }
111
112 fn join(group: GroupId, _suffix: Self::Suffix) -> Self::GroupedKey {
113 AccumulatorKey {
114 group: Desc(group),
115 }
116 }
117}
118
119#[derive(Clone, Copy, Debug, PartialEq, Eq)]
120pub struct Buffer;
121
122impl Keyspace for Buffer {
123 const ID: KeyspaceId = KeyspaceId::BUFFER;
124 const NAME: &'static str = "BUFFER";
125 const RANGE_CACHED: bool = true;
126
127 type GroupedKey = BufferKey;
128 type Suffix = ();
129
130 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
131 (key.group.0, ())
132 }
133
134 fn join(group: GroupId, _suffix: Self::Suffix) -> Self::GroupedKey {
135 BufferKey {
136 group: Desc(group),
137 }
138 }
139}
140
141#[derive(Clone, Copy, Debug, PartialEq, Eq)]
142pub struct Running;
143
144impl Keyspace for Running {
145 const ID: KeyspaceId = KeyspaceId::RUNNING;
146 const NAME: &'static str = "RUNNING";
147 const RANGE_CACHED: bool = true;
148
149 type GroupedKey = RunningKey;
150 type Suffix = ();
151
152 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
153 (key.group.0, ())
154 }
155
156 fn join(group: GroupId, _suffix: Self::Suffix) -> Self::GroupedKey {
157 RunningKey {
158 group: Desc(group),
159 }
160 }
161}
162
163#[derive(Clone, Copy, Debug, PartialEq, Eq)]
164pub struct Count;
165
166impl Keyspace for Count {
167 const ID: KeyspaceId = KeyspaceId::COUNT;
168 const NAME: &'static str = "COUNT";
169 const RANGE_CACHED: bool = true;
170
171 type GroupedKey = CountKey;
172 type Suffix = ();
173
174 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
175 (key.group.0, ())
176 }
177
178 fn join(group: GroupId, _suffix: Self::Suffix) -> Self::GroupedKey {
179 CountKey {
180 group: Desc(group),
181 }
182 }
183}
184
185#[derive(Clone, Copy, Debug, PartialEq, Eq)]
186pub struct Session;
187
188impl Keyspace for Session {
189 const ID: KeyspaceId = KeyspaceId::SESSION;
190 const NAME: &'static str = "SESSION";
191 const RANGE_CACHED: bool = true;
192
193 type GroupedKey = SessionKey;
194 type Suffix = ();
195
196 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
197 (key.group.0, ())
198 }
199
200 fn join(group: GroupId, _suffix: Self::Suffix) -> Self::GroupedKey {
201 SessionKey {
202 group: Desc(group),
203 }
204 }
205}
206
207#[derive(Clone, Copy, Debug, PartialEq, Eq)]
208pub struct RollingMeta;
209
210impl Keyspace for RollingMeta {
211 const ID: KeyspaceId = KeyspaceId::ROLLING_META;
212 const NAME: &'static str = "ROLLING_META";
213 const RANGE_CACHED: bool = true;
214
215 type GroupedKey = RollingMetaKey;
216 type Suffix = ();
217
218 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
219 (key.group.0, ())
220 }
221
222 fn join(group: GroupId, _suffix: Self::Suffix) -> Self::GroupedKey {
223 RollingMetaKey {
224 group: Desc(group),
225 }
226 }
227}
228
229#[derive(Clone, Copy, Debug, PartialEq, Eq)]
230pub struct EngineMeta;
231
232impl Keyspace for EngineMeta {
233 const ID: KeyspaceId = KeyspaceId::ENGINE_META;
234 const NAME: &'static str = "ENGINE_META";
235 const RANGE_CACHED: bool = true;
236
237 type GroupedKey = EngineMetaKey;
238 type Suffix = ();
239
240 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
241 (key.group.0, ())
242 }
243
244 fn join(group: GroupId, _suffix: Self::Suffix) -> Self::GroupedKey {
245 EngineMetaKey {
246 group: Desc(group),
247 }
248 }
249}
250
251#[derive(Clone, Copy, Debug, PartialEq, Eq)]
252pub struct Emit;
253
254impl Keyspace for Emit {
255 const ID: KeyspaceId = KeyspaceId::EMIT;
256 const NAME: &'static str = "EMIT";
257 const RANGE_CACHED: bool = true;
258
259 type GroupedKey = EmitKey;
260 type Suffix = Asc<RowNumber>;
261
262 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
263 (key.group.0, key.row)
264 }
265
266 fn join(group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
267 EmitKey {
268 group: Desc(group),
269 row: suffix,
270 }
271 }
272}
273
274#[derive(Clone, Copy, Debug, PartialEq, Eq)]
275pub struct RowIndex;
276
277impl Keyspace for RowIndex {
278 const ID: KeyspaceId = KeyspaceId::ROW_INDEX;
279 const NAME: &'static str = "ROW_INDEX";
280 const RANGE_CACHED: bool = true;
281
282 type GroupedKey = RowIndexKey;
283 type Suffix = Asc<RowNumber>;
284
285 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
286 (key.group.0, key.row)
287 }
288
289 fn join(group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
290 RowIndexKey {
291 group: Desc(group),
292 row: suffix,
293 }
294 }
295}
296
297#[derive(Clone, Copy, Debug, PartialEq, Eq)]
298pub struct WindowMeta;
299
300impl Keyspace for WindowMeta {
301 const ID: KeyspaceId = KeyspaceId::WINDOW_META;
302 const NAME: &'static str = "WINDOW_META";
303 const RANGE_CACHED: bool = true;
304
305 type GroupedKey = WindowMetaKey;
306 type Suffix = WindowMetaSuffix;
307
308 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
309 (
310 key.group.0,
311 WindowMetaSuffix {
312 window: key.window,
313 },
314 )
315 }
316
317 fn join(group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
318 WindowMetaKey {
319 group: Desc(group),
320 window: suffix.window,
321 }
322 }
323}
324
325#[derive(Clone, Copy, Debug, PartialEq, Eq)]
326pub struct GuestAccumulator;
327
328impl Keyspace for GuestAccumulator {
329 const ID: KeyspaceId = KeyspaceId::GUEST_ACCUMULATOR;
330 const NAME: &'static str = "GUEST_ACCUMULATOR";
331 const RANGE_CACHED: bool = true;
332
333 type GroupedKey = GuestAccumulatorKey;
334 type Suffix = Asc<[u8; 16]>;
335
336 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
337 (key.group.0, key.slot)
338 }
339
340 fn join(group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
341 GuestAccumulatorKey {
342 group: Desc(group),
343 slot: suffix,
344 }
345 }
346}
347
348#[derive(Clone, Copy, Debug, PartialEq, Eq)]
349pub struct GuestBuffer;
350
351impl Keyspace for GuestBuffer {
352 const ID: KeyspaceId = KeyspaceId::GUEST_BUFFER;
353 const NAME: &'static str = "GUEST_BUFFER";
354 const RANGE_CACHED: bool = true;
355
356 type GroupedKey = GuestBufferKey;
357 type Suffix = Asc<[u8; 16]>;
358
359 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
360 (key.group.0, key.slot)
361 }
362
363 fn join(group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
364 GuestBufferKey {
365 group: Desc(group),
366 slot: suffix,
367 }
368 }
369}
370
371#[derive(Clone, Copy, Debug, PartialEq, Eq)]
372pub struct GuestRunning;
373
374impl Keyspace for GuestRunning {
375 const ID: KeyspaceId = KeyspaceId::GUEST_RUNNING;
376 const NAME: &'static str = "GUEST_RUNNING";
377 const RANGE_CACHED: bool = true;
378
379 type GroupedKey = GuestRunningKey;
380 type Suffix = Asc<[u8; 16]>;
381
382 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
383 (key.group.0, key.slot)
384 }
385
386 fn join(group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
387 GuestRunningKey {
388 group: Desc(group),
389 slot: suffix,
390 }
391 }
392}