@@ -45,10 +45,7 @@ use crate::udaf::PyAggregateUDF;
4545use crate :: udf:: PyScalarUDF ;
4646use crate :: udtf:: PyTableFunction ;
4747use crate :: udwf:: PyWindowUDF ;
48- use crate :: utils:: {
49- call_async, call_datafusion_async, call_datafusion_async_double_question, get_global_ctx,
50- get_tokio_runtime, validate_pycapsule, wait_for_future,
51- } ;
48+ use crate :: utils:: { get_global_ctx, get_tokio_runtime, validate_pycapsule, wait_for_future} ;
5249use datafusion:: arrow:: datatypes:: { DataType , Schema , SchemaRef } ;
5350use datafusion:: arrow:: pyarrow:: PyArrowType ;
5451use datafusion:: arrow:: record_batch:: RecordBatch ;
@@ -428,8 +425,10 @@ impl PySessionContext {
428425 let ctx = self . ctx . clone ( ) ;
429426 let query_owned = query. to_string ( ) ;
430427
431- // Use the helper function to handle async execution
432- let df = call_datafusion_async ( py, async move { ctx. sql ( & query_owned) . await } ) ?;
428+ // Create a future that moves owned values
429+ let result_future = async move { ctx. sql ( & query_owned) . await } ;
430+
431+ let df = wait_for_future ( py, result_future) ?. map_err ( PyDataFusionError :: from) ?;
433432 Ok ( PyDataFrame :: new ( df) )
434433 }
435434
@@ -451,11 +450,10 @@ impl PySessionContext {
451450 let ctx = self . ctx . clone ( ) ;
452451 let query_owned = query. to_string ( ) ;
453452
454- // Use the helper function to handle async execution
455- let df = call_datafusion_async ( py, async move {
456- ctx. sql_with_options ( & query_owned, sql_options) . await
457- } ) ?;
453+ // Create a future that moves owned values
454+ let result_future = async move { ctx. sql_with_options ( & query_owned, sql_options) . await } ;
458455
456+ let df = wait_for_future ( py, result_future) ?. map_err ( PyDataFusionError :: from) ?;
459457 Ok ( PyDataFrame :: new ( df) )
460458 }
461459
@@ -720,7 +718,7 @@ impl PySessionContext {
720718 ctx. register_parquet ( & name_owned, & path_owned, options)
721719 . await
722720 } ;
723- let _ = wait_for_future ( py, result_future) ?? ;
721+ let _ = wait_for_future ( py, result_future) ?;
724722 Ok ( ( ) )
725723 }
726724
@@ -1002,13 +1000,13 @@ impl PySessionContext {
10021000 let ctx = self . ctx . clone ( ) ;
10031001 let name_owned = name. to_string ( ) ;
10041002
1005- // Use call_async since we need custom error mapping
1006- let df = call_async ( py, async move { ctx. table ( & name_owned) . await } , |e| {
1007- PyKeyError :: new_err ( e. to_string ( ) ) . into ( )
1008- } ) ?
1009- . map_err ( |e| PyKeyError :: new_err ( e. to_string ( ) ) ) ?;
1003+ // Create a future that moves owned values
1004+ let table_future = async move { ctx. table ( & name_owned) . await } ;
10101005
1011- Ok ( PyDataFrame :: new ( df) )
1006+ let x = wait_for_future ( py, table_future)
1007+ . map_err ( |e| PyKeyError :: new_err ( e. to_string ( ) ) ) ?
1008+ . map_err ( |e| PyKeyError :: new_err ( e. to_string ( ) ) ) ?;
1009+ Ok ( PyDataFrame :: new ( x) )
10121010 }
10131011
10141012 pub fn execute (
@@ -1269,8 +1267,8 @@ impl PySessionContext {
12691267 // Convert table partition columns
12701268 let table_partition_cols = convert_table_partition_cols ( table_partition_cols) ?;
12711269
1272- // Use the helper function to handle async execution
1273- let df = call_datafusion_async ( py , async move {
1270+ // Create a future that moves owned values
1271+ let result_future = async move {
12741272 let mut options = ParquetReadOptions :: default ( )
12751273 . table_partition_cols ( table_partition_cols)
12761274 . parquet_pruning ( parquet_pruning)
@@ -1285,9 +1283,11 @@ impl PySessionContext {
12851283 options. file_sort_order = file_sort_order_converted;
12861284
12871285 ctx. read_parquet ( & path_owned, options) . await
1288- } ) ? ;
1286+ } ;
12891287
1290- Ok ( PyDataFrame :: new ( df) )
1288+ let df =
1289+ PyDataFrame :: new ( wait_for_future ( py, result_future) ?. map_err ( PyDataFusionError :: from) ?) ;
1290+ Ok ( df)
12911291 }
12921292
12931293 #[ allow( clippy:: too_many_arguments) ]
0 commit comments