@@ -156,6 +156,7 @@ pub fn split_files(
156156 chunks
157157}
158158
159+ #[ derive( Debug ) ]
159160pub struct Partition {
160161 /// The path to the partition, including the table prefix
161162 path : Path ,
@@ -245,7 +246,16 @@ async fn prune_partitions(
245246 partition_cols : & [ ( String , DataType ) ] ,
246247) -> Result < Vec < Partition > > {
247248 if filters. is_empty ( ) {
248- return Ok ( partitions) ;
249+ // prune partitions which don't contain the partition columns
250+ return Ok ( partitions
251+ . into_iter ( )
252+ . filter ( |p| {
253+ let cols = partition_cols. iter ( ) . map ( |x| x. 0 . as_str ( ) ) ;
254+ !parse_partitions_for_path ( table_path, & p. path , cols)
255+ . unwrap_or_default ( )
256+ . is_empty ( )
257+ } )
258+ . collect ( ) ) ;
249259 }
250260
251261 let mut builders: Vec < _ > = ( 0 ..partition_cols. len ( ) )
@@ -432,6 +442,7 @@ pub async fn pruned_partition_list<'a>(
432442 }
433443
434444 let partition_prefix = evaluate_partition_prefix ( partition_cols, filters) ;
445+
435446 let partitions =
436447 list_partitions ( store, table_path, partition_cols. len ( ) , partition_prefix)
437448 . await ?;
@@ -502,12 +513,12 @@ where
502513 let subpath = table_path. strip_prefix ( file_path) ?;
503514
504515 let mut part_values = vec ! [ ] ;
505- for ( part, pn ) in subpath. zip ( table_partition_cols) {
516+ for ( part, expected_partition ) in subpath. zip ( table_partition_cols) {
506517 match part. split_once ( '=' ) {
507- Some ( ( name, val) ) if name == pn => part_values. push ( val) ,
518+ Some ( ( name, val) ) if name == expected_partition => part_values. push ( val) ,
508519 _ => {
509520 debug ! (
510- "Ignoring file: file_path='{file_path}', table_path='{table_path}', part='{part}', partition_col='{pn }'" ,
521+ "Ignoring file: file_path='{file_path}', table_path='{table_path}', part='{part}', partition_col='{expected_partition }'" ,
511522 ) ;
512523 return None ;
513524 }
@@ -594,6 +605,8 @@ mod tests {
594605 ( "tablepath/mypartition=val1/notparquetfile" , 100 ) ,
595606 ( "tablepath/mypartition=val1/ignoresemptyfile.parquet" , 0 ) ,
596607 ( "tablepath/file.parquet" , 100 ) ,
608+ ( "tablepath/notapartition/file.parquet" , 100 ) ,
609+ ( "tablepath/notmypartition=val1/file.parquet" , 100 ) ,
597610 ] ) ;
598611 let filter = Expr :: eq ( col ( "mypartition" ) , lit ( "val1" ) ) ;
599612 let pruned = pruned_partition_list (
@@ -619,6 +632,8 @@ mod tests {
619632 ( "tablepath/mypartition=val2/file.parquet" , 100 ) ,
620633 ( "tablepath/mypartition=val1/ignoresemptyfile.parquet" , 0 ) ,
621634 ( "tablepath/mypartition=val1/other=val3/file.parquet" , 100 ) ,
635+ ( "tablepath/notapartition/file.parquet" , 100 ) ,
636+ ( "tablepath/notmypartition=val1/file.parquet" , 100 ) ,
622637 ] ) ;
623638 let filter = Expr :: eq ( col ( "mypartition" ) , lit ( "val1" ) ) ;
624639 let pruned = pruned_partition_list (
0 commit comments