
    G6                     N   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
r
SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr   " S S\R@                  5      r!g)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                   h   ^  \ rS rSrSrSrS\S\R                  4U 4S jjr	S\S\
\   4S	 jrS
rU =r$ )Delete%   zThe Delete CLI command.z#rm [-f] [-r] [(-d|-t)] <identifier>namefvc                   > [         [        U ]  X5        [        R                  " SSSSUS9  [        R                  " SSSSUS9  [        R                  " S	SS
SUS9  [        R                  " SSSUS9  [        R                  " SS SSUS9  [        R                  " SSSSUS9  [        R                  " SSSUS9  [        R                  " SSSUS9  [        R                  " SSSUS9  [        R                  " SSSUS9  [        R                  " SSSSUS9  [        R                  " S SS!US9  [        R                  " S"SS#US9  [        R                  " S$SS%US9  U R                  U5        g )&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.pyr6   Delete.__init__*   s   	&$ *	6 
4 
2 
E	 
< 
7 
?	 
G	 
 *	 
B	 
* 
5@b 
e3 
&	 	2    
identifierreturnc                    [         R                  R                  5       n[        R                  " U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  5
      (       a  [        R                   " S5      eU(       d  [        R                   " S5      eU R                  (       a  ["        R$                  " X!S9nGOU R&                  (       a  ["        R(                  " X!S9nGOU R                  (       a  ["        R*                  " X!S9nGOU R
                  (       a  ["        R,                  " X!S9nGOdU R                  (       a0  ["        R.                  " UU[0        R2                  R4                  S9nGO#U R                  (       a5  [6        R8                  " X!5      n[:        R<                  R?                  US9nGOU R                  (       ab   ["        R@                  " UU[0        R2                  R4                  S9n[B        RD                  " URG                  5       US9  [I        SU-  5        GOjU R                  (       ab   ["        RP                  " UU[0        R2                  R4                  S9n[B        RR                  " URG                  5       US9  [I        SU-  5        GOU R                  (       am   ["        RT                  " UU[0        R2                  R4                  S9n[B        RV                  " URG                  5       UU RX                  S9  [I        SU-  5        GOyU R                  (       a   [Z        R\                  " [0        R^                  R`                  5        ["        Rb                  " UU[0        R2                  R4                  S9n[B        Rd                  " URG                  5       US9  [I        SU-  5        OU R                  (       aR  ["        Rf                  " UU[0        R2                  R4                  S9n[h        Rj                  " URm                  5       US9  OvU Rn                  (       a  UnOb["        Rp                  " X!S9n[:        Rr                  " U[:        R<                  Rt                  [:        R<                  Rv                  4SU< S3SS9  [y        U[:        R<                  Rv                  5      (       a+  U Rz                  (       a  [        R                   " SU< 35      e[y        U[:        R<                  R|                  5      (       a+  U Rz                  (       a  [        R                   " SU< 35      e[y        U[:        R<                  R~                  5      (       a+  U Rz                  (       a  [        R                   " SU< 35      eU Rn                  (       a+  U Rz                  (       a  [        R                   " SU< 35      eU RX                  (       Gd  [y        U[:        R<                  Rt                  5      (       a%  [        R                  " UR                  US9(       Gd  [y        U[:        R<                  Rv                  5      (       a%  [        R                  " UR                  US9(       GdK  [y        U[:        R<                  R                  5      (       a  [        R                  " X#5      (       Gd  [y        U[:        R<                  R|                  5      (       a(  [        R                  " UR                  5       US9(       d  [y        U[:        R<                  R~                  5      (       a(  [        R                  " UR                  5       US9(       dd  [y        U[:        R<                  R>                  5      (       a*  [        R                  " UR                  5       U5      (       d  U Rn                  (       a0  S[        R                  " SU< S35      :w  a  [I        SU< S35        g [y        U[:        R<                  Rt                  5      (       aT  U R                  S!S"US#U R                  0S$9  [        R                  " UR                  UU RX                  U R                  S%9  g
[y        U[:        R<                  Rv                  5      (       a+  [        R                  " UR                  UU RX                  S&9  g
[y        U[:        R<                  R                  5      (       a   [        R                  " X#U RX                  S'9  g
[y        U[:        R<                  R|                  5      (       a/  [        R                  " UR                  5       UU RX                  S(9  g
[y        U[:        R<                  R~                  5      (       a/  [        R                  " UR                  5       UU RX                  S)9  g
[y        U[:        R<                  R>                  5      (       a/  [        R                  " UR                  5       UU RX                  S'9  g
U Rn                  (       a  U R                  S*S"U5        g
g
! [J         a#  n[L        RN                  " SU< S	U< 35      eS
nAff = f! [J         a#  n[L        RN                  " SU< S	U< 35      eS
nAff = f! [J         a#  n[L        RN                  " SU< S	U< 35      eS
nAff = f! [J         a#  n[L        RN                  " SU< S	U< 35      eS
nAff = f)+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>   )rA   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 ')rD   rE   r(   z.Capacity commitment '%s' successfully deleted.z&Failed to delete capacity commitment ')reservation_group_clientrE   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 )	apiclientrE   )model_clientrE   )routines_api_clientrE   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)rH   rE   rQ   )rQ   )rI   rE   rQ   )rJ   rE   rQ   migration_workflows)[r   ClientGetfrontend_utilsValidateAtMostOneSelectedr    r$   r&   r2   r'   r,   r.   r-   r/   r3   r   
UsageErrorbq_client_utilsGetTableReferencer1   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GetConnectionV1ApiClientr4   GetReference	typecheckDatasetReferenceTableReference
isinstancer+   ModelReferenceRoutineReferencer   DatasetExistsrH   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)r9   r>   rD   rE   formatted_identifieres         r;   RunWithArgsDelete.RunWithArgs   s   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IFFNN)EFF 	9k99HHIIFFNN)EFF 	9k99JJKKFFNN)EFF466NN)EFF::: [88II  !..",,	 
 K$?$?$N$NOO++",,	 
 K$?$?$L$LMM&&v99 K$?$?$N$NO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J
**+6*G	 +  ""



::..	 
I{::II	J	J$$::
 
I{::GG	H	H6tzzJ	I{::II	J	J002::
 
I{::KK	L	L""$99;::
 
;..FF
 
 11

'
'
)
::
 
	 	 
""


 
!I  
$$7A1E
 	

  
$$BLaP
 	

"  
$$?I1M
 	

*  
$$=GK
 	

sd   Aj Aj3 5A*k# 3Bl 
j0j++j03
k =kk #
l-ll
m l;;m  )__name__
__module____qualname____firstlineno____doc__usagestrr   
FlagValuesr6   r   intr   __static_attributes____classcell__)r:   s   @r;   r   r   %   sH    
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   rY   frontendr   r   rV   r   r   rb   r   r   BigqueryCmdr   r   r=   r;   <module>r      se    & &  %     % ( "    & " ,   , % % ,   2  |)) |r=   