feat(cli/delete): add --urn-file option (#12247)

Co-authored-by: Sergio Gómez Villamor <sgomezvillamor@gmail.com>
This commit is contained in:
Aseem Bansal 2025-01-20 22:32:43 +05:30 committed by GitHub
parent 7ac6523b2d
commit 2109abdc1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -265,6 +265,11 @@ def undo_by_filter(
type=str, type=str,
help="Urn of the entity to delete, for single entity deletion", 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( @click.option(
"-a", "-a",
"--aspect", "--aspect",
@ -353,6 +358,7 @@ def undo_by_filter(
@telemetry.with_telemetry() @telemetry.with_telemetry()
def by_filter( def by_filter(
urn: Optional[str], urn: Optional[str],
urn_file: Optional[str],
aspect: Optional[str], aspect: Optional[str],
force: bool, force: bool,
soft: bool, soft: bool,
@ -373,6 +379,7 @@ def by_filter(
# Validate the cli arguments. # Validate the cli arguments.
_validate_user_urn_and_filters( _validate_user_urn_and_filters(
urn=urn, urn=urn,
urn_file=urn_file,
entity_type=entity_type, entity_type=entity_type,
platform=platform, platform=platform,
env=env, env=env,
@ -429,6 +436,12 @@ def by_filter(
batch_size=batch_size, 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: else:
urns = list( urns = list(
graph.get_urns_by_filter( graph.get_urns_by_filter(
@ -537,6 +550,7 @@ def _delete_urns_parallel(
def _validate_user_urn_and_filters( def _validate_user_urn_and_filters(
urn: Optional[str], urn: Optional[str],
urn_file: Optional[str],
entity_type: Optional[str], entity_type: Optional[str],
platform: Optional[str], platform: Optional[str],
env: Optional[str], env: Optional[str],
@ -549,9 +563,9 @@ def _validate_user_urn_and_filters(
raise click.UsageError( raise click.UsageError(
"You cannot provide both an urn and a filter rule (entity-type / platform / env / query)." "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( 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: elif query:
logger.warning( logger.warning(

View File

@ -97,6 +97,7 @@ def datahub_delete(auth_session, params: List[str]) -> None:
args: List[str] = ["delete"] args: List[str] = ["delete"]
args.extend(params) args.extend(params)
args.append("--hard") args.append("--hard")
logger.info(f"Running delete command with args: {args}")
delete_result: Result = runner.invoke( delete_result: Result = runner.invoke(
datahub, datahub,
args, args,