
    [                         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	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 CLI extract command.    )absolute_import)division)print_function)Optional)flagsN)
client_job)utils)bigquery_command)bq_cached_client)utils_flags)utils_formattingc                   h   ^  \ rS rSrSrS\S\R                  4U 4S jjrS\S\S\	\
   4S	 jrS
rU =r$ )Extract   z)extract <source_table> <destination_uris>namefvc                    > [         [        U ]  X5        [        R                  " SS SSUS9  [        R
                  " SS / SQSUS9  [        R                  " S	S S
US9  [        R                  " SS SUS9  [        R
                  " SS/ SQ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                  " US9U l
        U R                  U5        g )Nfield_delimiterzThe character that indicates the boundary between columns in the output file. "\t" and "tab" are accepted names for tab. Not applicable when extracting models.F)
short_nameflag_valuesdestination_format)CSVNEWLINE_DELIMITED_JSONAVROPARQUETML_TF_SAVED_MODELML_XGBOOST_BOOSTERae  The extracted file format. Format CSV, NEWLINE_DELIMITED_JSON, PARQUET and AVRO are applicable for extracting tables. Formats ML_TF_SAVED_MODEL and ML_XGBOOST_BOOSTER are applicable for extracting models. The default value for tables is CSV. Tables with nested or repeated fields cannot be exported as CSV. The default value for models is ML_TF_SAVED_MODEL.)r   trial_idz1-based ID of the trial to be exported from a hyperparameter tuning model. The default_trial_id will be exported if not specified. This does not apply for models not trained with hyperparameter tuning.add_serving_default_signaturezXWhether to add serving_default signature for export BigQuery ML trained tf based models.compressionNONE)GZIPDEFLATESNAPPYZSTDr"   zThe compression type to use for exported files. Possible values include GZIP, DEFLATE, SNAPPY, ZSTD, and NONE. The default value is None. Not applicable when extracting models.print_headerz|Whether to print header rows for formats that have headers. Prints headers by default.Not applicable when extracting models.use_avro_logical_typesa  If destinationFormat is set to "AVRO", this flag indicates whether to enable extracting applicable column types (such as TIMESTAMP) to their corresponding AVRO logical types (timestamp-micros), instead of only using their raw types (avro-long). Not applicable when extracting models.modelFz!Extract model with this model ID.m)superr   __init__r   DEFINE_stringDEFINE_enumDEFINE_integerDEFINE_booleanfrontend_flagsdefine_reservation_id_for_a_jobreservation_id_for_a_job_flag_ProcessCommandRc)selfr   r   	__class__s      'platform/bq/frontend/command_extract.pyr,   Extract.__init__   sA   	'4!$+		1  
	
	1 #& 
	L  
'	# 
5	7  
	1  
 	1
 	 
+ 	662F 	& 	2    
identifierdestination_urisreturnc                 n   [         R                  R                  5       nS[        R                  " 5       0n[
        R                  R                  (       a  [
        R                  R                  US'   U R                  R                  (       a  U R                  R                  US'   U R                  (       a  [        R                  " X1S9nO[        R                  " X1S9n[        R                  " UUU4U R                   ["        R$                  " U R&                  5      U R(                  U R*                  U R,                  U R.                  U R0                  S.UD6n[
        R2                  R                  (       a+  ["        R4                  " [6        R8                  " U5      5        gU R;                  U5        g)a  Perform an extract operation of source into destination_uris.

Usage:
  extract <source_table> <destination_uris>

Use -m option to extract a source_model.

Examples:
  bq extract ds.table gs://mybucket/table.csv
  bq extract -m ds.model gs://mybucket/model

Arguments:
  source_table: Source table to extract.
  source_model: Source model to extract.
  destination_uris: One or more Google Cloud Storage URIs, separated by
    commas.
job_idlocationreservation_id)id_fallbacksr:   )r'   r   r   r   r    r!   r(   N)r   ClientGetr   get_job_id_from_flagsbq_flagsLOCATIONvaluer3   presentr*   bq_client_utilsGetModelReferenceGetTableReferencer   r   r'   frontend_utilsNormalizeFieldDelimiterr   r   r   r    r!   r(   SYNCHRONOUS_MODEPrintJobMessagesr   format_job_infoPrintJobStartInfo)r5   r:   r;   clientkwds	referencejobs          r7   RunWithArgsExtract.RunWithArgsr   s[   ( $$((*F+335D !**00d:))11#AAGGdvv!33i "33i 

 &&&>>  
  22&*&H&H$$#:: C   &&%%&6&F&Fs&KL
S!r9   )r3   )__name__
__module____qualname____firstlineno__usagestrr   
FlagValuesr,   r   intrV   __static_attributes____classcell__)r6   s   @r7   r   r      sK    
9%R3 RE$4$4 Rh8"8"/28"}8" 8"r9   r   )__doc__
__future__r   r   r   typingr   abslr   rE   clientsr   r	   rI   frontendr
   r   r1   rL   r   r   BigqueryCmdr    r9   r7   <module>rj      sG    ' &  %     , % % , ,   %O"** O"r9   