vortex_array/pipeline/operators/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4//! Plan nodes represent the logical structure of a pipeline.
5
6pub mod binary_bool;
7mod compare;
8mod scalar_compare;
9
10use std::any::Any;
11use std::fmt::Debug;
12use std::rc::Rc;
13
14pub use compare::CompareOperator;
15use dyn_hash::DynHash;
16pub use scalar_compare::ScalarCompareOperator;
17use vortex_error::VortexResult;
18
19use crate::pipeline::Kernel;
20use crate::pipeline::types::VType;
21use crate::pipeline::vec::VectorId;
22
23/// An operator represents a node in a logical query plan.
24pub trait Operator: Debug + DynHash + 'static {
25 fn as_any(&self) -> &dyn Any;
26
27 /// The output [`VType`] of this operator.
28 fn vtype(&self) -> VType;
29
30 /// The children of this operator.
31 fn children(&self) -> &[Rc<dyn Operator>];
32
33 fn with_children(&self, children: Vec<Rc<dyn Operator>>) -> Rc<dyn Operator>;
34
35 /// Whether this operator works by mutating its first child in-place.
36 ///
37 /// If `true`, the operator is invoked with the first child's input data passed via the
38 /// mutable output view. The node is expected to mutate this data in-place.
39 fn in_place(&self) -> bool {
40 false
41 }
42
43 /// Create a kernel for this operator
44 fn bind(&self, ctx: &dyn BindContext) -> VortexResult<Box<dyn Kernel>>;
45
46 /// Operator reduction optimization examples:
47 ///
48 /// Step 1 - Initial pipeline:
49 /// compare(_, 12) <- for(ref=10) <- bitpacked
50 ///
51 /// Step 2 - reduce_children optimization:
52 /// compare_scalar(12-10=2) <- bitpacked
53 ///
54 /// Step 3 - Final optimized pipeline (reduce_parent):
55 /// bitpacked -> compare_scalar(2)
56 ///
57 /// The reduction process eliminates the FoR decoding step by adjusting
58 /// the comparison constant to work directly on encoded values.
59 /// Given a set of reduced children, try and reduce the current node.
60 /// If Keep is returned then the children of this node as still updated.
61 fn reduce_children(&self, children: &[Rc<dyn Operator>]) -> Option<Rc<dyn Operator>> {
62 None
63 }
64
65 /// Given a reduced parent, try and reduce the current node.
66 /// If `Replace` is returned then the parent node and this node and replaced by the returned node.
67 fn reduce_parent(&self, parent: Rc<dyn Operator>) -> Option<Rc<dyn Operator>> {
68 None
69 }
70}
71
72dyn_hash::hash_trait_object!(Operator);
73
74/// The context used when binding an operator for execution.
75pub trait BindContext {
76 fn children(&self) -> &[VectorId];
77}