File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -1103,6 +1103,13 @@ impl PySessionContext {
11031103 }
11041104
11051105 pub fn read_table ( & self , table : Bound < ' _ , PyAny > ) -> PyDataFusionResult < PyDataFrame > {
1106+ if let Ok ( py_table) = table. extract :: < PyTable > ( ) {
1107+ // RawTable values returned from DataFusion (e.g. ctx.catalog().schema().table(...).table)
1108+ // should keep using this native path to avoid an unnecessary FFI round-trip.
1109+ let df = self . ctx . read_table ( py_table. table ( ) ) ?;
1110+ return Ok ( PyDataFrame :: new ( df) ) ;
1111+ }
1112+
11061113 if table. hasattr ( "__datafusion_table_provider__" ) ? {
11071114 let capsule = table. getattr ( "__datafusion_table_provider__" ) ?. call0 ( ) ?;
11081115 let capsule = capsule. downcast :: < PyCapsule > ( ) . map_err ( py_datafusion_err) ?;
@@ -1114,16 +1121,10 @@ impl PySessionContext {
11141121 let df = self . ctx . read_table ( Arc :: new ( provider) ) ?;
11151122 Ok ( PyDataFrame :: new ( df) )
11161123 } else {
1117- match table. extract :: < PyTable > ( ) {
1118- Ok ( py_table) => {
1119- let df = self . ctx . read_table ( py_table. table ( ) ) ?;
1120- Ok ( PyDataFrame :: new ( df) )
1121- }
1122- Err ( _) => Err ( crate :: errors:: PyDataFusionError :: Common (
1123- "Object must be a datafusion.Table or expose __datafusion_table_provider__()."
1124- . to_string ( ) ,
1125- ) ) ,
1126- }
1124+ Err ( crate :: errors:: PyDataFusionError :: Common (
1125+ "Object must be a datafusion.Table or expose __datafusion_table_provider__()."
1126+ . to_string ( ) ,
1127+ ) )
11271128 }
11281129 }
11291130
You can’t perform that action at this time.
0 commit comments