
     g                     v   S r SSKJr  SSKJr  SSKJr  SSKJr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KJ#r#  SSKJ$r$   " S S\RJ                  5      r&g	)zThe BigQuery list CLI command.    )absolute_import)division)print_function)DictOptional)app)flags)overrideN)client_connection)client_data_transfer)client_dataset)
client_job)client_model)client_project)client_reservation)client_routine)client_row_access_policy)client_table)utils)bigquery_command)bq_cached_client)utils_flags)utils_id)bq_error)bq_id_utils)bq_processor_utilsc                      ^  \ rS rSrSrS\S\R                  4U 4S jjrSS\S\	\
   4S jjr\S\\\4   4S	 j5       rS
rU =r$ )ListCmd)   z1ls [(-j|-p|-d)] [-a] [-n <number>] [<identifier>]namefvc                   > [         [        U ]  X5        [        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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%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                  " S0S	S1US9  [        R                  " S2S	S3US9  [        R                  " S4S S5US9  [        R                  " S6S S7US9  [        R                  " S8S S9U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 SAUS9  [        R                  " SBS SCUS9  [        R                  " SDS	SEUS9  U R                  U5        g )FNallzShow all results. For jobs, will show jobs from all users. For datasets, will list hidden datasets.For transfer configs and runs, this flag is redundant and not necessary.a)
short_nameflag_valuesall_jobszDEPRECATED. Use --all instead)r&   jobsFz'Show jobs described by this identifier.jmax_resultszMaximum number to list.nmin_creation_timezDTimestamp in milliseconds. Return jobs created after this timestamp.max_creation_timezETimestamp in milliseconds. Return jobs created before this timestamp.projectszShow all projects.pdatasetsz+Show datasets described by this identifier.dmodelszShow all models.mroutineszShow all routines.row_access_policieszShow all row access policies.transfer_locationz7Location for list transfer config (e.g., "eu" or "us").transfer_configzeShow transfer configurations described by this identifier. This requires setting --transfer_location.transfer_runzList the transfer runs.run_attemptLATESTzFor transfer run, respresents which runs should be pulled. See https://cloud.google.com/bigquery/docs/reference/datatransfer/rest/v1/projects.transferConfigs.runs/list#RunAttempt for detailstransfer_logz%List messages under the run specifiedmessage_typezusage:- messageTypes:INFO For transferlog, represents which messages should be listed. See https://cloud.google.com/bigquery/docs/reference/datatransfer/rest/v1/projects.transferConfigs.runs.transferLogs#MessageSeverity for details.
page_tokenz#Start listing from this page token.kprint_last_tokenz:If true, also print the next page token for the jobs list.print_unreachablezQIf true, also print unreachable locations for the dataset list and the jobs list.filterar  Filters resources based on the filter expression.
For datasets, use a space-separated list of label keys and values in the form "labels.key:value". Datasets must match all provided filter expressions. See https://cloud.google.com/bigquery/docs/filtering-labels#filtering_datasets_using_labels for details
For transfer configurations, the filter expression, in the form "dataSourceIds:value(s)", will show transfer configurations with  the specified dataSourceId. 
For transfer runs, the filter expression, in the form "states:VALUE(s)", will show transfer runs with the specified states. See https://cloud.google.com/bigquery/docs/reference/datatransfer/rest/v1/TransferState for details.
For jobs, the filter expression, in the form "states:VALUE(s)", will show jobs with the specified states. See https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobStatus for details.reservationz9List all reservations for the given project and location.capacity_commitmentzOLists all capacity commitments (e.g. slots) for the given project and location.reservation_assignmentz;List all reservation assignments for given project/locationreservation_groupz?List all reservation groups for the given project and location.reservation_group_nameziReservation group name used as a filter when listing reservation. Used in conjunction with --reservation.parent_job_idzfOnly show jobs which are children of this parent job; if omitted, shows all jobs which have no parent.
connectionz/List all connections for given project/locationmigration_workflowz@List all migration workflows for the given project and location.)	superr   __init__r	   DEFINE_booleanDEFINE_integerDEFINE_stringDEFINE_bool_ProcessCommandRc)selfr    r!   	__class__s      $platform/bq/frontend/command_list.pyrK   ListCmd.__init__,   so   	'4!$+		
 
 
D9r 
1 
! 
N	 
O	 
E/CR 
5 
%+ 
E/R 
'	 
A	 
	5 
8b 
	  
/	 
	  
- 
D	 
	 
	%* 14 
C	 
	 
 E	 
I	 
 	. 
	/ 
9	 
J	 	2    
identifierreturnc                 P!   [         R                  " U R                  U R                  U R                  5      (       a  [
        R                  " S5      eU R                  (       a  U(       a  [
        R                  " S5      eU R                  b  U R                  U l        [        R                  R                  5       nU(       a  [        R                  " X!S9nO [        R                  " X!S9nU R                   (       aK  ["        R$                  " U["        R&                  R(                  SU< S[+        U5      R,                  < 3SS9  O[/        U["        R&                  R(                  5      (       a   [        R0                  " X!S9n["        R$                  " U[+        S5      ["        R&                  R2                  ["        R&                  R4                  4SU< S	[+        U5      R,                  < 3SS9  U R                  (       a9  [/        U["        R&                  R4                  5      (       a  UR7                  5       nU R8                  nSnSnU R                  (       a  ["        R&                  R:                  n[        R6                  " X!S9n["        R$                  " U["        R&                  R2                  S
U< S3SS9  [<        R>                  " U R@                  5      n[B        RD                  " UUU RF                  U R                  UU RH                  U RJ                  UU RL                  S9	nURO                  S5      nGO^U RP                  (       a  ["        R&                  RR                  n[        R0                  " X!S9n[T        RV                  " URY                  5       UU RF                  US9n	SU	;   a  U	S   nSU	;   a  [         RZ                  " U	5        G
OU R\                  (       a  ["        R&                  R^                  n[        R0                  " X!S9n[`        Rb                  " URe                  5       UU RF                  UU R@                  S9n	SU	;   a  U	S   nSU	;   a  [         RZ                  " U	5        G
O%U Rf                  (       a   ["        R&                  Rh                  n[        Rj                  " UU(       a  UOS[l        Rn                  Rp                  SS9n[r        Rt                  " URw                  5       UU RF                  U Rx                  S9n	SU	;   a  U	S   nO[{        S5        SU	;   a  [         RZ                  " U	5        G	OSU R~                  (       a   ["        R&                  R                  n[        R                  " UU[l        Rn                  Rp                  SS9n[r        R                  " URw                  5       UU RF                  U Rx                  S9n	SU	;   a  U	S   nO[{        S5        SU	;   a  [         RZ                  " U	5        GOU R                  (       Gaf  Sn	["        R&                  R                  n[        Rj                  " UU[l        Rn                  Rp                  SS9n  [r        R                  " URw                  5       US9n	U	/nU	(       a'  S U	;   a!  [        U	S    5      nUS!-  n[{        S"U-  5          U R                  b.  [        R                  " [l        R                  R                  5        [r        R                  " URw                  5       UU RF                  U Rx                  U R                  S$9n	S%U	;   a  U	S%   O/ nU(       d  [{        S'5        U	(       a  SU	;   a  [         RZ                  " U	5        GOU R                  (       a  ["        R&                  R                  n[        R                  " UU[l        Rn                  Rp                  SS(9n [        R                  " [l        R                  R                  5        [r        R                  " URw                  5       UU RF                  U Rx                  S)9n	S*U	;   a  U	S*   nO[{        S+5        SU	;   a  [         RZ                  " U	5        GOU R                  (       Ga(  ["        R&                  R                  n[        R6                  " U[        R                  " X!5      S9n["        R$                  " U["        R&                  R2                  S-U< S3SS9  U R                  c  [
        R                  " S.5      e[        R                  " UR                  5       UU R                  U RF                  UU R@                  S/9nU RF                  (       a1  [        U5      S0:X  a"  [        US1   S29n[         RZ                  " U5        US3   nGOU R                  (       a  ["        R&                  R                  nU R                  n[        R                  " X!5      n["        R&                  R                  US49n[        R                  " UR                  5       UUU RF                  U Rx                  U R@                  S59nU RF                  (       a1  [        U5      S0:X  a"  [        US1   S29n[         RZ                  " U5        US3   nGOU R                  (       a  ["        R&                  R                  n[        R                  " X!5      n["        R&                  R                  US69n[        R                  " UR                  5       UU R                  U RF                  U Rx                  S79nU RF                  (       a1  [        U5      S0:X  a"  [        US1   S29n[         RZ                  " U5        US3   nGOU R                  (       a  ["        R&                  R                  n[        R                  " UR                  5       [l        R                  Rp                  [l        Rn                  Rp                  U RF                  U Rx                  S89nS9U;   a  US9   nO[{        S:5        SU;   a  [         RZ                  " U5        GO4U R                   (       az  ["        R&                  R                  n[        R                  " UUU RF                  U Rx                  S;9n	S<U	;   a  U	S<   nO[{        S=5        SU	;   a  [         RZ                  " U	5        GOU R                  (       ad  [l        Rn                  Rp                  (       d  [
        R                  " S>5      eSnU R                  S?S@SA[l        Rn                  Rp                  0SB9  GO4U R                  (       a/  [        R6                  " X!S9n["        R&                  R4                  nOU R                  (       d  UcW  ["        R&                  R2                  nU R                  SCS@5        [        R                  " UR                  U RF                  USD9nO[/        U["        R&                  R2                  5      (       a  ["        R&                  R4                  nOE["        R&                  R(                  n[        R                  " UR                  UU RF                  USE9nU["        R&                  R4                  L ae  U R                  SFS@5        [        R                  " UR                  UUU RF                  U R                  UU R@                  SG9nURO                  SF5      nU(       d"  U R                  (       d  U R                  (       a  Uc   e[         R                  " UUU USH9  gg! [        R                   a    Sn GNf = f! [        R                   a     GNf = f! [|         a#  n
[        R                  " SU< SU
< 35      eSn
A
ff = f! [|         a#  n
[        R                  " SU< SU
< 35      eSn
A
ff = f! [        R                   a     G	NO[|         a#  n
[        R                  " S#U< SU
< 35      eSn
A
ff = f! [|         a#  n
[        R                  " S&U< SU
< 35      eSn
A
ff = f! [|         a#  n
[        R                  " S,U< SU
< 35      eSn
A
ff = f)IaY  List the objects contained in the named collection.

List the objects in the named project or dataset. A trailing : or
. can be used to signify a project or dataset.
 * With -j, show the jobs in the named project.
 * With -p, show all projects.

Examples:
  bq ls
  bq ls -j proj
  bq ls -j --filter:'states:RUNNING,PENDING' proj
  bq ls -p -n 1000
  bq ls mydataset
  bq ls -a
  bq ls -m mydataset
  bq ls --routines mydataset
  bq ls --row_access_policies mytable (requires whitelisting)
  bq ls --filter labels.color:red
  bq ls --filter 'labels.color:red labels.size:*'
  bq ls --transfer_config --transfer_location='us'
      --filter='dataSourceIds:play,adwords'
  bq ls --transfer_run --filter='states:SUCCEEDED,PENDING'
      --run_attempt='LATEST' projects/p/locations/l/transferConfigs/c
  bq ls --transfer_log --message_type='messageTypes:INFO,ERROR'
      projects/p/locations/l/transferConfigs/c/runs/r
  bq ls --capacity_commitment --project_id=proj --location='us'
  bq ls --reservation --project_id=proj --location='us'
  bq ls --reservation_assignment --project_id=proj --location='us'
  bq ls --reservation_assignment --project_id=proj --location='us'
      <reservation_id>
  bq ls --reservation_group --project_id=proj --location='us'
  bq ls --connection --project_id=proj --location=us
  bq ls --migration_workflow --project_id=proj --location=us
z.Cannot specify more than one of -j, -p, or -d.z$Cannot specify an identifier with -pN)id_fallbacksrV   zInvalid identifier "z<" for ls, cannot list row access policies on object of type T)is_usage_errorz-" for ls, cannot call list on object of type z)Cannot determine job(s) associated with "")	bqclient	referencer*   	all_usersstate_filterr,   r-   r=   rG   results)model_clientr]   r*   r=   r2   nextPageToken)routines_api_clientr]   r*   r=   filter_expressionr4   - )rY   rV   default_locationdefault_reservation_id)clientr]   	page_sizer=   assignmentsz!No reservation assignments found.z(Failed to list reservation assignments 'z': )rY   rV   rg   default_capacity_commitment_idcapacityCommitmentszNo capacity commitments found.z%Failed to list capacity commitments ')ri   r]   sizei   @zBI Engine reservation: %sGBz Failed to list BI reservations ')ri   r]   rj   r=   rE   reservationszFailed to list reservations 'zNo reservations found.)rY   rV   rg   default_reservation_group_id)reservation_group_clientr]   rj   r=   reservationGroupszNo reservation groups found.z#Failed to list reservation groups 'z<Cannot determine transfer configuration(s) associated with "z<Need to specify transfer_location for list transfer configs.)transfer_clientr]   locationrj   r=   data_source_ids      )rb   r   )transferConfigName)r*   r=   states)transferRunName)r<   r*   r=   )ri   
project_idrt   r*   r=   connectionszNo connections found.)r\   table_referencerj   r=   rowAccessPolicieszNo row access policies found.z9Need to specify location for listing migration workflows.migration_workflowslsrt   )command_flags_for_this_resourcer.   )	apiclientr*   r=   )r   r]   r*   r=   r0   )r   rY   r]   r*   list_allr=   rd   )objects_listobjects_typepassed_flagsobjects_metadata){frontend_utilsValidateAtMostOneSelectedr)   r/   r1   r   
UsageErrorr'   r$   r   ClientGetbq_client_utilsGetReferencer   BigqueryErrorr5   r   	typecheckApiClientHelperTableReferencetype__name__
isinstanceGetDatasetReferenceProjectReferenceDatasetReferenceGetProjectReferencer>   JobReferencer   ParseStateFilterExpressionrA   r   ListJobsWithTokenAndUnreachabler*   r,   r-   rG   popr3   ModelReferencer   list_modelsGetModelsApiClientPrintPageTokenr4   RoutineReferencer   ListRoutinesGetRoutinesApiClientrD   ReservationAssignmentReferenceGetReservationReferencebq_flagsLOCATIONvaluer   ListReservationAssignmentsGetReservationApiClientr=   printBaseExceptionrC   CapacityCommitmentReferenceGetCapacityCommitmentReferenceListCapacityCommitmentsrB   ReservationReferenceListBiReservationsintBigqueryNotFoundErrorrF   r   fail_if_not_using_alpha_featureAlphaFeaturesRESERVATION_GROUPSListReservationsrE   ReservationGroupReferenceGetReservationGroupReferenceListReservationGroupsr7   TransferConfigReferencefrontend_id_utilsFormatProjectIdentifierr6   r   list_transfer_configsGetTransferV1ApiClientlendictr8   TransferRunReferencer9   FormatDataTransferIdentifierslist_transfer_runsr;   TransferLogReferencelist_transfer_logsr<   rH   ConnectionReferencer   ListConnectionsGetConnectionV1ApiClient
PROJECT_IDRowAccessPolicyReferencer   &list_row_access_policies_with_granteesrI   DelegateToGcloudAndExitPossiblyDelegateToGcloudAndExitr   list_projectsr   r   list_tablesr   #ListDatasetsWithTokenAndUnreachabler?   r@   PrintObjectsArrayWithMetadata)rQ   rV   ri   r]   r=   r`   r   object_typer_   responseesize_in_bytessize_in_gbytestransfer_configsr9   formatted_identifierlist_transfer_runs_resultlist_transfer_log_resultlist_connections_resultss                      rS   RunWithArgsListCmd.RunWithArgs   s   J //GGNNKLLvv*NNABB }} }}df$$((*F!..i#00
	 


%
%
4
4
 i11	3
 	 
I{::II	J	J	%99!)
 
4j))::)):: i11	3
  vv*;..??  //1iJGvv//<<k!55i 


%
%
6
6<F
H	 (BB4;;Ol#CC&&FF# 22 22**
 !$$Y/g	//>>k!55i ))002&&	h 
X	8$	H	$%%h/	//@@k!55i  ,,$99;&& KKh 
x	:&	H	$%%h/		$	$
!11PP#;;%/zS%..44#&	
	 &@@113&&	
 H$]+'
3
4h&

'
'
1
 
	!	!
!11MM#BB!%..44+.	
	 &==113&&	
 !H,23'
0
1h&

'
'
1
 
			h//DDk!99#,,22!$	i
'::335( J'(*hv./-(,>?.
->
?
((477&&99 (88335!(( $ ; ;( +9H*Dh~&"  &'	o1%%h/			//IIk!>>#,,22'*	i
33""55	
 &;;%+%C%C%E&&	
 (*01'
.
/h&

'
'
1
 
			//GGk!55&>>i 


%
%
6
6 
			'nnJ
 	
 .CC 779))$$++ 
		c"23q8(8(;<
%%j1 #g			//DDk$$k.LL
 --EE1 F i
 #7"I"I

'
'
)

&&__# 
		c";<A(A!(DE
%%j1)!,g			//DDk.LL
 --BB. C i
 "6!H!H

'
'
)
((&&__" 
		c":;q@(@(CD
%%j1(+g	//CCk!2!B!B002((..$$**&&__" 
2	2*=9%&	4	4%%&>?		!	!//HHk)PP#$$__	h 
	(./-.	H	$%%h/		 	 $$nnG
 	
 k
""

+5x7H7H7N7N*O # 
 
!55i  //@@k	9$//@@k
**:t<,,$$&&g
 
I{::KK	L	L//@@k//>>k(($$&&	g k11BBB
**:t<'KK$$&&66 KK !$$Z0g$''4+A+A$$$22"+	 ,BO ##  	2 %% 	
	J  
$$AKQO
 	

2  
$$>H!L
 	

. ++  
$$9CQG
 	

*  
$$6@!D
 	

@  
$$<FJ
 	

s   }* 3~ B>~"  B5 5AA@ BAA *BAA8 *~~~~"
,


?::?@AA@	AA@"AA A AAA
AA5AAA0A0AA5A8
AB%BAB B AB%c                 B    S[        U R                  =(       d    S5      0$ )z+Parses command flags from the command line.r*   2   )strr*   )rQ   s    rS   'ParseCommandFlagsSharedWithAllResources/ListCmd.ParseCommandFlagsSharedWithAllResources  s#     	s4++1r2 rU   )r$   ) )r   
__module____qualname____firstlineno__usager   r	   
FlagValuesrK   r   r   r   r
   r   r   __static_attributes____classcell__)rR   s   @rS   r   r   )   sc    
A%L3 LE$4$4 L\FC F# FP tCH~  rU   r   )'__doc__
__future__r   r   r   typingr   r   abslr   r	   typing_extensionsr
   r   clientsr   r   r   r   r   r   r   r   r   r   r   r   frontendr   r   r   r   r   r   r   r   r   BigqueryCmdr    rU   rS   <module>r      sn    $ &  % !   &  % ( "    " & " ,   , % % ,   2   $b
** b
rU   