
    s9                        d 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 ej2                  Zej2                  j4                  Zej2                  j6                  Zej2                  j8                  Zej2                  j:                  Z G d dej<                        Zy)z The show command for the BQ CLI.    )Optional)app)flagsN)client_connection)client_data_transfer)client_dataset)client_deprecated)client_reservation)client_row_access_policy)utils)bigquery_command)bq_cached_client)utils_flags)utils_id)bq_error)bq_id_utilsc                   `     e Zd ZdZdZdedej                  ddf fdZd
dede	e
   fd	Z xZS )Showz5The BQ CLI command to display a resource to the user.zshow [<identifier>]namefvreturnNc                    t         t        |   ||       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|       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 |       t        j                  d!d d"|       t        j                  d#d d$|       t        j
                  d%d g d&d'|       t        j
                  d(d g d)d*|       t        j                  d+d d,|       t        j                  d-d d.|       t        j
                  d/d g d0d1|       t        j                  d2d d3|       | j                  |       y )4NjobFz/If true, interpret this identifier as a job id.j)
short_nameflag_valuesdatasetzShow dataset with this name.dviewz<Show view specific details instead of general table details.)r   materialized_viewzIShow materialized view specific details instead of general table details.table_replicazEShow table replica specific details instead of general table details.schemaz6Show only the schema instead of general table details.encryption_service_accountzUShow the service account for a user if it exists, or create one if it does not exist.transfer_configz<Show transfer configuration for configuration resource name.transfer_runz3Show information about the particular transfer run.modelz)Show details of model with this model ID.mroutinez)Show the details of a particular routine.reservationz?Shows details for the reservation described by this identifier.capacity_commitmentzGShows details for the capacity commitment described by this identifier.reservation_assignmenta  Looks up reservation assignments for a specified project/folder/organization. Explicit reservation assignments will be returned if exist. Otherwise implicit reservation assignments from parents will be returned. Used in conjunction with --job_type, --assignee_type and --assignee_id.reservation_groupzEShows details for the reservation group described by this identifier.job_type)	QUERYPIPELINEML_EXTERNAL
BACKGROUNDSPARK
CONTINUOUSBACKGROUND_CHANGE_DATA_CAPTURE BACKGROUND_COLUMN_METADATA_INDEXBACKGROUND_SEARCH_INDEX_REFRESHa  Type of jobs to search reservation assignment for. Options include:
 QUERY
 PIPELINE
 ML_EXTERNAL
 BACKGROUND
 SPARK
 CONTINUOUS
 BACKGROUND_CHANGE_DATA_CAPTURE
 BACKGROUND_COLUMN_METADATA_INDEX
 BACKGROUND_SEARCH_INDEX_REFRESH
 Used in conjunction with --reservation_assignment.assignee_type)PROJECTFOLDERORGANIZATIONzType of assignees for the reservation assignment. Options include:
 PROJECT
 FOLDER
 ORGANIZATION
 Used in conjunction with --reservation_assignment.assignee_idzxProject/folder/organization ID, to which the reservation is assigned. Used in conjunction with --reservation_assignment.
connectionz>Shows details for the connection described by this identifier.dataset_view)METADATAACLFULLzSpecifies the view that determines which dataset information is returned. By default, metadata and ACL information are returned. Options include:
 METADATA
 ACL
 FULL
 If not set, defaults as FULLmigration_workflowz@Show details of migration workflow described by this identifier.)superr   __init__r   DEFINE_booleanDEFINE_enumDEFINE_string_ProcessCommandRc)selfr   r   	__class__s      $platform/bq/frontend/command_show.pyrC   zShow.__init__&   s   	$tR(	9 
& 
F	 
	 
O	 
@	 
$	  
F	 
=	 
3 
3	 
I	 
	 
 	 
 
O	 

	
D 9< 
-	@
 
 
	= 
H	 
#	*  
J	 	2    
identifierc                    t         j                  j                         }d}d}d}| j                  r2t	        j
                  ||t        j                  j                        }n"| j                  rX| j                  dd|       t	        j                  ||      }t        j                  |j                  || j                        }n| j                   rt	        j"                  ||      }d}n| j$                  rt	        j"                  ||      }d	}np| j&                  rt	        j"                  ||      }d
}nI| j(                  rLt        j*                  j                  dvrt-        j.                  d      t	        j"                  ||      }d}n| j0                  rHt3        j4                  ||      }t7        |      }t9        j:                  |j=                         |      }n| j>                  rHt3        j4                  ||      }tA        |      }t9        jB                  |j=                         |      }nI| jD                  rt	        jF                  ||      }n$| jH                  rt	        jJ                  ||      }n| jL                  rWt	        jN                  ||t        j                  j                        }tQ        jR                  |jU                         |      }n| jV                  rd}|r^tQ        jX                  |jU                         t        j                  j                  | jZ                  | j\                  | j^                        }t`        jb                  je                  dddd      }d}n| jf                  rWt	        jh                  ||t        j                  j                        }tQ        jj                  |jU                         |      }n| jl                  r	 to        jp                  t        jr                  jt                         t	        jv                  ||t        j                  j                        }tQ        jx                  |jU                         |      }n| j                  rl|j                  j                         j                  t	        j                  |      j                        j                         }|d   }
d|
i}t        d      }n| j                  rVt	        j                  ||t        j                  j                        }t        j                  |j                         |      }n9| j                  rd}| j                  dd|       nt	        j                  ||      }|t-        j.                  d      t        |t              rB|s@| j                  dd|       t        j                  |j                  || j                        }	 |7t        j                  |j                  |j                  |j                  |       }t        j                  ||||!       y# tz        $ r }	t}        j~                  d|d|	      d}	~	ww xY w)"a  Show all information about an object.

    Examples:
      bq show -j <job_id>
      bq show dataset
      bq show [--schema] dataset.table
      bq show [--view] dataset.view
      bq show [--materialized_view] dataset.materialized_view
      bq show -m ds.model
      bq show --routine ds.routine
      bq show --transfer_config projects/p/locations/l/transferConfigs/c
      bq show --transfer_run projects/p/locations/l/transferConfigs/c/runs/r
      bq show --encryption_service_account
      bq show --connection --project_id=project --location=us connection
      bq show --capacity_commitment project:US.capacity_commitment_id
      bq show --reservation --location=US --project_id=project reservation_name
      bq show --reservation_assignment --project_id=project --location=US
          --assignee_type=PROJECT --assignee_id=myproject --job_type=QUERY
      bq show --reservation_assignment --project_id=project --location=US
          --assignee_type=FOLDER --assignee_id=123 --job_type=QUERY
      bq show --reservation_assignment --project_id=project --location=US
          --assignee_type=ORGANIZATION --assignee_id=456 --job_type=QUERY
      bq show --reservation_group --location=US --project_id=project
          reservation_group_name
      bq show --migration_workflow projects/p/locations/l/workflows/workflow_id

    Arguments:
      identifier: the identifier of the resource to show.
    showNT)id_fallbacksrL   default_locationdatasets)rO   rL   )	apiclient	referencer=   r   r    r!   )N
