@@ -775,17 +775,22 @@ impl PySessionContext {
775775 // Clone self to avoid borrowing
776776 let self_clone = self . clone ( ) ;
777777
778- // Create a future that uses our helper function
778+ // Create options with owned values inside the async block
779779 let result_future = async move {
780- let schema_ref = schema_owned. as_ref ( ) ;
781- let options = create_csv_read_options (
782- has_header,
783- delimiter_byte,
784- schema_infer_max_records,
785- & file_extension_owned,
786- file_compression_type. clone ( ) ,
787- schema_ref,
788- ) ?;
780+ let mut options = CsvReadOptions :: new ( )
781+ . has_header ( has_header)
782+ . delimiter ( delimiter_byte)
783+ . schema_infer_max_records ( schema_infer_max_records)
784+ . file_extension ( & file_extension_owned)
785+ . file_compression_type (
786+ parse_file_compression_type ( file_compression_type. clone ( ) )
787+ . map_err ( py_err_to_datafusion_err) ?,
788+ ) ;
789+
790+ // Use owned schema if provided
791+ if let Some ( s) = & schema_owned {
792+ options. schema = Some ( s) ;
793+ }
789794
790795 self_clone
791796 . register_csv_from_multiple_paths ( & name_owned, paths, options)
@@ -798,15 +803,20 @@ impl PySessionContext {
798803
799804 // Create a future that moves owned values
800805 let result_future = async move {
801- let schema_ref = schema_owned. as_ref ( ) ;
802- let options = create_csv_read_options (
803- has_header,
804- delimiter_byte,
805- schema_infer_max_records,
806- & file_extension_owned,
807- file_compression_type. clone ( ) ,
808- schema_ref,
809- ) ?;
806+ let mut options = CsvReadOptions :: new ( )
807+ . has_header ( has_header)
808+ . delimiter ( delimiter_byte)
809+ . schema_infer_max_records ( schema_infer_max_records)
810+ . file_extension ( & file_extension_owned)
811+ . file_compression_type (
812+ parse_file_compression_type ( file_compression_type. clone ( ) )
813+ . map_err ( py_err_to_datafusion_err) ?,
814+ ) ;
815+
816+ // Use owned schema if provided
817+ if let Some ( s) = & schema_owned {
818+ options. schema = Some ( s) ;
819+ }
810820
811821 ctx. register_csv ( & name_owned, & path, options) . await
812822 } ;
@@ -1406,32 +1416,6 @@ impl PySessionContext {
14061416 }
14071417}
14081418
1409- /// Create CsvReadOptions with the provided parameters
1410- fn create_csv_read_options < ' a > (
1411- has_header : bool ,
1412- delimiter_byte : u8 ,
1413- schema_infer_max_records : usize ,
1414- file_extension : & ' a str ,
1415- file_compression_type : Option < String > ,
1416- schema : Option < & ' a Schema > ,
1417- ) -> PyDataFusionResult < CsvReadOptions < ' a > > {
1418- let mut options = CsvReadOptions :: new ( )
1419- . has_header ( has_header)
1420- . delimiter ( delimiter_byte)
1421- . schema_infer_max_records ( schema_infer_max_records)
1422- . file_extension ( file_extension)
1423- . file_compression_type (
1424- parse_file_compression_type ( file_compression_type) . map_err ( py_err_to_datafusion_err) ?,
1425- ) ;
1426-
1427- // Use schema if provided
1428- if let Some ( s) = schema {
1429- options. schema = Some ( s) ;
1430- }
1431-
1432- Ok ( options)
1433- }
1434-
14351419pub fn convert_table_partition_cols (
14361420 table_partition_cols : Vec < ( String , String ) > ,
14371421) -> PyDataFusionResult < Vec < ( String , DataType ) > > {
0 commit comments