|
1 | 1 | // SPDX-License-Identifier: Apache-2.0 |
2 | 2 | // SPDX-FileCopyrightText: Copyright the Vortex contributors |
3 | 3 |
|
| 4 | +use std::fmt::Debug; |
| 5 | + |
4 | 6 | use vortex_buffer::BufferHandle; |
5 | 7 | use vortex_dtype::DType; |
6 | 8 | use vortex_error::VortexResult; |
7 | 9 | use vortex_error::vortex_bail; |
| 10 | +use vortex_error::vortex_ensure; |
| 11 | +use vortex_mask::Mask; |
8 | 12 | use vortex_scalar::Scalar; |
9 | 13 | use vortex_scalar::ScalarValue; |
10 | 14 | use vortex_vector::ScalarOps; |
| 15 | +use vortex_vector::Vector; |
11 | 16 | use vortex_vector::VectorMutOps; |
12 | 17 |
|
13 | 18 | use crate::EmptyMetadata; |
14 | 19 | use crate::arrays::ConstantArray; |
15 | 20 | use crate::kernel::BindCtx; |
| 21 | +use crate::kernel::Kernel; |
16 | 22 | use crate::kernel::KernelRef; |
17 | | -use crate::kernel::kernel; |
| 23 | +use crate::kernel::PushDownResult; |
18 | 24 | use crate::serde::ArrayChildren; |
19 | 25 | use crate::vtable; |
20 | 26 | use crate::vtable::ArrayId; |
@@ -87,8 +93,29 @@ impl VTable for ConstantVTable { |
87 | 93 | } |
88 | 94 |
|
89 | 95 | fn bind_kernel(array: &Self::Array, _ctx: &mut BindCtx) -> VortexResult<KernelRef> { |
90 | | - let scalar = array.scalar().to_vector_scalar(); |
91 | | - let len = array.len(); |
92 | | - Ok(kernel(move || Ok(scalar.clone().repeat(len).freeze()))) |
| 96 | + Ok(Box::new(ConstantKernel { |
| 97 | + value: array.scalar.to_vector_scalar(), |
| 98 | + len: array.len, |
| 99 | + })) |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +#[derive(Debug)] |
| 104 | +struct ConstantKernel { |
| 105 | + value: vortex_vector::Scalar, |
| 106 | + len: usize, |
| 107 | +} |
| 108 | + |
| 109 | +impl Kernel for ConstantKernel { |
| 110 | + fn execute(self: Box<Self>) -> VortexResult<Vector> { |
| 111 | + Ok(self.value.repeat(self.len).freeze()) |
| 112 | + } |
| 113 | + |
| 114 | + fn push_down_filter(self: Box<Self>, selection: &Mask) -> VortexResult<PushDownResult> { |
| 115 | + vortex_ensure!(self.len == selection.len()); |
| 116 | + Ok(PushDownResult::Pushed(Box::new(ConstantKernel { |
| 117 | + value: self.value, |
| 118 | + len: selection.true_count(), |
| 119 | + }))) |
93 | 120 | } |
94 | 121 | } |
0 commit comments