@@ -26,8 +26,7 @@ use datafusion::logical_expr::Volatility;
2626use datafusion_ffi:: proto:: logical_extension_codec:: FFI_LogicalExtensionCodec ;
2727use datafusion_ffi:: table_provider:: FFI_TableProvider ;
2828use pyo3:: IntoPyObjectExt ;
29- use pyo3:: exceptions:: { PyImportError , PyTypeError , PyValueError } ;
30- use pyo3:: ffi:: c_str;
29+ use pyo3:: exceptions:: { PyImportError , PyTypeError } ;
3130use pyo3:: prelude:: * ;
3231use pyo3:: types:: { PyCapsule , PyType } ;
3332use tokio:: runtime:: Runtime ;
@@ -36,7 +35,7 @@ use tokio::time::sleep;
3635
3736use crate :: TokioRuntime ;
3837use crate :: context:: PySessionContext ;
39- use crate :: errors:: { PyDataFusionError , PyDataFusionResult , py_datafusion_err , to_datafusion_err} ;
38+ use crate :: errors:: { PyDataFusionError , PyDataFusionResult , to_datafusion_err} ;
4039
4140/// Utility to get the Tokio Runtime from Python
4241#[ inline]
@@ -152,24 +151,6 @@ pub(crate) fn parse_volatility(value: &str) -> PyDataFusionResult<Volatility> {
152151 } )
153152}
154153
155- pub ( crate ) fn validate_pycapsule ( capsule : & Bound < PyCapsule > , name : & str ) -> PyResult < ( ) > {
156- let capsule_name = capsule. name ( ) ?;
157- if capsule_name. is_none ( ) {
158- return Err ( PyValueError :: new_err ( format ! (
159- "Expected {name} PyCapsule to have name set."
160- ) ) ) ;
161- }
162-
163- let capsule_name = unsafe { capsule_name. unwrap ( ) . as_cstr ( ) . to_str ( ) ? } ;
164- if capsule_name != name {
165- return Err ( PyValueError :: new_err ( format ! (
166- "Expected name '{name}' in PyCapsule, instead got '{capsule_name}'"
167- ) ) ) ;
168- }
169-
170- Ok ( ( ) )
171- }
172-
173154pub ( crate ) fn table_provider_from_pycapsule < ' py > (
174155 mut obj : Bound < ' py , PyAny > ,
175156 session : Bound < ' py , PyAny > ,
@@ -187,11 +168,9 @@ pub(crate) fn table_provider_from_pycapsule<'py>(
187168 } ) ?;
188169 }
189170
190- if let Ok ( capsule) = obj. cast :: < PyCapsule > ( ) . map_err ( py_datafusion_err) {
191- validate_pycapsule ( capsule, "datafusion_table_provider" ) ?;
192-
171+ if let Ok ( capsule) = obj. cast :: < PyCapsule > ( ) {
193172 let data: NonNull < FFI_TableProvider > = capsule
194- . pointer_checked ( Some ( c_str ! ( "datafusion_table_provider" ) ) ) ?
173+ . pointer_checked ( Some ( c "datafusion_table_provider") ) ?
195174 . cast ( ) ;
196175 let provider = unsafe { data. as_ref ( ) } ;
197176 let provider: Arc < dyn TableProvider > = provider. into ( ) ;
@@ -216,12 +195,10 @@ pub(crate) fn extract_logical_extension_codec(
216195 } else {
217196 obj
218197 } ;
219- let capsule = capsule. cast :: < PyCapsule > ( ) . map_err ( py_datafusion_err) ?;
220-
221- validate_pycapsule ( capsule, "datafusion_logical_extension_codec" ) ?;
198+ let capsule = capsule. cast :: < PyCapsule > ( ) ?;
222199
223200 let data: NonNull < FFI_LogicalExtensionCodec > = capsule
224- . pointer_checked ( Some ( c_str ! ( "datafusion_logical_extension_codec" ) ) ) ?
201+ . pointer_checked ( Some ( c "datafusion_logical_extension_codec") ) ?
225202 . cast ( ) ;
226203 let codec = unsafe { data. as_ref ( ) } ;
227204 Ok ( Arc :: new ( codec. clone ( ) ) )
0 commit comments