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

feat(cli): add platform filter for undo soft delete #12012

Merged
merged 1 commit into from
Dec 4, 2024
Merged
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
41 changes: 37 additions & 4 deletions metadata-ingestion/src/datahub/cli/delete_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,47 @@ def references(urn: str, dry_run: bool, force: bool) -> None:


@delete.command()
@click.option("--urn", required=True, type=str, help="the urn of the entity")
def undo_by_filter(urn: str) -> None:
@click.option("--urn", required=False, type=str, help="the urn of the entity")
@click.option(
"-p",
"--platform",
required=False,
type=str,
help="Platform filter (e.g. snowflake)",
)
@click.option(
"-b",
"--batch-size",
required=False,
default=3000,
type=int,
help="Batch size when querying for entities to un-soft delete."
"Maximum 10000. Large batch sizes may cause timeouts.",
)
def undo_by_filter(
urn: Optional[str], platform: Optional[str], batch_size: int
) -> None:
"""
Undo a soft deletion of an entity
Undo soft deletion by filters
"""
graph = get_default_graph()
logger.info(f"Using {graph}")
graph.set_soft_delete_status(urn=urn, delete=False)
if urn:
graph.set_soft_delete_status(urn=urn, delete=False)
else:
urns = list(
Copy link
Collaborator

Choose a reason for hiding this comment

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

should raise an error if both urn and platform are specified

graph.get_urns_by_filter(
platform=platform,
query="*",
status=RemovedStatusFilter.ONLY_SOFT_DELETED,
batch_size=batch_size,
)
)
logger.info(f"Going to un-soft delete {len(urns)} urns")
urns_iter = progressbar.progressbar(urns, redirect_stdout=True)
for urn in urns_iter:
assert urn
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need this line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lint error. If there is a better fix please let me know

graph.set_soft_delete_status(urn=urn, delete=False)


@delete.command(no_args_is_help=True)
Expand Down
Loading