@@ -18,18 +18,9 @@ use crate::ArrayRef;
1818use crate :: ExecutionCtx ;
1919use crate :: dtype:: DType ;
2020use crate :: dtype:: Nullability ;
21- use crate :: expr:: StatsCatalog ;
2221use crate :: expr:: and;
23- use crate :: expr:: and_collect;
24- use crate :: expr:: eq;
2522use crate :: expr:: expression:: Expression ;
26- use crate :: expr:: gt;
27- use crate :: expr:: gt_eq;
2823use crate :: expr:: lit;
29- use crate :: expr:: lt;
30- use crate :: expr:: lt_eq;
31- use crate :: expr:: or_collect;
32- use crate :: expr:: stats:: Stat ;
3324use crate :: scalar_fn:: Arity ;
3425use crate :: scalar_fn:: ChildName ;
3526use crate :: scalar_fn:: ExecutionArgs ;
@@ -221,110 +212,6 @@ impl ScalarFnVTable for Binary {
221212 } )
222213 }
223214
224- fn stat_falsification (
225- & self ,
226- operator : & Operator ,
227- expr : & Expression ,
228- catalog : & dyn StatsCatalog ,
229- ) -> Option < Expression > {
230- // Wrap another predicate with an optional NaNCount check, if the stat is available.
231- //
232- // For example, regular pruning conversion for `A >= B` would be
233- //
234- // A.max < B.min
235- //
236- // With NaN predicate introduction, we'd conjunct it with a check for NaNCount, resulting
237- // in:
238- //
239- // (A.nan_count = 0) AND (B.nan_count = 0) AND A.max < B.min
240- //
241- // Non-floating point column and literal expressions should be unaffected as they do not
242- // have a nan_count statistic defined.
243- fn with_nan_predicate (
244- lhs : & Expression ,
245- rhs : & Expression ,
246- value_predicate : Expression ,
247- catalog : & dyn StatsCatalog ,
248- ) -> Expression {
249- let nan_predicate = and_collect (
250- lhs. stat_expression ( Stat :: NaNCount , catalog)
251- . into_iter ( )
252- . chain ( rhs. stat_expression ( Stat :: NaNCount , catalog) )
253- . map ( |nans| eq ( nans, lit ( 0u64 ) ) ) ,
254- ) ;
255-
256- if let Some ( nan_check) = nan_predicate {
257- and ( nan_check, value_predicate)
258- } else {
259- value_predicate
260- }
261- }
262-
263- let lhs = expr. child ( 0 ) ;
264- let rhs = expr. child ( 1 ) ;
265- match operator {
266- Operator :: Eq => {
267- let min_lhs = lhs. stat_min ( catalog) ;
268- let max_lhs = lhs. stat_max ( catalog) ;
269-
270- let min_rhs = rhs. stat_min ( catalog) ;
271- let max_rhs = rhs. stat_max ( catalog) ;
272-
273- let left = min_lhs. zip ( max_rhs) . map ( |( a, b) | gt ( a, b) ) ;
274- let right = min_rhs. zip ( max_lhs) . map ( |( a, b) | gt ( a, b) ) ;
275-
276- let min_max_check = or_collect ( left. into_iter ( ) . chain ( right) ) ?;
277-
278- // NaN is not captured by the min/max stat, so we must check NaNCount before pruning
279- Some ( with_nan_predicate ( lhs, rhs, min_max_check, catalog) )
280- }
281- Operator :: NotEq => {
282- let min_lhs = lhs. stat_min ( catalog) ?;
283- let max_lhs = lhs. stat_max ( catalog) ?;
284-
285- let min_rhs = rhs. stat_min ( catalog) ?;
286- let max_rhs = rhs. stat_max ( catalog) ?;
287-
288- let min_max_check = and ( eq ( min_lhs, max_rhs) , eq ( max_lhs, min_rhs) ) ;
289-
290- Some ( with_nan_predicate ( lhs, rhs, min_max_check, catalog) )
291- }
292- Operator :: Gt => {
293- let min_max_check = lt_eq ( lhs. stat_max ( catalog) ?, rhs. stat_min ( catalog) ?) ;
294-
295- Some ( with_nan_predicate ( lhs, rhs, min_max_check, catalog) )
296- }
297- Operator :: Gte => {
298- // NaN is not captured by the min/max stat, so we must check NaNCount before pruning
299- let min_max_check = lt ( lhs. stat_max ( catalog) ?, rhs. stat_min ( catalog) ?) ;
300-
301- Some ( with_nan_predicate ( lhs, rhs, min_max_check, catalog) )
302- }
303- Operator :: Lt => {
304- // NaN is not captured by the min/max stat, so we must check NaNCount before pruning
305- let min_max_check = gt_eq ( lhs. stat_min ( catalog) ?, rhs. stat_max ( catalog) ?) ;
306-
307- Some ( with_nan_predicate ( lhs, rhs, min_max_check, catalog) )
308- }
309- Operator :: Lte => {
310- // NaN is not captured by the min/max stat, so we must check NaNCount before pruning
311- let min_max_check = gt ( lhs. stat_min ( catalog) ?, rhs. stat_max ( catalog) ?) ;
312-
313- Some ( with_nan_predicate ( lhs, rhs, min_max_check, catalog) )
314- }
315- Operator :: And => or_collect (
316- lhs. stat_falsification ( catalog)
317- . into_iter ( )
318- . chain ( rhs. stat_falsification ( catalog) ) ,
319- ) ,
320- Operator :: Or => Some ( and (
321- lhs. stat_falsification ( catalog) ?,
322- rhs. stat_falsification ( catalog) ?,
323- ) ) ,
324- Operator :: Add | Operator :: Sub | Operator :: Mul | Operator :: Div => None ,
325- }
326- }
327-
328215 fn validity (
329216 & self ,
330217 operator : & Operator ,
@@ -381,8 +268,12 @@ mod tests {
381268 use crate :: expr:: Expression ;
382269 use crate :: expr:: and_collect;
383270 use crate :: expr:: col;
271+ use crate :: expr:: eq;
272+ use crate :: expr:: gt;
273+ use crate :: expr:: gt_eq;
384274 use crate :: expr:: lit;
385275 use crate :: expr:: lt;
276+ use crate :: expr:: lt_eq;
386277 use crate :: expr:: not_eq;
387278 use crate :: expr:: or;
388279 use crate :: expr:: or_collect;
0 commit comments