timsaucer commented on PR #1256: URL: https://github.com/apache/datafusion-python/pull/1256#issuecomment-3371191794
I don't think that example demonstrates how users are expected to provide PyCapsule based providers. I changed it slightly below to fit [TableProviderExportable](https://github.com/apache/datafusion-python/blob/main/python/datafusion/context.py#L76). With this change it does segfault, but I expect that because it is not a valid object. ``` from __future__ import annotations import ctypes from datafusion import SessionContext, Table # Keep the backing memory alive for the lifetime of the module so the capsule # always wraps a valid (non-null) pointer. The capsule content is irrelevant for # this regression example—we only need a non-null address. _DUMMY_CAPSULE_BYTES = ctypes.create_string_buffer(b"x") class CapsuleContainer: def __init__(self): self.__datafusion_table_provider__ = make_table_provider_capsule def make_table_provider_capsule() -> object: """Create a dummy PyCapsule with the expected table provider name.""" pycapsule_new = ctypes.pythonapi.PyCapsule_New pycapsule_new.restype = ctypes.py_object pycapsule_new.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p] dummy_ptr = ctypes.cast(_DUMMY_CAPSULE_BYTES, ctypes.c_void_p) return pycapsule_new(dummy_ptr, b"datafusion_table_provider", None) def main() -> None: """Attempt to use the capsule the same way existing callers do.""" ctx = SessionContext() try: capsule = CapsuleContainer() except Exception as err: print("Creating the PyCapsule failed:", err) return ctx.read_table(capsule) if __name__ == "__main__": main() ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
