Skip to content

Commit 4c990b4

Browse files
authored
fix: cast must cast its stats too (#5386)
Fixes #5385. On develop: ``` thread 'tests::issue_5385_filter_casted_column' panicked at vortex-file/src/tests.rs:456:10: called `Result::unwrap()` on an `Err` value: Cannot compare different DTypes u8? and u16 Backtrace: disabled backtrace note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` Signed-off-by: Daniel King <[email protected]>
1 parent 34a6ac1 commit 4c990b4

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

vortex-array/src/expr/exprs/cast.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,27 @@ impl VTable for Cast {
9191
expr: &ExpressionView<Self>,
9292
catalog: &mut dyn StatsCatalog,
9393
) -> Option<Expression> {
94-
expr.children()[0].stat_max(catalog)
94+
expr.child(0)
95+
.stat_max(catalog)
96+
.map(|x| cast(x, expr.data().clone()))
9597
}
9698

9799
fn stat_min(
98100
&self,
99101
expr: &ExpressionView<Self>,
100102
catalog: &mut dyn StatsCatalog,
101103
) -> Option<Expression> {
102-
expr.children()[0].stat_min(catalog)
104+
expr.child(0)
105+
.stat_min(catalog)
106+
.map(|x| cast(x, expr.data().clone()))
103107
}
104108

105109
fn stat_nan_count(
106110
&self,
107111
expr: &ExpressionView<Self>,
108112
catalog: &mut dyn StatsCatalog,
109113
) -> Option<Expression> {
110-
expr.children()[0].stat_nan_count(catalog)
114+
expr.child(0).stat_nan_count(catalog)
111115
}
112116

113117
fn stat_field_path(&self, expr: &ExpressionView<Self>) -> Option<FieldPath> {

vortex-file/src/tests.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use vortex_array::arrays::{
1414
StructArray, VarBinArray, VarBinViewArray,
1515
};
1616
use vortex_array::expr::{
17-
Pack, PackOptions, VTableExt, and, eq, get_item, gt, gt_eq, lit, lt, lt_eq, or, root, select,
17+
Pack, PackOptions, VTableExt, and, cast, eq, get_item, gt, gt_eq, lit, lt, lt_eq, or, root,
18+
select,
1819
};
1920
use vortex_array::stats::PRUNING_STATS;
2021
use vortex_array::stream::{ArrayStreamAdapter, ArrayStreamExt};
@@ -421,6 +422,45 @@ async fn test_empty_varbin_array_roundtrip() {
421422
assert_eq!(result.dtype(), st.dtype());
422423
}
423424

425+
#[tokio::test]
426+
#[cfg_attr(miri, ignore)]
427+
async fn issue_5385_filter_casted_column() {
428+
let array = StructArray::try_from_iter([("x", buffer![1u8, 2, 3, 4, 5])])
429+
.unwrap()
430+
.into_array();
431+
432+
let mut buf = ByteBufferMut::empty();
433+
SESSION
434+
.write_options()
435+
.write(&mut buf, array.to_array_stream())
436+
.await
437+
.unwrap();
438+
439+
let result = SESSION
440+
.open_options()
441+
.open_buffer(buf)
442+
.unwrap()
443+
.scan()
444+
.unwrap()
445+
.with_filter(eq(
446+
cast(
447+
get_item("x", root()),
448+
DType::Primitive(PType::U16, Nullability::NonNullable),
449+
),
450+
lit(1u16),
451+
))
452+
.into_array_stream()
453+
.unwrap()
454+
.read_all()
455+
.await
456+
.unwrap();
457+
458+
assert_arrays_eq!(
459+
result,
460+
StructArray::try_from_iter([("x", buffer![1u8])]).unwrap()
461+
);
462+
}
463+
424464
#[tokio::test]
425465
#[cfg_attr(miri, ignore)]
426466
async fn filter_string() {

0 commit comments

Comments
 (0)