Skip to content

fix: make DeltaTable pickleable #3501

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

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 17 additions & 0 deletions python/deltalake/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ def __init__(

"""
self._storage_options = storage_options

Choose a reason for hiding this comment

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

Suggested change
self._storage_options = storage_options
self._storage_options = storage_options
self._pickle_storage_options = storage_options is not None

self._without_files = without_files
self._log_buffer_size = log_buffer_size
self._table = RawDeltaTable(
str(table_uri),
version=version,
Expand All @@ -166,6 +168,21 @@ def __init__(
log_buffer_size=log_buffer_size,
)

def __reduce__(self) -> tuple[type, tuple[Any, ...]]:
"""
This allows DeltaTable to be pickled.
"""
return (
self.__class__,
(
self.table_uri,
self.version(),
self._storage_options,
self._without_files,
self._log_buffer_size,
),
)

@staticmethod
def is_deltatable(
table_uri: str, storage_options: dict[str, str] | None = None
Expand Down
14 changes: 14 additions & 0 deletions python/tests/test_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pickle

from deltalake import DeltaTable


def test_table_serialization():
table_path = "../crates/test/tests/data/simple_table"
dt = DeltaTable(table_path)

dt2 = pickle.loads(pickle.dumps(dt))

# Do some sanity checks
assert dt2.version() == dt.version()
assert dt2.table_uri == dt.table_uri
Loading