grafeo_core/execution/operators/
single_row.rs1use super::{Operator, OperatorResult};
7use crate::execution::DataChunk;
8
9pub struct SingleRowOperator {
14 produced: bool,
16}
17
18impl SingleRowOperator {
19 #[must_use]
21 pub fn new() -> Self {
22 Self { produced: false }
23 }
24}
25
26impl Default for SingleRowOperator {
27 fn default() -> Self {
28 Self::new()
29 }
30}
31
32impl Operator for SingleRowOperator {
33 fn next(&mut self) -> OperatorResult {
34 if self.produced {
35 return Ok(None);
36 }
37
38 self.produced = true;
39
40 let mut chunk = DataChunk::with_capacity(&[], 1);
42 chunk.set_count(1);
43
44 Ok(Some(chunk))
45 }
46
47 fn reset(&mut self) {
48 self.produced = false;
49 }
50
51 fn name(&self) -> &'static str {
52 "SingleRow"
53 }
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_single_row_operator() {
62 let mut op = SingleRowOperator::new();
63
64 let chunk = op.next().unwrap();
66 assert!(chunk.is_some());
67 let chunk = chunk.unwrap();
68 assert_eq!(chunk.row_count(), 1);
69
70 let chunk = op.next().unwrap();
72 assert!(chunk.is_none());
73
74 op.reset();
76 let chunk = op.next().unwrap();
77 assert!(chunk.is_some());
78 }
79}