From 2109abdc1a1de5fe711900ee47e5f5891d2c59dc Mon Sep 17 00:00:00 2001 From: Aseem Bansal Date: Mon, 20 Jan 2025 22:32:43 +0530 Subject: [PATCH] feat(cli/delete): add --urn-file option (#12247) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sergio Gómez Villamor --- .../src/datahub/cli/delete_cli.py | 18 ++++++++++++++++-- .../cli/delete_cmd/test_timeseries_delete.py | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/metadata-ingestion/src/datahub/cli/delete_cli.py b/metadata-ingestion/src/datahub/cli/delete_cli.py index 8501cf71f0d544..f77156b4bd7544 100644 --- a/metadata-ingestion/src/datahub/cli/delete_cli.py +++ b/metadata-ingestion/src/datahub/cli/delete_cli.py @@ -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", @@ -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, @@ -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, @@ -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( @@ -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], @@ -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( diff --git a/smoke-test/tests/cli/delete_cmd/test_timeseries_delete.py b/smoke-test/tests/cli/delete_cmd/test_timeseries_delete.py index 99ed790f25ffd7..745224a099fc53 100644 --- a/smoke-test/tests/cli/delete_cmd/test_timeseries_delete.py +++ b/smoke-test/tests/cli/delete_cmd/test_timeseries_delete.py @@ -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,