@@ -53,36 +53,38 @@ async fn check_stats_precision_with_filter_pushdown() {
5353 let opt = ListingOptions :: new ( Arc :: new ( ParquetFormat :: default ( ) ) ) ;
5454 let table = get_listing_table ( & table_path, None , & opt) . await ;
5555 let ( _, _, state) = get_cache_runtime_state ( ) ;
56+
57+ let filter = Expr :: gt ( col ( "id" ) , lit ( 1 ) ) ;
58+
5659 // Scan without filter, stats are exact
5760 let exec = table. scan ( & state, None , & [ ] , None ) . await . unwrap ( ) ;
5861 assert_eq ! ( exec. statistics( ) . unwrap( ) . num_rows, Precision :: Exact ( 8 ) ) ;
5962
60- // Scan with filter pushdown, stats are inexact
61- let filter = Expr :: gt ( col ( "id" ) , lit ( 1 ) ) ;
62-
63- let data_source_exec = table
64- . scan ( & state, None , & [ filter. clone ( ) ] , None )
65- . await
66- . unwrap ( ) ;
63+ // Apply filter pushdown, this should make the estimate inexact because we don't know
64+ // how many rows will be filtered out by the predicate.
6765 let df_schema = DFSchema :: try_from ( table. schema ( ) ) . unwrap ( ) ;
6866 let exec = FilterExec :: try_new (
6967 state
7068 . create_physical_expr ( filter. clone ( ) , & df_schema)
7169 . unwrap ( ) ,
72- data_source_exec ,
70+ exec ,
7371 )
7472 . unwrap ( ) ;
7573 let exec = FilterPushdown :: new ( )
7674 . optimize ( Arc :: new ( exec) , state. config ( ) . options ( ) )
7775 . unwrap ( ) ;
78- println ! ( "exec: {:?}" , exec) ;
79- let filter_exec = exec. as_any ( ) . downcast_ref :: < FilterExec > ( ) . unwrap ( ) ;
80- // TODO: we need to get the FilterExec to push down its filters
81- // since they no longer get applied to the DataSourceExec directly.
82- // let data_source_exec = Arc::new(
83- // filter_exec.input().as_any().downcast_ref::<DataSourceExec>().unwrap()
84- // ) as Arc<dyn ExecutionPlan>;
85- // assert_eq!(data_source_exec.statistics().unwrap().num_rows, Precision::Inexact(8));
76+ let data_source_exec = exec
77+ . as_any ( )
78+ . downcast_ref :: < FilterExec > ( )
79+ . unwrap ( )
80+ . input ( )
81+ . as_any ( )
82+ . downcast_ref :: < DataSourceExec > ( )
83+ . unwrap ( ) ;
84+ assert_eq ! (
85+ data_source_exec. statistics( ) . unwrap( ) . num_rows,
86+ Precision :: Inexact ( 8 )
87+ ) ;
8688}
8789
8890#[ tokio:: test]
0 commit comments