springql_core/pipeline/pump_model/window_parameter.rs
1// This file is part of https://github.com/SpringQL/SpringQL which is licensed under MIT OR Apache-2.0. See file LICENSE-MIT or LICENSE-APACHE for full license details.
2
3use crate::stream_engine::time::SpringEventDuration;
4
5/// Window parameters
6#[derive(Clone, Eq, PartialEq, Debug)]
7pub enum WindowParameter {
8 /// Time-based sliding window
9 ///
10 /// ```text
11 /// length = 10sec, period = 5sec, allowed_delay = 0;
12 ///
13 /// pane1 | |
14 /// pane2 | |
15 /// pane3 | |
16 ///
17 /// -----------------------------------> t
18 /// :00 :05 :10 :15 :20
19 /// ```
20 TimedSlidingWindow {
21 length: SpringEventDuration,
22 period: SpringEventDuration,
23 allowed_delay: SpringEventDuration,
24 },
25
26 /// Time-based fixed window
27 ///
28 /// ```text
29 /// length = 10sec, allowed_delay = 0;
30 ///
31 /// pane1 | |
32 /// pane2 | |
33 /// pane3 | |
34 ///
35 /// -----------------------------------> t
36 /// :00 :05 :10 :15 :20
37 /// ```
38 TimedFixedWindow {
39 length: SpringEventDuration,
40 allowed_delay: SpringEventDuration,
41 },
42}
43
44impl WindowParameter {
45 pub fn length(&self) -> SpringEventDuration {
46 match self {
47 WindowParameter::TimedSlidingWindow { length, .. } => *length,
48 WindowParameter::TimedFixedWindow { length, .. } => *length,
49 }
50 }
51
52 pub fn period(&self) -> SpringEventDuration {
53 match self {
54 WindowParameter::TimedSlidingWindow { period, .. } => *period,
55 WindowParameter::TimedFixedWindow { length, .. } => *length,
56 }
57 }
58
59 pub fn allowed_delay(&self) -> SpringEventDuration {
60 match self {
61 WindowParameter::TimedSlidingWindow { allowed_delay, .. } => *allowed_delay,
62 WindowParameter::TimedFixedWindow { allowed_delay, .. } => *allowed_delay,
63 }
64 }
65}