@@ -265,6 +265,9 @@ def undo_by_filter(
265
265
type = str ,
266
266
help = "Urn of the entity to delete, for single entity deletion" ,
267
267
)
268
+ @click .option (
269
+ "--urn-file" , required = True , help = "Absolute path of file with urns to be deleted"
270
+ )
268
271
@click .option (
269
272
"-a" ,
270
273
"--aspect" ,
@@ -353,6 +356,7 @@ def undo_by_filter(
353
356
@telemetry .with_telemetry ()
354
357
def by_filter (
355
358
urn : Optional [str ],
359
+ urn_file : Optional [str ],
356
360
aspect : Optional [str ],
357
361
force : bool ,
358
362
soft : bool ,
@@ -373,6 +377,7 @@ def by_filter(
373
377
# Validate the cli arguments.
374
378
_validate_user_urn_and_filters (
375
379
urn = urn ,
380
+ urn_file = urn_file ,
376
381
entity_type = entity_type ,
377
382
platform = platform ,
378
383
env = env ,
@@ -407,11 +412,27 @@ def by_filter(
407
412
logger .info (f"Using { graph } " )
408
413
409
414
# Determine which urns to delete.
410
- delete_by_urn = bool (urn ) and not recursive
411
415
if urn :
412
416
urns = [urn ]
413
-
414
- if recursive :
417
+ elif urn_file :
418
+ with open (urn_file , "r" ) as r :
419
+ urns = []
420
+ for line in r .readlines ():
421
+ urn = line .strip ().strip ('"' )
422
+ urns .append (urn )
423
+ else :
424
+ urns = list (
425
+ graph .get_urns_by_filter (
426
+ entity_types = [entity_type ] if entity_type else None ,
427
+ platform = platform ,
428
+ env = env ,
429
+ query = query ,
430
+ status = soft_delete_filter ,
431
+ batch_size = batch_size ,
432
+ )
433
+ )
434
+ if recursive :
435
+ for urn in urns :
415
436
# Add children urns to the list.
416
437
if guess_entity_type (urn ) == "dataPlatformInstance" :
417
438
urns .extend (
@@ -429,25 +450,15 @@ def by_filter(
429
450
batch_size = batch_size ,
430
451
)
431
452
)
432
- else :
433
- urns = list (
434
- graph .get_urns_by_filter (
435
- entity_types = [entity_type ] if entity_type else None ,
436
- platform = platform ,
437
- env = env ,
438
- query = query ,
439
- status = soft_delete_filter ,
440
- batch_size = batch_size ,
441
- )
453
+ if len (urns ) == 0 :
454
+ click .echo (
455
+ "Found no urns to delete. Maybe you want to change your filters to be something different?"
442
456
)
443
- if len (urns ) == 0 :
444
- click .echo (
445
- "Found no urns to delete. Maybe you want to change your filters to be something different?"
446
- )
447
- return
457
+ return
448
458
459
+ delete_by_urn = len (urns ) == 1
449
460
# Print out a summary of the urns to be deleted and confirm with the user.
450
- if not delete_by_urn :
461
+ if delete_by_urn :
451
462
urns_by_type : Dict [str , List [str ]] = {}
452
463
for urn in urns :
453
464
entity_type = guess_entity_type (urn )
@@ -537,6 +548,7 @@ def process_urn(urn):
537
548
538
549
def _validate_user_urn_and_filters (
539
550
urn : Optional [str ],
551
+ urn_file : Optional [str ],
540
552
entity_type : Optional [str ],
541
553
platform : Optional [str ],
542
554
env : Optional [str ],
@@ -549,9 +561,9 @@ def _validate_user_urn_and_filters(
549
561
raise click .UsageError (
550
562
"You cannot provide both an urn and a filter rule (entity-type / platform / env / query)."
551
563
)
552
- elif not urn and not (entity_type or platform or env or query ):
564
+ elif not urn and not urn_file and not (entity_type or platform or env or query ):
553
565
raise click .UsageError (
554
- "You must provide either an urn or at least one filter (entity-type / platform / env / query) in order to delete entities."
566
+ "You must provide either an urn or urn file path or at least one filter (entity-type / platform / env / query) in order to delete entities."
555
567
)
556
568
elif query :
557
569
logger .warning (
0 commit comments