1717
1818use crate :: dataset:: Dataset ;
1919use crate :: errors:: { py_datafusion_err, to_datafusion_err, PyDataFusionError , PyDataFusionResult } ;
20- use crate :: utils:: { validate_pycapsule, wait_for_future} ;
20+ use crate :: utils:: { get_tokio_runtime , validate_pycapsule, wait_for_future} ;
2121use async_trait:: async_trait;
2222use datafusion:: catalog:: { MemoryCatalogProvider , MemorySchemaProvider } ;
2323use datafusion:: common:: DataFusionError ;
@@ -34,6 +34,7 @@ use pyo3::types::PyCapsule;
3434use pyo3:: IntoPyObjectExt ;
3535use std:: any:: Any ;
3636use std:: collections:: HashSet ;
37+ use std:: ffi:: CString ;
3738use std:: sync:: Arc ;
3839
3940#[ pyclass( name = "RawCatalog" , module = "datafusion.catalog" , subclass) ]
@@ -261,6 +262,23 @@ impl PyTable {
261262 }
262263 }
263264
265+ fn __datafusion_table_provider__ < ' py > (
266+ & self ,
267+ py : Python < ' py > ,
268+ ) -> PyResult < Bound < ' py , PyCapsule > > {
269+ let name = CString :: new ( "datafusion_table_provider" ) . unwrap ( ) ;
270+ let runtime = get_tokio_runtime ( ) . 0 . handle ( ) . clone ( ) ;
271+
272+ let provider = Arc :: clone ( & self . table ) ;
273+ let provider_ptr = Arc :: into_raw ( provider) ;
274+ let provider: Arc < dyn TableProvider + Send > =
275+ unsafe { Arc :: from_raw ( provider_ptr as * const ( dyn TableProvider + Send ) ) } ;
276+
277+ let provider = FFI_TableProvider :: new ( provider, false , Some ( runtime) ) ;
278+
279+ PyCapsule :: new ( py, provider, Some ( name. clone ( ) ) )
280+ }
281+
264282 fn __repr__ ( & self ) -> PyResult < String > {
265283 let kind = self . kind ( ) ;
266284 Ok ( format ! ( "Table(kind={kind})" ) )
0 commit comments