Skip to content

Commit

Permalink
feat(cli/delete): add --urn-file option (#12247)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergio Gómez Villamor <[email protected]>
  • Loading branch information
anshbansal and sgomezvillamor authored Jan 20, 2025
1 parent 7ac6523 commit 2109abd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions metadata-ingestion/src/datahub/cli/delete_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ def undo_by_filter(
type=str,
help="Urn of the entity to delete, for single entity deletion",
)
@click.option(
"--urn-file",
required=False,
help="Path of file with urns (one per line) to be deleted",
)
@click.option(
"-a",
"--aspect",
Expand Down Expand Up @@ -353,6 +358,7 @@ def undo_by_filter(
@telemetry.with_telemetry()
def by_filter(
urn: Optional[str],
urn_file: Optional[str],
aspect: Optional[str],
force: bool,
soft: bool,
Expand All @@ -373,6 +379,7 @@ def by_filter(
# Validate the cli arguments.
_validate_user_urn_and_filters(
urn=urn,
urn_file=urn_file,
entity_type=entity_type,
platform=platform,
env=env,
Expand Down Expand Up @@ -429,6 +436,12 @@ def by_filter(
batch_size=batch_size,
)
)
elif urn_file:
with open(urn_file, "r") as r:
urns = []
for line in r.readlines():
urn = line.strip().strip('"')
urns.append(urn)
else:
urns = list(
graph.get_urns_by_filter(
Expand Down Expand Up @@ -537,6 +550,7 @@ def process_urn(urn):

def _validate_user_urn_and_filters(
urn: Optional[str],
urn_file: Optional[str],
entity_type: Optional[str],
platform: Optional[str],
env: Optional[str],
Expand All @@ -549,9 +563,9 @@ def _validate_user_urn_and_filters(
raise click.UsageError(
"You cannot provide both an urn and a filter rule (entity-type / platform / env / query)."
)
elif not urn and not (entity_type or platform or env or query):
elif not urn and not urn_file and not (entity_type or platform or env or query):
raise click.UsageError(
"You must provide either an urn or at least one filter (entity-type / platform / env / query) in order to delete entities."
"You must provide either an urn or urn_file or at least one filter (entity-type / platform / env / query) in order to delete entities."
)
elif query:
logger.warning(
Expand Down
1 change: 1 addition & 0 deletions smoke-test/tests/cli/delete_cmd/test_timeseries_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def datahub_delete(auth_session, params: List[str]) -> None:
args: List[str] = ["delete"]
args.extend(params)
args.append("--hard")
logger.info(f"Running delete command with args: {args}")
delete_result: Result = runner.invoke(
datahub,
args,
Expand Down

0 comments on commit 2109abd

Please sign in to comment.