@@ -299,6 +299,7 @@ struct PushdownChecker<'schema> {
299
299
non_primitive_columns : bool ,
300
300
/// Does the expression reference any columns that are in the table
301
301
/// schema but not in the file schema?
302
+ /// This includes partition columns and projected columns.
302
303
projected_columns : bool ,
303
304
// Indices into the table schema of the columns required to evaluate the expression
304
305
required_columns : BTreeSet < usize > ,
@@ -387,13 +388,12 @@ fn would_column_prevent_pushdown(column_name: &str, table_schema: &Schema) -> bo
387
388
/// Otherwise, true.
388
389
pub fn can_expr_be_pushed_down_with_schemas (
389
390
expr : & datafusion_expr:: Expr ,
390
- _file_schema : & Schema ,
391
- table_schema : & Schema ,
391
+ file_schema : & Schema ,
392
392
) -> bool {
393
393
let mut can_be_pushed = true ;
394
394
expr. apply ( |expr| match expr {
395
395
datafusion_expr:: Expr :: Column ( column) => {
396
- can_be_pushed &= !would_column_prevent_pushdown ( column. name ( ) , table_schema ) ;
396
+ can_be_pushed &= !would_column_prevent_pushdown ( column. name ( ) , file_schema ) ;
397
397
Ok ( if can_be_pushed {
398
398
TreeNodeRecursion :: Jump
399
399
} else {
@@ -649,8 +649,6 @@ mod test {
649
649
650
650
#[ test]
651
651
fn nested_data_structures_prevent_pushdown ( ) {
652
- let table_schema = get_basic_table_schema ( ) ;
653
-
654
652
let file_schema = Schema :: new ( vec ! [ Field :: new(
655
653
"list_col" ,
656
654
DataType :: Struct ( Fields :: empty( ) ) ,
@@ -659,49 +657,31 @@ mod test {
659
657
660
658
let expr = col ( "list_col" ) . is_not_null ( ) ;
661
659
662
- assert ! ( !can_expr_be_pushed_down_with_schemas(
663
- & expr,
664
- & file_schema,
665
- & table_schema
666
- ) ) ;
660
+ assert ! ( !can_expr_be_pushed_down_with_schemas( & expr, & file_schema, ) ) ;
667
661
}
668
662
669
663
#[ test]
670
- fn projected_columns_prevent_pushdown ( ) {
671
- let table_schema = get_basic_table_schema ( ) ;
672
-
664
+ fn projected_or_partition_columns_prevent_pushdown ( ) {
673
665
let file_schema =
674
666
Schema :: new ( vec ! [ Field :: new( "existing_col" , DataType :: Int64 , true ) ] ) ;
675
667
676
668
let expr = col ( "nonexistent_column" ) . is_null ( ) ;
677
669
678
- assert ! ( !can_expr_be_pushed_down_with_schemas(
679
- & expr,
680
- & file_schema,
681
- & table_schema
682
- ) ) ;
670
+ assert ! ( !can_expr_be_pushed_down_with_schemas( & expr, & file_schema, ) ) ;
683
671
}
684
672
685
673
#[ test]
686
674
fn basic_expr_doesnt_prevent_pushdown ( ) {
687
- let table_schema = get_basic_table_schema ( ) ;
688
-
689
675
let file_schema =
690
676
Schema :: new ( vec ! [ Field :: new( "string_col" , DataType :: Utf8 , true ) ] ) ;
691
677
692
678
let expr = col ( "string_col" ) . is_null ( ) ;
693
679
694
- assert ! ( can_expr_be_pushed_down_with_schemas(
695
- & expr,
696
- & file_schema,
697
- & table_schema
698
- ) ) ;
680
+ assert ! ( can_expr_be_pushed_down_with_schemas( & expr, & file_schema, ) ) ;
699
681
}
700
682
701
683
#[ test]
702
684
fn complex_expr_doesnt_prevent_pushdown ( ) {
703
- let table_schema = get_basic_table_schema ( ) ;
704
-
705
685
let file_schema = Schema :: new ( vec ! [
706
686
Field :: new( "string_col" , DataType :: Utf8 , true ) ,
707
687
Field :: new( "bigint_col" , DataType :: Int64 , true ) ,
@@ -711,23 +691,6 @@ mod test {
711
691
. is_not_null ( )
712
692
. or ( col ( "bigint_col" ) . gt ( Expr :: Literal ( ScalarValue :: Int64 ( Some ( 5 ) ) ) ) ) ;
713
693
714
- assert ! ( can_expr_be_pushed_down_with_schemas(
715
- & expr,
716
- & file_schema,
717
- & table_schema
718
- ) ) ;
719
- }
720
-
721
- fn get_basic_table_schema ( ) -> Schema {
722
- let testdata = datafusion_common:: test_util:: parquet_test_data ( ) ;
723
- let file = std:: fs:: File :: open ( format ! ( "{testdata}/alltypes_plain.parquet" ) )
724
- . expect ( "opening file" ) ;
725
-
726
- let reader = SerializedFileReader :: new ( file) . expect ( "creating reader" ) ;
727
-
728
- let metadata = reader. metadata ( ) ;
729
-
730
- parquet_to_arrow_schema ( metadata. file_metadata ( ) . schema_descr ( ) , None )
731
- . expect ( "parsing schema" )
694
+ assert ! ( can_expr_be_pushed_down_with_schemas( & expr, & file_schema, ) ) ;
732
695
}
733
696
}
0 commit comments