quill_sql/execution/physical_plan/
empty.rs1use crate::catalog::SchemaRef;
2use crate::execution::{ExecutionContext, VolcanoExecutor};
3use crate::{error::QuillSQLResult, storage::tuple::Tuple};
4use std::sync::atomic::{AtomicUsize, Ordering};
5
6#[derive(Debug)]
7pub struct PhysicalEmpty {
8 pub produce_row_count: usize,
9 pub schema: SchemaRef,
10 outputted_count: AtomicUsize,
11}
12
13impl PhysicalEmpty {
14 pub fn new(produce_row_count: usize, schema: SchemaRef) -> Self {
15 Self {
16 produce_row_count,
17 schema,
18 outputted_count: AtomicUsize::new(0),
19 }
20 }
21}
22
23impl VolcanoExecutor for PhysicalEmpty {
24 fn init(&self, _context: &mut ExecutionContext) -> QuillSQLResult<()> {
25 self.outputted_count.store(0, Ordering::SeqCst);
26 Ok(())
27 }
28 fn next(&self, _context: &mut ExecutionContext) -> QuillSQLResult<Option<Tuple>> {
29 if self.outputted_count.fetch_add(1, Ordering::SeqCst) < self.produce_row_count {
30 Ok(Some(Tuple::new(self.schema.clone(), vec![])))
31 } else {
32 Ok(None)
33 }
34 }
35
36 fn output_schema(&self) -> SchemaRef {
37 self.schema.clone()
38 }
39}
40
41impl std::fmt::Display for PhysicalEmpty {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 write!(f, "Empty")
44 }
45}