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::sync::Arc;
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
23pub type OperatorRef = Arc<dyn Operator>;
24
25/// An operator represents a node in a logical query plan.
26pub trait Operator: Debug + DynHash + Send + Sync + 'static {
27 fn as_any(&self) -> &dyn Any;
28
29 /// The output [`VType`] of this operator.
30 fn vtype(&self) -> VType;
31
32 /// The children of this operator.
33 fn children(&self) -> &[OperatorRef];
34
35 fn with_children(&self, children: Vec<OperatorRef>) -> OperatorRef;
36
37 /// Whether this operator works by mutating its first child in-place.
38 ///
39 /// If `true`, the operator is invoked with the first child's input data passed via the
40 /// mutable output view. The node is expected to mutate this data in-place.
41 fn in_place(&self) -> bool {
42 false
43 }
44
45 /// Create a kernel for this operator
46 fn bind(&self, ctx: &dyn BindContext) -> VortexResult<Box<dyn Kernel>>;
47
48 /// Operator reduction optimization examples:
49 ///
50 /// Step 1 - Initial pipeline:
51 /// compare(_, 12) <- for(ref=10) <- bitpacked
52 ///
53 /// Step 2 - reduce_children optimization:
54 /// compare_scalar(12-10=2) <- bitpacked
55 ///
56 /// Step 3 - Final optimized pipeline (reduce_parent):
57 /// bitpacked -> compare_scalar(2)
58 ///
59 /// The reduction process eliminates the FoR decoding step by adjusting
60 /// the comparison constant to work directly on encoded values.
61 /// Given a set of reduced children, try and reduce the current node.
62 /// If Keep is returned then the children of this node as still updated.
63 fn reduce_children(&self, children: &[OperatorRef]) -> Option<OperatorRef> {
64 None
65 }
66
67 /// Given a reduced parent, try and reduce the current node.
68 /// If `Replace` is returned then the parent node and this node and replaced by the returned node.
69 fn reduce_parent(&self, parent: OperatorRef) -> Option<OperatorRef> {
70 None
71 }
72}
73
74dyn_hash::hash_trait_object!(Operator);
75
76/// The context used when binding an operator for execution.
77pub trait BindContext {
78 fn children(&self) -> &[VectorId];
79}