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