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

Adding add_files_overwrite method #810

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
42 changes: 42 additions & 0 deletions pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,25 @@ def add_files(self, file_paths: List[str], snapshot_properties: Dict[str, str] =
for data_file in data_files:
update_snapshot.append_data_file(data_file)

def add_files_overwrite(
self,
file_paths: List[str],
overwrite_filter: Union[BooleanExpression, str] = ALWAYS_TRUE,
snapshot_properties: Dict[str, str] = EMPTY_DICT,
) -> None:
"""Shorthand API for adding files as data files and overwriting the table.

Args:
file_paths: The list of full file paths to be added as data files to the table
overwrite_filter: ALWAYS_TRUE when you overwrite all the data,
or a boolean expression in case of a partial overwrite
snapshot_properties: Custom properties to be added to the snapshot summary
Raises:
FileNotFoundError: If the file does not exist.
"""
self.delete(delete_filter=overwrite_filter)
self.add_files(file_paths=file_paths, snapshot_properties=snapshot_properties)

def update_spec(self) -> UpdateSpec:
"""Create a new UpdateSpec to update the partitioning of the table.

Expand Down Expand Up @@ -1613,6 +1632,29 @@ def add_files(self, file_paths: List[str], snapshot_properties: Dict[str, str] =
with self.transaction() as tx:
tx.add_files(file_paths=file_paths, snapshot_properties=snapshot_properties)

def add_files_overwrite(
self,
file_paths: List[str],
overwrite_filter: Union[BooleanExpression, str] = ALWAYS_TRUE,
snapshot_properties: Dict[str, str] = EMPTY_DICT,
) -> None:
"""
Shorthand API for adding files as data files and overwriting the table.

Args:
file_paths: The list of full file paths to be added as data files to the table
overwrite_filter: ALWAYS_TRUE when you overwrite all the data,
or a boolean expression in case of a partial overwrite
snapshot_properties: Custom properties to be added to the snapshot summary

Raises:
FileNotFoundError: If the file does not exist.
"""
with self.transaction() as tx:
tx.add_files_overwrite(
file_paths=file_paths, overwrite_filter=overwrite_filter, snapshot_properties=snapshot_properties
)

def update_spec(self, case_sensitive: bool = True) -> UpdateSpec:
return UpdateSpec(Transaction(self, autocommit=True), case_sensitive=case_sensitive)

Expand Down
Loading