
    G6                     N   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
Z
dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ  G d dej@                        Z!y)z The BigQuery delete CLI command.    )absolute_import)division)print_function)Optional)app)flagsN)client_connection)client_data_transfer)client_dataset)
client_job)client_model)client_reservation)client_routine)client_row_access_policy)client_table)utils)bigquery_command)bq_cached_client)utils_flags)utils_id)bq_error)bq_id_utilsc                   Z     e Zd ZdZdZdedej                  f fdZdede	e
   fdZ xZS )	DeletezThe Delete CLI command.z#rm [-f] [-r] [(-d|-t)] <identifier>namefvc                    t         t        |   ||       t        j                  dddd|       t        j                  dddd|       t        j                  d	dd
d|       t        j                  ddd|       t        j                  dd dd|       t        j                  dddd|       t        j                  ddd|       t        j                  ddd|       t        j                  ddd|       t        j                  ddd|       t        j                  dddd|       t        j                  d dd!|       t        j                  d"dd#|       t        j                  d$dd%|       | j                  |       y )&NdatasetFz,Remove dataset described by this identifier.d)
short_nameflag_valuestablez*Remove table described by this identifier.tjobz(Remove job described by this identifier.jtransfer_configz;Remove transfer configuration described by this identifier.)r!   forcez2Ignore existing tables and datasets, don't prompt.f	recursivez-Remove dataset and any tables it may contain.rreservationz5Deletes the reservation described by this identifier.capacity_commitmentz=Deletes the capacity commitment described by this identifier.reservation_assignmentz Delete a reservation assignment.reservation_groupz8Delete a reservation group described by this identifier.modelz Remove model with this model ID.mroutinez$Remove routine with this routine ID.
connectionzDelete a connection.migration_workflowzDelete a migration workflow.)superr   __init__r   DEFINE_boolean_ProcessCommandRc)selfr   r   	__class__s      &platform/bq/frontend/command_delete.pyr5   zDelete.__init__*   s   	&$ r*	6 
4 
2 
E	 
< 
7 
?	 
G	 
 *	 
B	 
* 
5@b 
e3 
&	 	2    
identifierreturnc                    t         j                  j                         }t        j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  
      rt        j                   d      |st        j                   d      | j                  rt#        j$                  ||      }n| j&                  rt#        j(                  ||      }n| j                  rt#        j*                  ||      }n}| j
                  rt#        j,                  ||      }nX| j                  r2t#        j.                  ||t0        j2                  j4                        }n| j                  r8t7        j8                  ||      }t:        j<                  j?                  |      }n| j                  rf	 t#        j@                  ||t0        j2                  j4                        }tC        jD                  |jG                         |       tI        d|z         nd| j                  rf	 t#        jP                  ||t0        j2                  j4                        }tC        jR                  |jG                         |       tI        d|z         n| j                  rq	 t#        jT                  ||t0        j2                  j4                        }tC        jV                  |jG                         || jX                         tI        d|z         nu| j                  r	 t[        j\                  t0        j^                  j`                         t#        jb                  ||t0        j2                  j4                        }tC        jd                  |jG                         |       tI        d|z         n| j                  rVt#        jf                  ||t0        j2                  j4                        }ti        jj                  |jm                         |       nu| jn                  r|}nft#        jp                  ||      }t;        jr                  |t:        j<                  jt                  t:        j<                  jv                  fd|dd       ty        |t:        j<                  jv                        r$| jz                  rt        j                   d|      ty        |t:        j<                  j|                        r$| jz                  rt        j                   d|      ty        |t:        j<                  j~                        r$| jz                  rt        j                   d|      | jn                  r$| jz                  rt        j                   d|      | jX                  sty        |t:        j<                  jt                        r"t        j                  |j                  |      sfty        |t:        j<                  jv                        r"t        j                  |j                  |      s ty        |t:        j<                  j                        rt        j                  ||      sty        |t:        j<                  j|                        r%t        j                  |j                         |      sty        |t:        j<                  j~                        r%t        j                  |j                         |      sTty        |t:        j<                  j>                        r$t        j                  |j                         |      s| jn                  r,dt        j                  d|d      k7  rtI        d|d       y ty        |t:        j<                  jt                        rY| j                  d!d"|d#| j                  i$       t        j                  |j                  || jX                  | j                  %       y
