rudb_exec/operator.rs
1//! The one interface every operator has.
2
3use std::fmt;
4
5use rudb_common::Result;
6use rudb_vector::Chunk;
7
8use crate::schema::Schema;
9
10/// A source of chunks.
11///
12/// Two methods, and the reason there are only two is that everything else an operator could be
13/// asked is either a property of its schema or a property of the plan it came from. An operator
14/// that needed a third method to be driven would be an operator the scheduler has to know the shape
15/// of, and section 7.2's morsel driven scheduler is supposed to know only that a pipeline has a
16/// source, some streaming operators and a sink.
17///
18/// `next` returning `Some` with an empty chunk is allowed and means nothing more than that this
19/// call produced no rows, which is what a filter that rejected a whole batch does. Only `None`
20/// means the operator is finished. Calling `next` again after `None` returns `None` again for every
21/// operator here, which is what makes a driver loop safe to write as a `while let`.
22pub trait Operator: fmt::Debug {
23 /// The columns this operator produces.
24 fn schema(&self) -> &Schema;
25
26 /// The next batch, or `None` when there are no more.
27 ///
28 /// # Errors
29 ///
30 /// Anything an expression, a cast or a kernel reports, carrying the message the user sees.
31 fn next(&mut self) -> Result<Option<Chunk>>;
32}