Skip to content

Commit a201670

Browse files
committed
wip datetimeparts fixes
Signed-off-by: Joe Isaacs <[email protected]>
1 parent c93b6a7 commit a201670

File tree

6 files changed

+92
-2
lines changed

6 files changed

+92
-2
lines changed

bench-vortex/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ tokio-stream = { workspace = true }
7373
tokio-util = { workspace = true }
7474
tpchgen = { workspace = true }
7575
tpchgen-arrow = { workspace = true }
76-
tracing = { workspace = true, features = ["max_level_debug"] }
76+
tracing = { workspace = true, features = ["max_level_trace"] }
7777
tracing-perfetto = { workspace = true }
7878
tracing-subscriber = { workspace = true, features = [
7979
"env-filter",

encodings/datetime-parts/src/array.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use vortex_array::ArrayHash;
1212
use vortex_array::ArrayRef;
1313
use vortex_array::Canonical;
1414
use vortex_array::DeserializeMetadata;
15+
use vortex_array::IntoArray;
1516
use vortex_array::Precision;
1617
use vortex_array::ProstMetadata;
1718
use vortex_array::SerializeMetadata;
@@ -40,6 +41,8 @@ use vortex_error::vortex_bail;
4041
use vortex_error::vortex_ensure;
4142
use vortex_error::vortex_err;
4243

44+
use crate::compute::rules::PARENT_RULES;
45+
4346
vtable!(DateTimeParts);
4447

4548
#[derive(Clone, prost::Message)]
@@ -159,6 +162,14 @@ impl VTable for DateTimePartsVTable {
159162

160163
Ok(())
161164
}
165+
166+
fn reduce_parent(
167+
array: &Self::Array,
168+
parent: &ArrayRef,
169+
child_idx: usize,
170+
) -> VortexResult<Option<ArrayRef>> {
171+
PARENT_RULES.evaluate(array, parent, child_idx)
172+
}
162173
}
163174

164175
#[derive(Clone, Debug)]

encodings/datetime-parts/src/compute/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod compare;
66
mod filter;
77
mod is_constant;
88
mod mask;
9+
pub(super) mod rules;
910
mod take;
1011

1112
#[cfg(test)]
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_array::ArrayRef;
5+
use vortex_array::IntoArray;
6+
use vortex_array::arrays::ConstantArray;
7+
use vortex_array::arrays::ConstantVTable;
8+
use vortex_array::arrays::FilterArray;
9+
use vortex_array::arrays::FilterVTable;
10+
use vortex_array::matchers::Exact;
11+
use vortex_array::optimizer::ArrayOptimizer;
12+
use vortex_array::optimizer::rules::ArrayParentReduceRule;
13+
use vortex_array::optimizer::rules::ParentRuleSet;
14+
use vortex_error::VortexExpect;
15+
use vortex_error::VortexResult;
16+
17+
use crate::DateTimePartsArray;
18+
use crate::DateTimePartsVTable;
19+
20+
pub(crate) const PARENT_RULES: ParentRuleSet<DateTimePartsVTable> =
21+
ParentRuleSet::new(&[ParentRuleSet::lift(&DTPFilterPushDownRule)]);
22+
23+
#[derive(Debug)]
24+
struct DTPFilterPushDownRule;
25+
26+
impl ArrayParentReduceRule<DateTimePartsVTable> for DTPFilterPushDownRule {
27+
type Parent = Exact<FilterVTable>;
28+
29+
fn parent(&self) -> Self::Parent {
30+
Exact::from(&FilterVTable)
31+
}
32+
33+
fn reduce_parent(
34+
&self,
35+
child: &DateTimePartsArray,
36+
parent: &FilterArray,
37+
child_idx: usize,
38+
) -> VortexResult<Option<ArrayRef>> {
39+
if child_idx != 0 {
40+
return Ok(None);
41+
}
42+
43+
if !child.seconds().is::<ConstantVTable>() || !child.subseconds().is::<ConstantVTable>() {
44+
return Ok(None);
45+
}
46+
47+
DateTimePartsArray::try_new(
48+
child.dtype().clone(),
49+
FilterArray::new(child.days().clone(), parent.filter_mask().clone())
50+
.into_array()
51+
.optimize()?,
52+
ConstantArray::new(
53+
child.seconds().as_constant().vortex_expect("constant"),
54+
parent.filter_mask().true_count(),
55+
)
56+
.into_array(),
57+
ConstantArray::new(
58+
child.subseconds().as_constant().vortex_expect("constant"),
59+
parent.filter_mask().true_count(),
60+
)
61+
.into_array(),
62+
)
63+
.map(|x| Some(x.into_array()))
64+
}
65+
}

vortex-array/src/expr/transform/partition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ where
7171
Nullability::NonNullable,
7272
);
7373

74-
let expr = expr.optimize_recursive(scope)?;
74+
// let expr = expr.optimize_recursive(scope)?;
7575
let expr_dtype = expr.return_dtype(scope)?;
7676

7777
partitions.push(expr);

vortex-btrblocks/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ use vortex_array::ArrayRef;
3838
use vortex_array::Canonical;
3939
use vortex_array::IntoArray;
4040
use vortex_array::ToCanonical;
41+
use vortex_array::arrays::ConstantArray;
4142
use vortex_array::arrays::ExtensionArray;
4243
use vortex_array::arrays::FixedSizeListArray;
4344
use vortex_array::arrays::ListArray;
4445
use vortex_array::arrays::StructArray;
4546
use vortex_array::arrays::TemporalArray;
4647
use vortex_array::arrays::list_from_list_view;
48+
use vortex_array::compute::Cost;
4749
use vortex_array::vtable::VTable;
4850
use vortex_array::vtable::ValidityHelper;
4951
use vortex_dtype::DType;
@@ -475,6 +477,17 @@ impl BtrBlocksCompressor {
475477
if let Ok(temporal_array) = TemporalArray::try_from(ext_array.to_array())
476478
&& let TemporalMetadata::Timestamp(..) = temporal_array.temporal_metadata()
477479
{
480+
let temporal_array_ref = temporal_array.clone().into_array();
481+
if temporal_array_ref
482+
.as_ref()
483+
.is_constant_opts(Cost::Canonicalize)
484+
{
485+
return Ok(ConstantArray::new(
486+
temporal_array_ref.scalar_at(0),
487+
ext_array.len(),
488+
)
489+
.into_array());
490+
}
478491
return compress_temporal(temporal_array);
479492
}
480493

0 commit comments

Comments
 (0)