|
| 1 | +.. Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +.. or more contributor license agreements. See the NOTICE file |
| 3 | +.. distributed with this work for additional information |
| 4 | +.. regarding copyright ownership. The ASF licenses this file |
| 5 | +.. to you under the Apache License, Version 2.0 (the |
| 6 | +.. "License"); you may not use this file except in compliance |
| 7 | +.. with the License. You may obtain a copy of the License at |
| 8 | +
|
| 9 | +.. http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +.. Unless required by applicable law or agreed to in writing, |
| 12 | +.. software distributed under the License is distributed on an |
| 13 | +.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +.. KIND, either express or implied. See the License for the |
| 15 | +.. specific language governing permissions and limitations |
| 16 | +.. under the License. |
| 17 | +
|
| 18 | +Upgrade Guides |
| 19 | +============== |
| 20 | + |
| 21 | +DataFusion 52.0.0 |
| 22 | +----------------- |
| 23 | + |
| 24 | +This version includes a major update to the :ref:`ffi` due to upgrades |
| 25 | +to the `Foreign Function Interface <https://doc.rust-lang.org/nomicon/ffi.html>`_. |
| 26 | +Users who contribute their own ``CatalogProvider``, ``SchemaProvider``, |
| 27 | +``TableProvider`` or ``TableFunction`` via FFI must now provide access to a |
| 28 | +``LogicalExtensionCodec`` and a ``TaskContextProvider``. The function signatures |
| 29 | +for the methods to get these ``PyCapsule`` objects now requires an additional |
| 30 | +parameter, which is a Python object that can be used to extract the |
| 31 | +``FFI_LogicalExtensionCodec`` that is necessary. |
| 32 | + |
| 33 | +A complete example can be found in the `FFI example <https://github.com/apache/datafusion-python/tree/main/examples/datafusion-ffi-example>`_. |
| 34 | +Your methods need to be updated to take an additional parameter like in this |
| 35 | +example. |
| 36 | + |
| 37 | +.. code-block:: rust |
| 38 | +
|
| 39 | + #[pymethods] |
| 40 | + impl MyCatalogProvider { |
| 41 | + pub fn __datafusion_catalog_provider__<'py>( |
| 42 | + &self, |
| 43 | + py: Python<'py>, |
| 44 | + session: Bound<PyAny>, |
| 45 | + ) -> PyResult<Bound<'py, PyCapsule>> { |
| 46 | + let name = cr"datafusion_catalog_provider".into(); |
| 47 | +
|
| 48 | + let provider = Arc::clone(&self.inner) as Arc<dyn CatalogProvider + Send>; |
| 49 | +
|
| 50 | + let codec = ffi_logical_codec_from_pycapsule(session)?; |
| 51 | + let provider = FFI_CatalogProvider::new_with_ffi_codec(provider, None, codec); |
| 52 | +
|
| 53 | + PyCapsule::new(py, provider, Some(name)) |
| 54 | + } |
| 55 | + } |
| 56 | +
|
| 57 | +To extract the logical extension codec FFI object from the provided object you |
| 58 | +can implement a helper method such as: |
| 59 | + |
| 60 | +.. code-block:: rust |
| 61 | +
|
| 62 | + pub(crate) fn ffi_logical_codec_from_pycapsule( |
| 63 | + obj: Bound<PyAny>, |
| 64 | + ) -> PyResult<FFI_LogicalExtensionCodec> { |
| 65 | + let attr_name = "__datafusion_logical_extension_codec__"; |
| 66 | + let capsule = if obj.hasattr(attr_name)? { |
| 67 | + obj.getattr(attr_name)?.call0()? |
| 68 | + } else { |
| 69 | + obj |
| 70 | + }; |
| 71 | +
|
| 72 | + let capsule = capsule.downcast::<PyCapsule>()?; |
| 73 | + validate_pycapsule(capsule, "datafusion_logical_extension_codec")?; |
| 74 | +
|
| 75 | + let codec = unsafe { capsule.reference::<FFI_LogicalExtensionCodec>() }; |
| 76 | +
|
| 77 | + Ok(codec.clone()) |
| 78 | + } |
| 79 | +
|
| 80 | +
|
| 81 | +The DataFusion FFI interface updates no longer depend directly on the |
| 82 | +``datafusion`` core crate. You can improve your build times and potentially |
| 83 | +reduce your library binary size by removing this dependency and instead |
| 84 | +using the specific datafusion project crates. |
| 85 | + |
| 86 | +For example, instead of including expressions like: |
| 87 | + |
| 88 | +.. code-block:: rust |
| 89 | +
|
| 90 | + use datafusion::catalog::MemTable; |
| 91 | +
|
| 92 | +Instead you can now write: |
| 93 | + |
| 94 | +.. code-block:: rust |
| 95 | +
|
| 96 | + use datafusion_catalog::MemTable; |
0 commit comments