Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ updates:
schedule:
interval: "monthly"
open-pull-requests-limit: 50
ignore:
- dependency-name: "datafusion"
cooldown:
default-days: 7
- package-ecosystem: "github-actions"
Expand Down
63 changes: 0 additions & 63 deletions mkdocs/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2278,69 +2278,6 @@ shape: (11, 4)
└───────────┴─────────────┴────────────────────────────┴─────────────────────┘
```

### Apache DataFusion

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we list this as "experimental" so i think we can remove without a deprecation cycle


PyIceberg integrates with [Apache DataFusion](https://datafusion.apache.org/) through the Custom Table Provider interface ([FFI_TableProvider](https://datafusion.apache.org/python/user-guide/io/table_provider.html)) exposed through `iceberg-rust`.

<!-- prettier-ignore-start -->

!!! note "Requirements"
This requires [`datafusion` and `pyiceberg-core` to be installed](index.md).

<!-- prettier-ignore-end -->

<!-- markdownlint-disable MD046 -- Allowing indented multi-line formatting in admonition-->

!!! warning "Experimental Feature"
The DataFusion integration is considered **experimental**.

The integration has a few caveats:

- Only works with `datafusion == 53`, aligns with the version used in `pyiceberg-core`
- Depends directly on `iceberg-rust` instead of PyIceberg's implementation
- Has limited features compared to the full PyIceberg API

The integration will improve as both DataFusion and `iceberg-rust` matures.

<!-- markdownlint-enable MD046 -->

PyIceberg tables can be registered directly with DataFusion's SessionContext using the table provider interface.

```python
from datafusion import SessionContext
from pyiceberg.catalog import load_catalog
import pyarrow as pa

# Load catalog and create/load a table
catalog = load_catalog("catalog", type="in-memory")
catalog.create_namespace_if_not_exists("default")

# Create some sample data
data = pa.table({"x": [1, 2, 3], "y": [4, 5, 6]})
iceberg_table = catalog.create_table("default.test", schema=data.schema)
iceberg_table.append(data)

# Register the table with DataFusion
ctx = SessionContext()
ctx.register_table("test", iceberg_table)

# Query the table using DataFusion SQL
ctx.table("test").show()
```

This will output:

```python
DataFrame()
+---+---+
| x | y |
+---+---+
| 1 | 4 |
| 2 | 5 |
| 3 | 6 |
+---+---+
```

## Type mapping

### PyArrow
Expand Down
1 change: 0 additions & 1 deletion mkdocs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ You can mix and match optional dependencies depending on your needs:
| gcsfs | GCSFS as a FileIO implementation to interact with the object store |
| rest-sigv4 | Support for generating AWS SIGv4 authentication headers for REST Catalogs |
| pyiceberg-core | Installs iceberg-rust powered core |
| datafusion | Installs both PyArrow and Apache DataFusion |
| hf | Support for Hugging Face Hub |
| gcp-auth | Support for Google Cloud authentication |
| entra-auth | Support for Azure Entra authentication |
Expand Down
47 changes: 0 additions & 47 deletions pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
import pyarrow as pa
import ray
from duckdb import DuckDBPyConnection
from pyiceberg_core.datafusion import IcebergDataFusionTable

from pyiceberg.catalog import Catalog
from pyiceberg.catalog.rest.scan_planning import RESTContentFile, RESTDeleteFile, RESTFileScanTask
Expand Down Expand Up @@ -2067,52 +2066,6 @@ def to_polars(self, **kwargs: Any) -> pl.LazyFrame:

return pl.scan_iceberg(self, **kwargs)

def __datafusion_table_provider__(self, session: Any | None = None) -> IcebergDataFusionTable:
"""Return the DataFusion table provider PyCapsule interface.

To support DataFusion features such as push down filtering, this function will return a PyCapsule
interface that conforms to the FFI Table Provider required by DataFusion. From an end user perspective
you should not need to call this function directly. Instead you can use ``register_table`` in
the DataFusion SessionContext.

Returns:
A PyCapsule DataFusion TableProvider interface.

Example:
```python
from datafusion import SessionContext
from pyiceberg.catalog import load_catalog
import pyarrow as pa
catalog = load_catalog("catalog", type="in-memory")
catalog.create_namespace_if_not_exists("default")
data = pa.table({"x": [1, 2, 3], "y": [4, 5, 6]})
iceberg_table = catalog.create_table("default.test", schema=data.schema)
iceberg_table.append(data)
ctx = SessionContext()
ctx.register_table("test", iceberg_table)
ctx.table("test").show()
```
Results in
```
DataFrame()
+---+---+
| x | y |
+---+---+
| 1 | 4 |
| 2 | 5 |
| 3 | 6 |
+---+---+
```
"""
from pyiceberg_core.datafusion import IcebergDataFusionTable

provider = IcebergDataFusionTable(
identifier=self.name(),
metadata_location=self.metadata_location,
file_io_properties=self.io.properties,
).__datafusion_table_provider__
return provider(session)


class StaticTable(Table):
"""Load a table directly from a metadata file (i.e., without using a catalog)."""
Expand Down
12 changes: 4 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ sql-sqlite = ["sqlalchemy>=2.0.18,<3"]
gcsfs = ["gcsfs>=2023.1.0"]
rest-sigv4 = ["boto3>=1.24.59"]
hf = ["huggingface-hub>=0.24.0"]
# `pyiceberg-core` bundles a `datafusion-ffi` build, and the DataFusion FFI ABI is not stable
# across major versions (https://github.com/apache/datafusion/issues/17374). The two ranges below
# must name the same DataFusion major version: pyiceberg-core 0.10.x bundles datafusion-ffi 53.x.
pyiceberg-core = ["pyiceberg-core>=0.10.1,<0.11.0"]
datafusion = ["datafusion>=53,<54"]
pyiceberg-core = ["pyiceberg-core>=0.10.1"]
gcp-auth = ["google-auth>=2.4.0"]
entra-auth = ["azure-identity>=1.25.1"]
geoarrow = ["geoarrow-types>=0.3.0"]
Expand Down Expand Up @@ -129,6 +125,7 @@ dev = [
"nbformat>=5.10.0",
"ipykernel>=6.29.0",
"ty==1.0.0",
"datafusion>=53",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is used by

from datafusion import SessionContext

]
# for mkdocs
docs = [
Expand Down Expand Up @@ -283,9 +280,8 @@ exclude = ["vendor/"]
extra-paths = ["vendor"]

[tool.ty.analysis]
# pyiceberg_core.datafusion is registered at runtime by its compiled extension; griffe and
# mkdocs_gen_files are only installed with the docs dependency group
allowed-unresolved-imports = ["pyiceberg_core.datafusion", "griffe", "mkdocs_gen_files"]
# griffe and mkdocs_gen_files are only installed with the docs dependency group
allowed-unresolved-imports = ["griffe", "mkdocs_gen_files"]

[tool.ty.rules]
# Rules that currently report errors are disabled so ty can run in CI; re-enable each one as its errors are fixed
Expand Down
64 changes: 0 additions & 64 deletions tests/table/test_datafusion.py

This file was deleted.

Loading
Loading