prettyjsonjsonz6Table schema output format must be json or prettyjson.r"   )transferConfigName)transferRunName)clientrS   )rX   locationr-   r7   r;    )	projectIdrY   reservationIdreservationAssignmentIdF)reservation_group_clientrS   z!Failed to get reservation group 'z': )rO   )r[   emailServiceAccountIDserviceAccount)ra   migration_workflowsz$Must provide an identifier for show.)rR   get_routines_api_clientget_models_api_clientrS   )custom_formatprint_reference)Wr   ClientGetr   bq_client_utilsGetJobReferencebq_flagsLOCATIONvaluer   PossiblyDelegateToGcloudAndExitGetDatasetReferencer   
GetDatasetrR   r=   r   GetTableReferencer    r!   r"   FORMATr   
UsageErrorr$   frontend_id_utilsFormatDataTransferIdentifiersTransferConfigReferencer   get_transfer_configGetTransferV1ApiClientr%   TransferRunReferenceget_transfer_runr'   GetModelReferencer(   GetRoutineReferencer)   GetReservationReferencer
   GetReservationGetReservationApiClientr+   SearchAllReservationAssignmentsr-   r7   r;   ApiClientHelperReservationAssignmentReferenceCreater*   GetCapacityCommitmentReferenceGetCapacityCommitmentr,   r   fail_if_not_using_alpha_featureAlphaFeaturesRESERVATION_GROUPSGetReservationGroupReferenceGetReservationGroupBaseExceptionr   BigqueryErrorr#   projectsgetServiceAccountGetProjectReferencer[   executeEncryptionServiceAccountr<   GetConnectionReferencer   GetConnectionGetConnectionV1ApiClientrA   DelegateToGcloudAndExitGetReference
isinstanceDatasetReferencer	   get_object_infoGetRoutinesApiClientGetModelsApiClientbq_frontend_utilsPrintObjectInfo)rH   rL   rX   re   object_inforf   rS   formatted_identifiersearch_all_projectser_   s              rJ   RunWithArgszShow.RunWithArgs   s   > $$((*FMKOvv!11#,,22i
 

**:vzJ!55*i #--$$((k
 
!33*i m			!33*i *m			!33*i &m				&B	BnnD
 	
 "33*i m			.LL
* *1i )<<

'
'
)+?k 
		.LL
* '7KLi(99

'
'
)+?k 
!33*i 
!55*i 
		!99#,,22i
 '55//1Yk 
	$	$ 	(HH113&&,,]],,((
 "@@GG"%	 H i o		!	!!@@#,,22i
 '<<//1k 
		
33""55	
 $@@!%..44
	
 )<<%+%C%C%E
 
	(	(



#
#
%';;%	  
 79  '"e'/k*:JKi	!88#,,22i
 &33002ik 
	 	 i
""


 "..*i NNABB)-.{
**:vzJ"--$$((k
 %55$$"("="= & 9 9	k %%#'	s  
$$:DaH
 	

s   .BY 	Y*
Y%%Y*) )__name__
__module____qualname____doc__usagestrr   
FlagValuesrC   r   intr   __classcell__)rI   s   @rJ   r   r   !   sJ    =
#%p3 pE$4$4 p pdYC Y# YrK   r   ) r   typingr   abslr   r   rk   clientsr   r   r   r	   r
   r   r   ri   frontendr   r   r   r   r   rt   r   r   r   r   rv   ry   r   BigqueryCmdr    rK   rJ   <module>r      s    &     % ( " % & , , % % /   2   --..?? %55MM "22GG &66OO P'' PrK   