vortex_array/arrays/primitive/vtable/
pipeline.rs1use std::any::Any;
7use std::fmt::Formatter;
8use std::hash::{Hash, Hasher};
9use std::sync::Arc;
10
11use vortex_dtype::DType;
12use vortex_error::VortexResult;
13
14use crate::Canonical;
15use crate::arrays::{PrimitiveArray, PrimitiveVTable};
16use crate::operator::canonical::CanonicalExecution;
17use crate::operator::{
18 BatchBindCtx, BatchExecutionRef, BatchOperator, DisplayFormat, LengthBounds, Operator,
19 OperatorEq, OperatorHash, OperatorId, OperatorRef,
20};
21use crate::vtable::PipelineVTable;
22
23impl PipelineVTable<PrimitiveVTable> for PrimitiveVTable {
24 fn to_operator(array: &PrimitiveArray) -> VortexResult<Option<OperatorRef>> {
25 Ok(Some(Arc::new(array.clone())))
26 }
27}
28
29impl OperatorHash for PrimitiveArray {
30 fn operator_hash<H: Hasher>(&self, state: &mut H) {
31 self.dtype.hash(state);
32 self.buffer.operator_hash(state);
33 self.validity.operator_hash(state);
34 }
35}
36
37impl OperatorEq for PrimitiveArray {
38 fn operator_eq(&self, other: &Self) -> bool {
39 self.dtype == other.dtype
40 && self.buffer.operator_eq(&other.buffer)
41 && self.validity.operator_eq(&other.validity)
42 }
43}
44
45impl Operator for PrimitiveArray {
46 fn id(&self) -> OperatorId {
47 self.encoding_id()
48 }
49
50 fn as_any(&self) -> &dyn Any {
51 self
52 }
53
54 fn dtype(&self) -> &DType {
55 &self.dtype
56 }
57
58 fn bounds(&self) -> LengthBounds {
59 LengthBounds::from(self.buffer.len() / self.dtype.as_ptype().byte_width())
60 }
61
62 fn children(&self) -> &[OperatorRef] {
63 &[]
64 }
65
66 fn fmt_as(&self, _df: DisplayFormat, f: &mut Formatter) -> std::fmt::Result {
67 write!(f, "PrimitiveArray(ptype={})", self.ptype())
68 }
69
70 fn with_children(self: Arc<Self>, _children: Vec<OperatorRef>) -> VortexResult<OperatorRef> {
71 Ok(self)
72 }
73
74 fn as_batch(&self) -> Option<&dyn BatchOperator> {
75 Some(self)
76 }
77}
78
79impl BatchOperator for PrimitiveArray {
80 fn bind(&self, _ctx: &mut dyn BatchBindCtx) -> VortexResult<BatchExecutionRef> {
81 Ok(Box::new(CanonicalExecution(Canonical::Primitive(
82 self.clone(),
83 ))))
84 }
85}