@@ -44,6 +44,7 @@ use datafusion::datasource::file_format::arrow::ArrowFormatFactory;
4444use datafusion:: datasource:: file_format:: csv:: CsvFormatFactory ;
4545use datafusion:: datasource:: file_format:: parquet:: ParquetFormatFactory ;
4646use datafusion:: datasource:: file_format:: { format_as_file_type, DefaultFileType } ;
47+ use datafusion:: datasource:: DefaultTableSource ;
4748use datafusion:: execution:: session_state:: SessionStateBuilder ;
4849use datafusion:: execution:: FunctionRegistry ;
4950use datafusion:: functions_aggregate:: count:: count_udaf;
@@ -75,9 +76,9 @@ use datafusion_expr::expr::{
7576use datafusion_expr:: logical_plan:: { Extension , UserDefinedLogicalNodeCore } ;
7677use datafusion_expr:: {
7778 Accumulator , AggregateUDF , ColumnarValue , ExprFunctionExt , ExprSchemable , Literal ,
78- LogicalPlan , Operator , PartitionEvaluator , ScalarUDF , Signature , TryCast , Volatility ,
79- WindowFrame , WindowFrameBound , WindowFrameUnits , WindowFunctionDefinition , WindowUDF ,
80- WindowUDFImpl ,
79+ LogicalPlan , LogicalPlanBuilder , Operator , PartitionEvaluator , ScalarUDF , Signature ,
80+ TryCast , Volatility , WindowFrame , WindowFrameBound , WindowFrameUnits ,
81+ WindowFunctionDefinition , WindowUDF , WindowUDFImpl ,
8182} ;
8283use datafusion_functions_aggregate:: average:: avg_udaf;
8384use datafusion_functions_aggregate:: expr_fn:: {
@@ -2643,16 +2644,24 @@ async fn roundtrip_custom_listing_tables_schema() -> Result<()> {
26432644 . infer_schema ( & ctx. state ( ) )
26442645 . await ?;
26452646
2646- ctx . register_table ( "hive_style" , Arc :: new ( ListingTable :: try_new ( config) ?) ) ? ;
2647+ let listing_table : Arc < dyn TableProvider > = Arc :: new ( ListingTable :: try_new ( config) ?) ;
26472648
2648- let plan = ctx
2649- . sql ( "SELECT part, value FROM hive_style LIMIT 1" )
2650- . await ?
2651- . logical_plan ( )
2652- . clone ( ) ;
2649+ let projection = [ "part" , "value" ]
2650+ . iter ( )
2651+ . map ( |field_name| listing_table. schema ( ) . index_of ( field_name) )
2652+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
2653+
2654+ let plan = LogicalPlanBuilder :: scan (
2655+ "hive_style" ,
2656+ Arc :: new ( DefaultTableSource :: new ( listing_table) ) ,
2657+ Some ( projection) ,
2658+ ) ?
2659+ . limit ( 0 , Some ( 1 ) ) ?
2660+ . build ( ) ?;
26532661
26542662 let bytes = logical_plan_to_bytes ( & plan) ?;
26552663 let new_plan = logical_plan_from_bytes ( & bytes, & ctx) ?;
2664+
26562665 assert_eq ! ( plan, new_plan) ;
26572666 Ok ( ( ) )
26582667}
0 commit comments