@@ -46,6 +46,7 @@ use datafusion::datasource::file_format::arrow::ArrowFormatFactory;
46
46
use datafusion:: datasource:: file_format:: csv:: CsvFormatFactory ;
47
47
use datafusion:: datasource:: file_format:: parquet:: ParquetFormatFactory ;
48
48
use datafusion:: datasource:: file_format:: { format_as_file_type, DefaultFileType } ;
49
+ use datafusion:: datasource:: DefaultTableSource ;
49
50
use datafusion:: execution:: session_state:: SessionStateBuilder ;
50
51
use datafusion:: execution:: FunctionRegistry ;
51
52
use datafusion:: functions_aggregate:: count:: count_udaf;
@@ -77,9 +78,9 @@ use datafusion_expr::expr::{
77
78
use datafusion_expr:: logical_plan:: { Extension , UserDefinedLogicalNodeCore } ;
78
79
use datafusion_expr:: {
79
80
Accumulator , AggregateUDF , ColumnarValue , ExprFunctionExt , ExprSchemable , Literal ,
80
- LogicalPlan , Operator , PartitionEvaluator , ScalarUDF , Signature , TryCast , Volatility ,
81
- WindowFrame , WindowFrameBound , WindowFrameUnits , WindowFunctionDefinition , WindowUDF ,
82
- WindowUDFImpl ,
81
+ LogicalPlan , LogicalPlanBuilder , Operator , PartitionEvaluator , ScalarUDF , Signature ,
82
+ TryCast , Volatility , WindowFrame , WindowFrameBound , WindowFrameUnits ,
83
+ WindowFunctionDefinition , WindowUDF , WindowUDFImpl ,
83
84
} ;
84
85
use datafusion_functions_aggregate:: average:: avg_udaf;
85
86
use datafusion_functions_aggregate:: expr_fn:: {
@@ -2669,6 +2670,44 @@ async fn roundtrip_custom_listing_tables_schema() -> Result<()> {
2669
2670
Ok ( ( ) )
2670
2671
}
2671
2672
2673
+ #[ tokio:: test]
2674
+ async fn roundtrip_custom_listing_tables_schema_table_scan_projection ( ) -> Result < ( ) > {
2675
+ let ctx = SessionContext :: new ( ) ;
2676
+ // Make sure during round-trip, constraint information is preserved
2677
+ let file_format = JsonFormat :: default ( ) ;
2678
+ let table_partition_cols = vec ! [ ( "part" . to_owned( ) , DataType :: Int64 ) ] ;
2679
+ let data = "../core/tests/data/partitioned_table_json" ;
2680
+ let listing_table_url = ListingTableUrl :: parse ( data) ?;
2681
+ let listing_options = ListingOptions :: new ( Arc :: new ( file_format) )
2682
+ . with_table_partition_cols ( table_partition_cols) ;
2683
+
2684
+ let config = ListingTableConfig :: new ( listing_table_url)
2685
+ . with_listing_options ( listing_options)
2686
+ . infer_schema ( & ctx. state ( ) )
2687
+ . await ?;
2688
+
2689
+ let listing_table: Arc < dyn TableProvider > = Arc :: new ( ListingTable :: try_new ( config) ?) ;
2690
+
2691
+ let projection = [ "part" , "value" ]
2692
+ . iter ( )
2693
+ . map ( |field_name| listing_table. schema ( ) . index_of ( field_name) )
2694
+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
2695
+
2696
+ let plan = LogicalPlanBuilder :: scan (
2697
+ "hive_style" ,
2698
+ Arc :: new ( DefaultTableSource :: new ( listing_table) ) ,
2699
+ Some ( projection) ,
2700
+ ) ?
2701
+ . limit ( 0 , Some ( 1 ) ) ?
2702
+ . build ( ) ?;
2703
+
2704
+ let bytes = logical_plan_to_bytes ( & plan) ?;
2705
+ let new_plan = logical_plan_from_bytes ( & bytes, & ctx) ?;
2706
+
2707
+ assert_eq ! ( plan, new_plan) ;
2708
+ Ok ( ( ) )
2709
+ }
2710
+
2672
2711
#[ tokio:: test]
2673
2712
async fn roundtrip_arrow_scan ( ) -> Result < ( ) > {
2674
2713
let ctx = SessionContext :: new ( ) ;
0 commit comments