@@ -5,14 +5,15 @@ use std::fmt::Formatter;
55use std:: ops:: Deref ;
66
77use prost:: Message ;
8- use vortex_dtype:: { DType , FieldPath } ;
9- use vortex_error:: { vortex_bail , vortex_err , VortexExpect , VortexResult } ;
8+ use vortex_dtype:: DType ;
9+ use vortex_error:: { VortexExpect , VortexResult , vortex_bail , vortex_err } ;
1010use vortex_proto:: expr as pb;
1111
12+ use crate :: ArrayRef ;
1213use crate :: compute:: cast as compute_cast;
1314use crate :: expr:: expression:: Expression ;
1415use crate :: expr:: { ChildName , ExprId , ExpressionView , StatsCatalog , VTable , VTableExt } ;
15- use crate :: ArrayRef ;
16+ use crate :: stats :: Stat ;
1617
1718/// A cast expression that converts values to a target data type.
1819pub struct Cast ;
@@ -86,32 +87,32 @@ impl VTable for Cast {
8687 } )
8788 }
8889
89- fn stat_max (
90- & self ,
91- expr : & ExpressionView < Self > ,
92- catalog : & dyn StatsCatalog ,
93- ) -> Option < Expression > {
94- expr. children ( ) [ 0 ] . stat_max ( catalog)
95- }
96-
97- fn stat_min (
98- & self ,
99- expr : & ExpressionView < Self > ,
100- catalog : & dyn StatsCatalog ,
101- ) -> Option < Expression > {
102- expr. children ( ) [ 0 ] . stat_min ( catalog)
103- }
104-
105- fn stat_nan_count (
90+ fn stat_expression (
10691 & self ,
10792 expr : & ExpressionView < Self > ,
93+ stat : Stat ,
10894 catalog : & dyn StatsCatalog ,
10995 ) -> Option < Expression > {
110- expr. children ( ) [ 0 ] . stat_nan_count ( catalog)
111- }
112-
113- fn stat_field_path ( & self , expr : & ExpressionView < Self > ) -> Option < FieldPath > {
114- expr. children ( ) [ 0 ] . stat_field_path ( )
96+ match stat {
97+ Stat :: IsConstant
98+ | Stat :: IsSorted
99+ | Stat :: IsStrictSorted
100+ | Stat :: Max
101+ | Stat :: Min
102+ | Stat :: NaNCount
103+ | Stat :: Sum
104+ | Stat :: UncompressedSizeInBytes => expr. child ( 0 ) . stat_expression ( stat, catalog) ,
105+ Stat :: NullCount => {
106+ // if !expr.data().is_nullable() {
107+ // NOTE(ngates): we should decide on the semantics here. In theory, the null
108+ // count of something cast to non-nullable will be zero. But if we return
109+ // that we know this to be zero, then a pruning predicate may eliminate data
110+ // that would otherwise have caused the cast to error.
111+ // return Some(lit(0u64));
112+ // }
113+ None
114+ }
115+ }
115116 }
116117}
117118
@@ -136,11 +137,11 @@ mod tests {
136137 use vortex_error:: VortexUnwrap as _;
137138
138139 use super :: cast;
140+ use crate :: IntoArray ;
139141 use crate :: arrays:: StructArray ;
140142 use crate :: expr:: exprs:: get_item:: get_item;
141143 use crate :: expr:: exprs:: root:: root;
142- use crate :: expr:: { test_harness, Expression } ;
143- use crate :: IntoArray ;
144+ use crate :: expr:: { Expression , test_harness} ;
144145
145146 #[ test]
146147 fn dtype ( ) {
0 commit comments