|
1 | 1 | // SPDX-License-Identifier: Apache-2.0 |
2 | 2 | // SPDX-FileCopyrightText: Copyright the Vortex contributors |
3 | 3 |
|
4 | | -use vortex_array::compute::IsConstantKernel; |
5 | | -use vortex_array::compute::IsConstantKernelAdapter; |
6 | | -use vortex_array::compute::IsConstantOpts; |
7 | | -use vortex_array::compute::is_constant_opts; |
8 | | -use vortex_array::register_kernel; |
| 4 | +use vortex_array::ArrayRef; |
| 5 | +use vortex_array::ExecutionCtx; |
| 6 | +use vortex_array::aggregate_fn::AggregateFnRef; |
| 7 | +use vortex_array::aggregate_fn::fns::is_constant::IsConstant; |
| 8 | +use vortex_array::aggregate_fn::fns::is_constant::is_constant; |
| 9 | +use vortex_array::aggregate_fn::kernels::DynAggregateKernel; |
| 10 | +use vortex_array::scalar::Scalar; |
9 | 11 | use vortex_error::VortexResult; |
10 | 12 |
|
11 | 13 | use crate::DateTimeParts; |
12 | | -use crate::DateTimePartsArray; |
13 | 14 |
|
14 | | -impl IsConstantKernel for DateTimeParts { |
15 | | - fn is_constant( |
16 | | - &self, |
17 | | - array: &DateTimePartsArray, |
18 | | - opts: &IsConstantOpts, |
19 | | - ) -> VortexResult<Option<bool>> { |
20 | | - let Some(days) = is_constant_opts(array.days(), opts)? else { |
21 | | - return Ok(None); |
22 | | - }; |
23 | | - if !days { |
24 | | - return Ok(Some(false)); |
25 | | - } |
| 15 | +/// DateTimeParts-specific is_constant kernel. |
| 16 | +/// |
| 17 | +/// Checks each component (days, seconds, subseconds) individually. |
| 18 | +#[derive(Debug)] |
| 19 | +pub(crate) struct DateTimePartsIsConstantKernel; |
26 | 20 |
|
27 | | - let Some(seconds) = is_constant_opts(array.seconds(), opts)? else { |
| 21 | +impl DynAggregateKernel for DateTimePartsIsConstantKernel { |
| 22 | + fn aggregate( |
| 23 | + &self, |
| 24 | + aggregate_fn: &AggregateFnRef, |
| 25 | + batch: &ArrayRef, |
| 26 | + ctx: &mut ExecutionCtx, |
| 27 | + ) -> VortexResult<Option<Scalar>> { |
| 28 | + if !aggregate_fn.is::<IsConstant>() { |
28 | 29 | return Ok(None); |
29 | | - }; |
30 | | - if !seconds { |
31 | | - return Ok(Some(false)); |
32 | 30 | } |
33 | 31 |
|
34 | | - let Some(subseconds) = is_constant_opts(array.subseconds(), opts)? else { |
| 32 | + let Some(array) = batch.as_opt::<DateTimeParts>() else { |
35 | 33 | return Ok(None); |
36 | 34 | }; |
37 | | - if !subseconds { |
38 | | - return Ok(Some(false)); |
39 | | - } |
40 | 35 |
|
41 | | - Ok(Some(true)) |
| 36 | + let result = is_constant(array.days(), ctx)? |
| 37 | + && is_constant(array.seconds(), ctx)? |
| 38 | + && is_constant(array.subseconds(), ctx)?; |
| 39 | + Ok(Some(IsConstant::make_partial(batch, result)?)) |
42 | 40 | } |
43 | 41 | } |
44 | | - |
45 | | -register_kernel!(IsConstantKernelAdapter(DateTimeParts).lift()); |
0 commit comments