@@ -27,7 +27,7 @@ use datafusion_common::{DataFusionError, ScalarValue};
2727use itertools:: Itertools ;
2828
2929use crate :: parquet:: Unit :: RowGroup ;
30- use crate :: parquet:: { ContextWithParquet , Scenario } ;
30+ use crate :: parquet:: { ContextWithParquet , Scenario , zero_if_metric_absent } ;
3131use datafusion_expr:: { col, lit} ;
3232struct RowGroupPruningTest {
3333 scenario : Scenario ,
@@ -136,33 +136,51 @@ impl RowGroupPruningTest {
136136
137137 println ! ( "{}" , output. description( ) ) ;
138138 assert_eq ! (
139- output. predicate_evaluation_errors( ) ,
139+ zero_if_metric_absent(
140+ output. predicate_evaluation_errors( ) ,
141+ self . expected_errors
142+ ) ,
140143 self . expected_errors,
141144 "mismatched predicate_evaluation error"
142145 ) ;
143146 assert_eq ! (
144- output. row_groups_matched_statistics( ) ,
147+ zero_if_metric_absent(
148+ output. row_groups_matched_statistics( ) ,
149+ self . expected_row_group_matched_by_statistics
150+ ) ,
145151 self . expected_row_group_matched_by_statistics,
146152 "mismatched row_groups_matched_statistics" ,
147153 ) ;
148154 assert_eq ! (
149- output. row_groups_pruned_statistics( ) ,
155+ zero_if_metric_absent(
156+ output. row_groups_pruned_statistics( ) ,
157+ self . expected_row_group_pruned_by_statistics
158+ ) ,
150159 self . expected_row_group_pruned_by_statistics,
151160 "mismatched row_groups_pruned_statistics" ,
152161 ) ;
153162 assert_eq ! (
154- output. files_ranges_pruned_statistics( ) ,
163+ zero_if_metric_absent(
164+ output. files_ranges_pruned_statistics( ) ,
165+ self . expected_files_pruned_by_statistics
166+ ) ,
155167 self . expected_files_pruned_by_statistics,
156168 "mismatched files_ranges_pruned_statistics" ,
157169 ) ;
158170 let bloom_filter_metrics = output. row_groups_bloom_filter ( ) ;
159171 assert_eq ! (
160- bloom_filter_metrics. as_ref( ) . map( |pm| pm. total_matched( ) ) ,
172+ zero_if_metric_absent(
173+ bloom_filter_metrics. as_ref( ) . map( |pm| pm. total_matched( ) ) ,
174+ self . expected_row_group_matched_by_bloom_filter
175+ ) ,
161176 self . expected_row_group_matched_by_bloom_filter,
162177 "mismatched row_groups_matched_bloom_filter" ,
163178 ) ;
164179 assert_eq ! (
165- bloom_filter_metrics. map( |pm| pm. total_pruned( ) ) ,
180+ zero_if_metric_absent(
181+ bloom_filter_metrics. map( |pm| pm. total_pruned( ) ) ,
182+ self . expected_row_group_pruned_by_bloom_filter
183+ ) ,
166184 self . expected_row_group_pruned_by_bloom_filter,
167185 "mismatched row_groups_pruned_bloom_filter" ,
168186 ) ;
@@ -196,32 +214,50 @@ impl RowGroupPruningTest {
196214
197215 println ! ( "{}" , output. description( ) ) ;
198216 assert_eq ! (
199- output. predicate_evaluation_errors( ) ,
217+ zero_if_metric_absent(
218+ output. predicate_evaluation_errors( ) ,
219+ self . expected_errors
220+ ) ,
200221 self . expected_errors,
201222 "mismatched predicate_evaluation error"
202223 ) ;
203224 assert_eq ! (
204- output. row_groups_matched_statistics( ) ,
225+ zero_if_metric_absent(
226+ output. row_groups_matched_statistics( ) ,
227+ self . expected_row_group_matched_by_statistics
228+ ) ,
205229 self . expected_row_group_matched_by_statistics,
206230 "mismatched row_groups_matched_statistics" ,
207231 ) ;
208232 assert_eq ! (
209- output. row_groups_fully_matched_statistics( ) ,
233+ zero_if_metric_absent(
234+ output. row_groups_fully_matched_statistics( ) ,
235+ self . expected_row_group_fully_matched_by_statistics
236+ ) ,
210237 self . expected_row_group_fully_matched_by_statistics,
211238 "mismatched row_groups_fully_matched_statistics" ,
212239 ) ;
213240 assert_eq ! (
214- output. row_groups_pruned_statistics( ) ,
241+ zero_if_metric_absent(
242+ output. row_groups_pruned_statistics( ) ,
243+ self . expected_row_group_pruned_by_statistics
244+ ) ,
215245 self . expected_row_group_pruned_by_statistics,
216246 "mismatched row_groups_pruned_statistics" ,
217247 ) ;
218248 assert_eq ! (
219- output. files_ranges_pruned_statistics( ) ,
249+ zero_if_metric_absent(
250+ output. files_ranges_pruned_statistics( ) ,
251+ self . expected_files_pruned_by_statistics
252+ ) ,
220253 self . expected_files_pruned_by_statistics,
221254 "mismatched files_ranges_pruned_statistics" ,
222255 ) ;
223256 assert_eq ! (
224- output. limit_pruned_row_groups( ) ,
257+ zero_if_metric_absent(
258+ output. limit_pruned_row_groups( ) ,
259+ self . expected_limit_pruned_row_groups
260+ ) ,
225261 self . expected_limit_pruned_row_groups,
226262 "mismatched limit_pruned_row_groups" ,
227263 ) ;
@@ -343,7 +379,10 @@ async fn prune_date64() {
343379
344380 println ! ( "{}" , output. description( ) ) ;
345381 // This should prune out groups without error
346- assert_eq ! ( output. predicate_evaluation_errors( ) , Some ( 0 ) ) ;
382+ assert_eq ! (
383+ zero_if_metric_absent( output. predicate_evaluation_errors( ) , Some ( 0 ) ) ,
384+ Some ( 0 )
385+ ) ;
347386 // 'dates' table has 4 row groups, and only the first one is matched by the predicate
348387 assert_eq ! ( output. row_groups_matched_statistics( ) , Some ( 1 ) ) ;
349388 assert_eq ! ( output. row_groups_pruned_statistics( ) , Some ( 3 ) ) ;
@@ -383,9 +422,15 @@ async fn prune_disabled() {
383422 println ! ( "{}" , output. description( ) ) ;
384423
385424 // This should not prune any
386- assert_eq ! ( output. predicate_evaluation_errors( ) , Some ( 0 ) ) ;
425+ assert_eq ! (
426+ zero_if_metric_absent( output. predicate_evaluation_errors( ) , Some ( 0 ) ) ,
427+ Some ( 0 )
428+ ) ;
387429 assert_eq ! ( output. row_groups_matched( ) , Some ( 4 ) ) ;
388- assert_eq ! ( output. row_groups_pruned( ) , Some ( 0 ) ) ;
430+ assert_eq ! (
431+ zero_if_metric_absent( output. row_groups_pruned( ) , Some ( 0 ) ) ,
432+ Some ( 0 )
433+ ) ;
389434 assert_eq ! (
390435 output. result_rows,
391436 expected_rows,
0 commit comments