@@ -36,8 +36,9 @@ use datafusion::datasource::listing::{
3636} ;
3737use datafusion:: datasource:: object_store:: ObjectStoreUrl ;
3838use datafusion:: datasource:: physical_plan:: {
39- ArrowSource , FileGroup , FileOutputMode , FileScanConfigBuilder , FileSinkConfig ,
40- ParquetSource , wrap_partition_type_in_dict, wrap_partition_value_in_dict,
39+ ArrowSource , FileGroup , FileOutputMode , FileScanConfig , FileScanConfigBuilder ,
40+ FileSinkConfig , ParquetSource , wrap_partition_type_in_dict,
41+ wrap_partition_value_in_dict,
4142} ;
4243use datafusion:: datasource:: sink:: DataSinkExec ;
4344use datafusion:: datasource:: source:: DataSourceExec ;
@@ -929,6 +930,59 @@ fn roundtrip_parquet_exec_with_pruning_predicate() -> Result<()> {
929930 roundtrip_test ( DataSourceExec :: from_data_source ( scan_config) )
930931}
931932
933+ #[ test]
934+ fn roundtrip_parquet_exec_attaches_cached_reader_factory_after_roundtrip ( ) -> Result < ( ) > {
935+ let file_schema =
936+ Arc :: new ( Schema :: new ( vec ! [ Field :: new( "col" , DataType :: Utf8 , false ) ] ) ) ;
937+ let file_source = Arc :: new ( ParquetSource :: new ( Arc :: clone ( & file_schema) ) ) ;
938+ let scan_config =
939+ FileScanConfigBuilder :: new ( ObjectStoreUrl :: local_filesystem ( ) , file_source)
940+ . with_file_groups ( vec ! [ FileGroup :: new( vec![ PartitionedFile :: new(
941+ "/path/to/file.parquet" . to_string( ) ,
942+ 1024 ,
943+ ) ] ) ] )
944+ . with_statistics ( Statistics {
945+ num_rows : Precision :: Inexact ( 100 ) ,
946+ total_byte_size : Precision :: Inexact ( 1024 ) ,
947+ column_statistics : Statistics :: unknown_column ( & file_schema) ,
948+ } )
949+ . build ( ) ;
950+ let exec_plan = DataSourceExec :: from_data_source ( scan_config) ;
951+
952+ let ctx = SessionContext :: new ( ) ;
953+ let codec = DefaultPhysicalExtensionCodec { } ;
954+ let proto_converter = DefaultPhysicalProtoConverter { } ;
955+ let roundtripped =
956+ roundtrip_test_and_return ( exec_plan, & ctx, & codec, & proto_converter) ?;
957+
958+ let data_source = roundtripped
959+ . as_any ( )
960+ . downcast_ref :: < DataSourceExec > ( )
961+ . ok_or_else ( || {
962+ internal_datafusion_err ! ( "Expected DataSourceExec after roundtrip" )
963+ } ) ?;
964+ let file_scan = data_source
965+ . data_source ( )
966+ . as_any ( )
967+ . downcast_ref :: < FileScanConfig > ( )
968+ . ok_or_else ( || {
969+ internal_datafusion_err ! ( "Expected FileScanConfig after roundtrip" )
970+ } ) ?;
971+ let parquet_source = file_scan
972+ . file_source ( )
973+ . as_any ( )
974+ . downcast_ref :: < ParquetSource > ( )
975+ . ok_or_else ( || {
976+ internal_datafusion_err ! ( "Expected ParquetSource after roundtrip" )
977+ } ) ?;
978+
979+ assert ! (
980+ parquet_source. parquet_file_reader_factory( ) . is_some( ) ,
981+ "Parquet reader factory should be attached after decoding from protobuf"
982+ ) ;
983+ Ok ( ( ) )
984+ }
985+
932986#[ test]
933987fn roundtrip_arrow_scan ( ) -> Result < ( ) > {
934988 let file_schema =
0 commit comments