ty        |t:        j<                  jv                        r-t        j                  |j                  || jX                  &       y
ty        |t:        j<                  j                        r#t        j                  ||| jX                  '       y
ty        |t:        j<                  j|                        r1t        j                  |j                         || jX                  (       y
ty        |t:        j<                  j~                        r1t        j                  |j                         || jX                  )       y
ty        |t:        j<                  j>                        r1t        j                  |j                         || jX                  '       y
| jn                  r| j                  d*d"|       y
y
# tJ        $ r }tM        jN                  d|d	|      d
}~ww xY w# tJ        $ r }tM        jN                  d|d	|      d
}~ww xY w# tJ        $ r }tM        jN                  d|d	|      d
}~ww xY w# tJ        $ r }tM        jN                  d|d	|      d
}~ww xY w)+a  Delete the resource described by the identifier.

    Always requires an identifier, unlike the show and ls commands.
    By default, also requires confirmation before deleting. Supports
    the -d -t flags to signify that the identifier is a dataset
    or table.
     * With -f, don't ask for confirmation before deleting.
     * With -r, remove all tables in the named dataset.

    Examples:
      bq rm ds.table
      bq rm -m ds.model
      bq rm --routine ds.routine
      bq rm -r -f old_dataset
      bq rm --transfer_config=projects/p/locations/l/transferConfigs/c
      bq rm --connection --project_id=proj --location=us con
      bq rm --capacity_commitment proj:US.capacity_commitment_id
      bq rm --reservation --project_id=proj --location=us reservation_name
      bq rm --reservation_assignment --project_id=proj --location=us
          assignment_name
      bq rm --reservation_group --project_id=proj --location=us
          reservation_group_name
    z+Cannot specify more than one resource type.z"Must provide an identifier for rm.)id_fallbacksr<   )r?   r<   default_location)transferConfigName)client	referencez&Reservation '%s' successfully deleted.zFailed to delete reservation 'z': Nz1Reservation assignment '%s' successfully deleted.z)Failed to delete reservation assignment ')rB   rC   r'   z.Capacity commitment '%s' successfully deleted.z&Failed to delete capacity commitment ')reservation_group_clientrC   z,Reservation group '%s' successfully deleted.z$Failed to delete reservation group 'zInvalid identifier "z	" for rm.T)is_usage_errorzCannot specify -r with )	apiclientrC   )model_clientrC   )routines_api_clientrC   yzrm: remove z? (y/N) zNOT deleting z
, exiting.r   datasetsrmr)   )resource
bq_commandr<   command_flags_for_this_resource)ignore_not_founddelete_contents)rF   rC   rO   )rO   )rG   rC   rO   )rH   rC   rO   migration_workflows)[r   ClientGetfrontend_utilsValidateAtMostOneSelectedr   r#   r%   r1   r&   r+   r-   r,   r.   r2   r   
UsageErrorbq_client_utilsGetTableReferencer0   GetModelReferenceGetRoutineReferenceGetDatasetReferenceGetJobReferencebq_flagsLOCATIONvaluefrontend_id_utilsFormatDataTransferIdentifiersr   ApiClientHelperTransferConfigReferenceGetReservationReferencer   DeleteReservationGetReservationApiClientprintBaseExceptionr   BigqueryError!GetReservationAssignmentReferenceDeleteReservationAssignmentGetCapacityCommitmentReferenceDeleteCapacityCommitmentr'   r   fail_if_not_using_alpha_featureAlphaFeaturesRESERVATION_GROUPSGetReservationGroupReferenceDeleteReservationGroupGetConnectionReferencer	   DeleteConnectionGetConnectionV1ApiClientr3   GetReference	typecheckDatasetReferenceTableReference
isinstancer*   ModelReferenceRoutineReferencer   DatasetExistsrF   r   table_existsJobReferencer   	JobExistsr   model_existsGetModelsApiClientr   RoutineExistsGetRoutinesApiClientr
   transfer_existsGetTransferV1ApiClientPromptYNPossiblyDelegateToGcloudAndExitr)   DeleteDatasetdelete_table	DeleteJobdelete_modelDeleteRoutinedelete_transfer_configDelegateToGcloudAndExit)r8   r<   rB   rC   formatted_identifieres         r:   RunWithArgszDelete.RunWithArgs   sp   2 $$((*F //##   NNHIINN?@@vv!33*i 
!33*i 
!55*i 
!55*i 
!11#,,22i
 
		.LL
* --EE1 F i 
		
#;;!%..44
	
 	,,113	
 	6CD
 
	$	$
#EE!%..44
	
 	66113y	
 	AJNO
 
	!	!
#BB!%..44
	
 	33113**	

 	>KL
 
		
33""55	
 $@@!%..44
	
 	11%+%C%C%E	
 	<zIJ
 
!88#,,22i
 ((002i 
	 	 i!..*i 
))::))88 0:
; 	9k99HHIFFNN)EFF 	9k99HHIFFNN)EFF 	9k99JJKFFNN)EFF466NN)EFF:: [88II !..",,	
 K$?$?$N$NO++",,	
 K$?$?$L$LM&&vy9 K$?$?$N$NO++%88:i
 [88II !..&,&A&A&C% [88PP '66//19 $$.))'02
 
 y:
;)[88IIJ
**+6*G	 +  ""



::..	 
I{::II	J$$::
 
I{::GG	H69tzzJ	I{::II	J002::
 
I{::KK	L""$99;::
 
;..FF
 11

'
'
)
::
 
	 	 
""


 
!I  
$$7A1E
 	

  
$$BLaP
 	

"  
$$?I1M
 	

*  
$$=GK
 	

sd   0A#g "A#h A.h3 Bi 	h$g??h	h0h++h03	i<ii	j(jj)__name__
__module____qualname____doc__usagestrr   
FlagValuesr5   r   intr   __classcell__)r9   s   @r:   r   r   %   sB    
3%V3 VE$4$4 Vp_C _HSM _r;   r   )"r   
__future__r   r   r   typingr   abslr   r   r]   clientsr	   r
   r   r   r   r   r   r   r   r   rW   frontendr   r   rT   r   r   r`   r   r   BigqueryCmdr    r;   r:   <module>r      se    & &  %     % ( "    & " ,   , % % ,   2  |)) |r;   