@@ -299,6 +299,7 @@ struct PushdownChecker<'schema> {
299299 non_primitive_columns : bool ,
300300 /// Does the expression reference any columns that are in the table
301301 /// schema but not in the file schema?
302+ /// This includes partition columns and projected columns.
302303 projected_columns : bool ,
303304 // Indices into the table schema of the columns required to evaluate the expression
304305 required_columns : BTreeSet < usize > ,
@@ -387,13 +388,12 @@ fn would_column_prevent_pushdown(column_name: &str, table_schema: &Schema) -> bo
387388/// Otherwise, true.
388389pub fn can_expr_be_pushed_down_with_schemas (
389390 expr : & datafusion_expr:: Expr ,
390- _file_schema : & Schema ,
391- table_schema : & Schema ,
391+ file_schema : & Schema ,
392392) -> bool {
393393 let mut can_be_pushed = true ;
394394 expr. apply ( |expr| match expr {
395395 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 ) ;
397397 Ok ( if can_be_pushed {
398398 TreeNodeRecursion :: Jump
399399 } else {
@@ -649,8 +649,6 @@ mod test {
649649
650650 #[ test]
651651 fn nested_data_structures_prevent_pushdown ( ) {
652- let table_schema = get_basic_table_schema ( ) ;
653-
654652 let file_schema = Schema :: new ( vec ! [ Field :: new(
655653 "list_col" ,
656654 DataType :: Struct ( Fields :: empty( ) ) ,
@@ -659,49 +657,31 @@ mod test {
659657
660658 let expr = col ( "list_col" ) . is_not_null ( ) ;
661659
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, ) ) ;
667661 }
668662
669663 #[ test]
670- fn projected_columns_prevent_pushdown ( ) {
671- let table_schema = get_basic_table_schema ( ) ;
672-
664+ fn projected_or_partition_columns_prevent_pushdown ( ) {
673665 let file_schema =
674666 Schema :: new ( vec ! [ Field :: new( "existing_col" , DataType :: Int64 , true ) ] ) ;
675667
676668 let expr = col ( "nonexistent_column" ) . is_null ( ) ;
677669
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, ) ) ;
683671 }
684672
685673 #[ test]
686674 fn basic_expr_doesnt_prevent_pushdown ( ) {
687- let table_schema = get_basic_table_schema ( ) ;
688-
689675 let file_schema =
690676 Schema :: new ( vec ! [ Field :: new( "string_col" , DataType :: Utf8 , true ) ] ) ;
691677
692678 let expr = col ( "string_col" ) . is_null ( ) ;
693679
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, ) ) ;
699681 }
700682
701683 #[ test]
702684 fn complex_expr_doesnt_prevent_pushdown ( ) {
703- let table_schema = get_basic_table_schema ( ) ;
704-
705685 let file_schema = Schema :: new ( vec ! [
706686 Field :: new( "string_col" , DataType :: Utf8 , true ) ,
707687 Field :: new( "bigint_col" , DataType :: Int64 , true ) ,
@@ -711,23 +691,6 @@ mod test {
711691 . is_not_null ( )
712692 . or ( col ( "bigint_col" ) . gt ( Expr :: Literal ( ScalarValue :: Int64 ( Some ( 5 ) ) ) ) ) ;
713693
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, ) ) ;
732695 }
733696}
0 commit comments