polars_pipe/operators/
sink.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::any::Any;
use std::fmt::{Debug, Formatter};

use polars_utils::arena::Node;

use super::*;

#[derive(Debug)]
pub enum SinkResult {
    Finished,
    CanHaveMoreInput,
}

pub enum FinalizedSink {
    Finished(DataFrame),
    Operator,
    Source(Box<dyn Source>),
}

impl Debug for FinalizedSink {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        let s = match self {
            FinalizedSink::Finished(_) => "finished",
            FinalizedSink::Operator => "operator",
            FinalizedSink::Source(_) => "source",
        };
        write!(f, "{s}")
    }
}

pub trait Sink: Send + Sync {
    fn sink(&mut self, context: &PExecutionContext, chunk: DataChunk) -> PolarsResult<SinkResult>;

    fn combine(&mut self, other: &mut dyn Sink);

    fn split(&self, thread_no: usize) -> Box<dyn Sink>;

    fn finalize(&mut self, context: &PExecutionContext) -> PolarsResult<FinalizedSink>;

    fn as_any(&mut self) -> &mut dyn Any;

    fn fmt(&self) -> &str;

    fn is_join_build(&self) -> bool {
        false
    }

    // Only implemented for Join sinks
    fn node(&self) -> Node {
        unimplemented!()
    }
}