Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(duckdb): use the delta extension for reading deltalake data #10833

Merged
merged 2 commits into from
Feb 13, 2025
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
32 changes: 16 additions & 16 deletions ibis/backends/duckdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,43 +827,43 @@ def _read_parquet_pyarrow_dataset(
# explicitly.

def read_delta(
self, path: str, /, *, table_name: str | None = None, **kwargs: Any
self, path: str | Path, /, *, table_name: str | None = None, **kwargs: Any
) -> ir.Table:
"""Register a Delta Lake table as a table in the current database.

Parameters
----------
path
The data source. Must be a directory
containing a Delta Lake table.
The data source. Must be a directory containing a Delta Lake table.
table_name
An optional name to use for the created table. This defaults to
a sequentially generated name.
**kwargs
kwargs
Additional keyword arguments passed to deltalake.DeltaTable.

Returns
-------
ir.Table
The just-registered table.

"""
path = util.normalize_filenames(path)[0]
(path,) = util.normalize_filenames(path)

extensions = ["delta"]
if path.startswith(("http://", "https://", "s3://")):
extensions.append("httpfs")

table_name = table_name or util.gen_name("read_delta")

try:
from deltalake import DeltaTable
except ImportError:
raise ImportError(
"The deltalake extra is required to use the "
"read_delta method. You can install it using pip:\n\n"
"pip install 'ibis-framework[deltalake]'\n"
)
options = [
sg.to_identifier(key).eq(sge.convert(val)) for key, val in kwargs.items()
]

delta_table = DeltaTable(path, **kwargs)
self._load_extensions(extensions)

self.con.register(table_name, delta_table.to_pyarrow_dataset())
self._create_temp_view(
table_name,
sg.select(STAR).from_(self.compiler.f.delta_scan(path, *options)),
)
return self.table(table_name)

def list_tables(
Expand Down
6 changes: 0 additions & 6 deletions ibis/backends/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from ibis import util
from ibis.backends.tests.errors import (
DatabricksServerOperationError,
DuckDBInvalidInputException,
DuckDBNotImplementedException,
DuckDBParserException,
ExaQueryError,
Expand Down Expand Up @@ -476,11 +475,6 @@ def test_to_pyarrow_decimal(backend, dtype, pyarrow_dtype):
condition=CI and IS_SPARK_REMOTE,
reason="not supported until pyspark 4",
)
@pytest.mark.xfail_version(
duckdb=["pyarrow>=19"],
raises=DuckDBInvalidInputException,
reason="decoding delta file fails",
)
@pytest.mark.xfail_version(
datafusion=["pyarrow>=19", "datafusion>=44"],
raises=Exception,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ druid = [
"rich>=12.4.4,<14",
]
duckdb = [
"duckdb>=0.10,<2",
"duckdb>=0.10.3,<2",
"pyarrow>=10.0.1",
"pyarrow-hotfix>=0.4,<1",
"numpy>=1.23.2,<3",
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading