
                             S 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\R"                  5      rg)zThe BigQuery CLI head command.    )Optional)app)flagsN)
client_job)client_table)utils)bigquery_command)bq_cached_client)bq_id_utilsc                   h   ^  \ 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	rU =r$ )Head   z+head [-n <max rows>] [-j] [-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SUS9  [        R                  " SS SSUS9  U R                  U5        g )NjobFz!Reads the results of a query job.j)
short_nameflag_valuestablezReads rows from a table.t	start_rowr   z5The number of rows to skip before showing table data.smax_rowsd   z4The number of rows to print when showing table data.nselected_fieldszA subset of fields (including nested fields) to return when showing table data. If not specified, full row will be retrieved. For example, "-c:a,b".c)superr   __init__r   DEFINE_booleanDEFINE_integerDEFINE_string_ProcessCommandRc)selfr   r   	__class__s      $platform/bq/frontend/command_head.pyr    Head.__init__   s    	$t(	+ 
" 
	? 
> 
	!  	2    
identifierreturnc           	         [         R                  R                  5       nU R                  (       a'  U R                  (       a  [
        R                  " S5      eU R                  (       a/  [        R                  " UU[        R                  R                  S9nO[        R                  " X!S9nSn[        U[        R                  R                   5      (       a7  ["        R$                  " U['        U5      U R(                  U R*                  S9u  pVO[        U[        R                  R,                  5      (       aN  [.        R0                  " UR2                  UU R(                  U R*                  U R4                  UR6                  S9u  pVO[
        R                  " SU< S35      e[         R8                  R:                  R=                  5       R?                  XVUS	9  g
)zDisplays rows in a table.

Examples:
  bq head dataset.table
  bq head -j job
  bq head -n 10 dataset.table
  bq head -s 5 -n 10 dataset.table
zCannot specify both -j and -t.)id_fallbacksr*   default_location)r-   r*   F)r   r   )	apiclient	table_refr   r   r   max_rows_per_requestzInvalid identifier 'z' for head.)use_full_timestampN) r
   ClientGetr   r   r   
UsageErrorbq_client_utilsGetJobReferencebq_flagsLOCATIONvalueGetTableReference
isinstancer   ApiClientHelperJobReferencer   ReadSchemaAndJobRowsdictr   r   TableReferencer   read_schema_and_rowsr/   r   r1   FactoryClientTablePrinterGetTablePrinter
PrintTable)r%   r*   client	referencer2   fieldsrowss          r'   RunWithArgsHead.RunWithArgsC   s_    $$((*Fvv$&&NN;<<vv!11#,,22i "33i )[88EEFF44

y/FF66	lfd 
I{::II	J	J!66$$FF66&&%::lfd NN*NOO//??ALL); M r)    ) )__name__
__module____qualname____firstlineno__usagestrr   
FlagValuesr    r   intrK   __static_attributes____classcell__)r&   s   @r'   r   r      s>    
;%'3 'E$4$4 'R0C 0# 0 0r)   r   )__doc__typingr   abslr   r   r8   clientsr   r   r   r6   frontendr	   r
   frontend_flagsr   BigqueryCmdr   rM   r)   r'   <module>r`      s>    $        , % % , \'' \r)   