reifydb_flow/window/engine/
config.rs1use crate::window::{
5 engine::KeyspaceFamily,
6 span::{SlotSpan, WindowAnchor},
7};
8
9pub const DEFAULT_EXPIRE_BATCH: usize = 256;
10
11#[derive(Clone)]
12pub struct WindowEngineConfig {
13 expire_batch: usize,
14 family: KeyspaceFamily,
15}
16
17impl WindowEngineConfig {
18 pub fn builder() -> WindowEngineConfigBuilder {
19 WindowEngineConfigBuilder::new()
20 }
21
22 pub fn expire_batch(&self) -> usize {
23 self.expire_batch
24 }
25
26 pub fn family(&self) -> KeyspaceFamily {
27 self.family
28 }
29}
30
31pub struct WindowEngineConfigBuilder {
32 expire_batch: usize,
33 family: KeyspaceFamily,
34}
35
36impl WindowEngineConfigBuilder {
37 fn new() -> Self {
38 Self {
39 expire_batch: DEFAULT_EXPIRE_BATCH,
40 family: KeyspaceFamily::Host,
41 }
42 }
43
44 pub fn expire_batch(mut self, batch: usize) -> Self {
45 self.expire_batch = batch;
46 self
47 }
48
49 pub fn family(mut self, family: KeyspaceFamily) -> Self {
50 self.family = family;
51 self
52 }
53
54 pub fn build(self) -> WindowEngineConfig {
55 WindowEngineConfig {
56 expire_batch: self.expire_batch,
57 family: self.family,
58 }
59 }
60}
61
62pub struct TumblingCarryConfig<S: WindowAnchor> {
63 base: WindowEngineConfig,
64 retention: Option<SlotSpan<S>>,
65}
66
67impl<S: WindowAnchor> TumblingCarryConfig<S> {
68 pub fn builder(base: WindowEngineConfig) -> TumblingCarryConfigBuilder<S> {
69 TumblingCarryConfigBuilder::new(base)
70 }
71
72 pub fn base(&self) -> WindowEngineConfig {
73 self.base.clone()
74 }
75
76 pub fn retention(&self) -> Option<SlotSpan<S>> {
77 self.retention
78 }
79}
80
81pub struct TumblingCarryConfigBuilder<S: WindowAnchor> {
82 base: WindowEngineConfig,
83 retention: Option<SlotSpan<S>>,
84}
85
86impl<S: WindowAnchor> TumblingCarryConfigBuilder<S> {
87 fn new(base: WindowEngineConfig) -> Self {
88 Self {
89 base,
90 retention: None,
91 }
92 }
93
94 pub fn retention(mut self, retention: Option<SlotSpan<S>>) -> Self {
95 self.retention = retention;
96 self
97 }
98
99 pub fn build(self) -> TumblingCarryConfig<S> {
100 TumblingCarryConfig {
101 base: self.base,
102 retention: self.retention,
103 }
104 }
105}
106
107#[cfg(test)]
108mod tests {
109 use reifydb_value::value::datetime::DateTime;
110
111 use super::*;
112
113 #[test]
114 fn the_expire_batch_defaults_and_survives_an_override() {
115 assert_eq!(WindowEngineConfig::builder().build().expire_batch(), DEFAULT_EXPIRE_BATCH);
117 assert_eq!(WindowEngineConfig::builder().expire_batch(9).build().expire_batch(), 9);
118 }
119
120 #[test]
121 fn a_carry_config_forwards_its_base() {
122 let config: TumblingCarryConfig<DateTime> =
123 TumblingCarryConfig::builder(WindowEngineConfig::builder().expire_batch(7).build())
124 .retention(None)
125 .build();
126
127 assert_eq!(config.base().expire_batch(), 7, "the carry config must not detach a fresh base");
128 }
129}