Skip to content

Add DeltaLake source support #31

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies = [
"fsspec >= 2023.12.2",
"ray[default] >= 2.10.0",
"graphviz >= 0.19.1",
"deltalake >= 0.15.0",
]

[project.optional-dependencies]
Expand Down
20 changes: 20 additions & 0 deletions smallpond/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ray
import ray.exceptions
from loguru import logger
from deltalake import DeltaTable

from smallpond.execution.task import Task
from smallpond.io.filesystem import remove_path
Expand Down Expand Up @@ -56,6 +57,25 @@ def read_parquet(
dataset = ParquetDataSet(paths, columns=columns, union_by_name=union_by_name, recursive=recursive)
plan = DataSourceNode(self._ctx, dataset)
return DataFrame(self, plan)


def read_deltalake(
self,
path: str,
recursive: bool = False,
columns: Optional[List[str]] = None,
union_by_name: bool = False,
) -> DataFrame:
"""
Create a DataFrame from DeltaLake Parquet files.
"""
if 's3://' in path or 'gs://' in path:
raise ValueError("DeltaLake on S3 and GS is not supported yet.")
dt = DeltaTable(path)
paths = dt.files()
dataset = ParquetDataSet(paths, columns=columns, union_by_name=union_by_name, recursive=recursive)
plan = DataSourceNode(self._ctx, dataset)
return DataFrame(self, plan)

def read_json(self, paths: Union[str, List[str]], schema: Dict[str, str]) -> DataFrame:
"""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pandas as pd
import pyarrow as pa
import pytest
from deltalake.writer import write_deltalake

from smallpond.dataframe import Session

Expand Down Expand Up @@ -39,6 +40,12 @@ def test_parquet(sp: Session):
df = sp.read_parquet("tests/data/mock_urls/*.parquet")
assert df.count() == 1000

def test_read_deltalake(sp: Session):
sample = pd.DataFrame({"x": [1, 2, 3]})
write_deltalake("tests/data/", sample)
df = sp.read_deltalake("tests/data/")
assert df.count() == 3


def test_take(sp: Session):
df = sp.from_pandas(pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}))
Expand Down