
    c                         S r SSKJr  SSKJr  SSKJr  SSKrSSK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All the BigQuery CLI commands.    )absolute_import)division)print_functionN)Optional)flags)
client_job)utils)bigquery_command)bq_cached_client)utils_flags)utils_formattingc            
       x   ^  \ rS rSrSrS\S\R                  4U 4S jjr SS\S\S\	\   S	\	\
   4S
 jjrSrU =r$ )Load   z*load <destination_table> <source> <schema>namefvc           	      
  > [         [        U ]  X5        [        R                  " SS SSUS9  [        R
                  " SS / SQ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US9  [        R                  " SS SUS9  [        R
                  " SS / S QS!US9  [        R                  " 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+US9  [        R                  " S,S S-US9  [        R                  " 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 [        R                  US9  [        R                  " SAS SBUS9  [        R                  " SCS SDUS9  [        R                  " SES / SFQSGUS9  [        R
                  " SHS SISJ/SKUS9  [        R                  " SLS SMUS9  [        R                  " SNS SOUS9  [        R                  " SPS SQUS9  [        R
                  " SRS SS/STUS9  [        R
                  " SUS / SVQSWUS9  [        R                  " SXS SYUS9  [        R
                  " SZS S[/S\US9  [        R
                  " S]S / S^QS_US9  [        R                  " S`S SaUS9  [        R                  " SbS ScUS9  [        R                  " SdS SeUS9  [        R                  " SfS SgUS9  [        R                  " ShS SiUS9  [        R                  " SjS SkUS9  [        R                  " SlS SmUS9  [        R
                  " SnS SoSp/SqUS9  [        R                  " US9U l        [        R                   " US9U l        [        R$                  " US9U l        U R)                  U5        g )rNfield_delimiterzwThe character that indicates the boundary between columns in the input file. "\t" and "tab" are accepted names for tab.F)
short_nameflag_valuesencoding)zUTF-8z
ISO-8859-1zUTF-16BEzUTF-16LEzUTF-32BEzUTF-32LEzThe character encoding used by the input file.  Options include:
 ISO-8859-1 (also known as Latin-1)
 UTF-8
 UTF-16BE (UTF-16 BigEndian)
 UTF-16LE (UTF-16 LittleEndian)
 UTF-32BE (UTF-32 BigEndian)
 UTF-32LE (UTF-32 LittleEndian)Eskip_leading_rowsz?The number of rows at the beginning of the source file to skip.)r   schemazNEither a filename or a comma-separated list of fields in the form name[:type].replaceFz8If true existing data is erased when new data is loaded.replace_datazbIf true, erase existing contents but not other table metadata like schema before loading new data.quoteztQuote character to use to enclose records. Default is ". To indicate no quote character at all, use an empty string.max_bad_recordszMaximum number of bad records allowed before the entire job fails. Only supported for CSV and NEWLINE_DELIMITED_JSON file formats.allow_quoted_newlinesz4Whether to allow quoted newlines in CSV import data.allow_jagged_rowszFWhether to allow missing trailing optional columns in CSV import data.!preserve_ascii_control_characterszIWhether to preserve embedded Ascii Control characters in CSV import data.ignore_unknown_valueszRWhether to allow and ignore extra, unrecognized values in CSV or JSON import data.source_format)CSVNEWLINE_DELIMITED_JSONDATASTORE_BACKUPAVROPARQUETORCTHRIFTzrFormat of source data. Options include:
 CSV
 NEWLINE_DELIMITED_JSON
 DATASTORE_BACKUP
 AVRO
 PARQUET
 ORC
 THRIFTprojection_fieldszIf sourceFormat is set to "DATASTORE_BACKUP", indicates which entity properties to load into BigQuery from a Cloud Datastore backup. Property names are case sensitive and must refer to top-level properties.
autodetectzgEnable auto detection of schema and options for formats that are not self describing like CSV and JSON.schema_update_optionaZ  Can be specified when append to a table, or replace a table partition. When specified, the schema of the destination table will be updated with the schema of the new data. One or more of the following options can be specified:
 ALLOW_FIELD_ADDITION: allow new fields to be added
 ALLOW_FIELD_RELAXATION: allow relaxing required fields to nullablenull_markerzMAn optional custom string that will represent a NULL valuein CSV import data.null_markerszVAn optional list of custom strings that will represent a NULL valuein CSV import data.time_partitioning_typezEnables time based partitioning on the table and set the type. The default value is DAY, which will generate one partition per day. Other supported values are HOUR, MONTH, and YEAR.time_partitioning_expirationzEnables time based partitioning on the table and sets the number of seconds for which to keep the storage for the partitions in the table. The storage in a partition will have an expiration time of its partition time plus this value.range_partitioninga  Enables range partitioning on the table. The format should be "field,start,end,interval". The table will be partitioned based on the value of the field. Field must be a top-level, non-repeated INT64 field. Start, end, and interval are INT64 values defining the ranges.time_partitioning_fieldzEnables time based partitioning on the table and the table will be partitioned based on the value of this field. If time based partitioning is enabled without this value, the table will be partitioned based on the loading time.destination_kms_keyz;Cloud KMS key for encryption of the destination table data.require_partition_filterzaWhether to require partition filter for queries over this table. Only apply to partitioned table.clustering_fieldszComma-separated list of field names that specifies the columns on which a table is clustered. To remove the clustering, set an empty value.use_avro_logical_typeszIf sourceFormat is set to "AVRO", indicates whether to enable interpreting logical types into their corresponding types (ie. TIMESTAMP), instead of only using their raw types (ie. INTEGER).reference_file_schema_urizfprovide a reference file with the reader schema, currently enabled for the format: AVRO, PARQUET, ORC.parquet_enum_as_stringzHInfer Parquet ENUM logical type as STRING (instead of BYTES by default).parquet_enable_list_inferencehive_partitioning_modezEnables hive partitioning.  AUTO indicates to perform automatic type inference.  STRINGS indicates to treat all hive partition keys as STRING typed.  No other values are accepted#hive_partitioning_source_uri_prefixzPrefix after which hive partition encoding begins.  For URIs like gs://bucket/path/key1=value/file, the value should be gs://bucket/path.decimal_target_types)NUMERIC
BIGNUMERICSTRINGa  Specifies the list of possible BigQuery data types to which the source decimal values are converted. This list and the precision and the scale parameters of the decimal field determine the target type in the following preference order, and one or more of the following options could be specified: 
 NUMERIC: decimal values could be converted to NUMERIC type, depending on the precision and scale of the decimal schema.
 BIGNUMERIC: decimal values could be converted to BIGNUMERIC type, depending on the precision and scale of the decimal schema.
 STRING: decimal values could be converted to STRING type, depending on the precision and scale of the decimal schema.file_set_spec_typeFILE_SYSTEM_MATCHNEW_LINE_DELIMITED_MANIFESTaU  Specifies how to discover files given source URIs. Options include: 
 FILE_SYSTEM_MATCH: expand source URIs by listing files from the underlying object store. This is the default behavior.
 NEW_LINE_DELIMITED_MANIFEST: indicate the source URIs provided are new line delimited manifest files, where each line contains a URI with no wild-card.thrift_schema_idl_root_dirzIf "source_format" is set to "THRIFT", indicates the root directory of the Thrift IDL bundle containing all Thrift files that should be used to parse the schema of the serialized Thrift records.thrift_schema_idl_uria  If "source_format" is set to "THRIFT", indicates the file uri that contains the Thrift IDL struct to be parsed as schema. This file will be used as the entry point to parse the schema and all its included Thrift IDL files should be in "thrift_schema_idl_root_dir".thrift_schema_structzIf "source_format" is set to "THRIFT", indicates the root Thrift struct that should be used as the schema. This struct should be defined in the "thrift_schema_idl_uri" file.thrift_deserializationT_BINARY_PROTOCOLzIf "source_format" is set to "THRIFT", configures how serialized Thrift record should be deserialized (using TProtocol). Options include: 
 T_BINARY_PROTOCOLthrift_framing)
NOT_FRAMEDFRAMED_WITH_BIG_ENDIANFRAMED_WITH_LITTLE_ENDIANzIf "source_format" is set to "THRIFT", configures how Thrift records or data blocks are framed (e.g. using TFramedTransport). Options includes: 
 NOT_FRAMED, 
 FRAMED_WITH_BIG_ENDIAN, 
 FRAMED_WITH_LITTLE_ENDIANboundary_bytes_base64zIf "source_format" is set to "THRIFT", indicates the sequence of boundary bytes (encoded in base64) that are added in front of the serialized Thrift records, or data blocks, or the frame when used with `thrift_framing`.json_extensionGEOJSONz(experimental) Allowed values: GEOJSON: only allowed when source_format is specified as NEWLINE_DELIMITED_JSON. When specified, the input is loaded as newline-delimited GeoJSON.column_name_character_map)STRICTV1V2aE  Indicates the character map used for column names: 
 STRICT: The latest character map and reject invalid column names.
 V1: Supports alphanumeric + underscore and name must start with a letter or underscore. Invalid column names will be normalized.
 V2: Supports flexible column name. Invalid column names will be normalized.
session_idzPIf loading to a temporary table, specifies the session ID of the temporary tablecopy_files_onlyz[Experimental] Configures the load job to only copy files to the destination BigLake managed table, without reading file content and writing them to new files.	time_zonezDefault time zone that will apply when parsing timestamp values that have no specific time zone. For example, "America/Los_Angeles".date_formatzlFormat elements that define how the DATE values are formatted in the input files. For example, "MM/DD/YYYY".datetime_formatzFormat elements that define how the DATETIME values are formatted in the input files. For example, "MM/DD/YYYY HH24:MI:SS.FF3".time_formatzpFormat elements that define how the TIME values are formatted in the input files. For example, "HH24:MI:SS.FF3".timestamp_formatzFormat elements that define how the TIMESTAMP values are formatted in the input files. For example, "MM/DD/YYYY HH24:MI:SS.FF3".source_column_matchPOSITIONNAMEaE  Controls the strategy used to match loaded columns to the schema. Options include:
 POSITION: matches by position. This option assumes that the columns are ordered the same way as the schema.
 NAME: matches by name. This option reads the header row as column names and reorders columns to match the field names in the schema.)superr   __init__r   DEFINE_stringDEFINE_enumDEFINE_integerDEFINE_booleanDEFINE_listDEFINE_multi_stringfrontend_utils"PARQUET_LIST_INFERENCE_DESCRIPTIONDEFINE_multi_enumfrontend_flags!define_timestamp_target_precisiontimestamp_target_precision_flagdefine_parquet_map_target_typeparquet_map_target_type_flagdefine_reservation_id_for_a_jobreservation_id_for_a_job_flag_ProcessCommandRc)selfr   r   	__class__s      $platform/bq/frontend/command_load.pyr`   Load.__init__    s   	$t(		B 
O0   
I	 
	 
B	 
	+ 
	F 
	J 
>	 
	 
+	 
	 
	
	 ), 

	  
	- 
	P 
 
	 

	 
 	<  
&	*  
	P  
!	1  
E	 
"	+ 
	  
 	P  
#	6 
 	) 
'99	 
 	H  
-	0  
+
	F " 
	;<	  
$	E  
	F  
	7  
 		 	 
M	'  
	!  
		% 	 
#	  
	 
	%  
	K 
	3 
	F 
	7 
	F 
	V	N  	88RH 	( 	55"E 	% 	662F 	& 	2    destination_tablesourcer   returnc                 D   [         R                  R                  5       nSnU R                  (       a  Sn[        R
                  " UUUS9nU R                  U R                  U R                  [        R                  " 5       U R                  U R                  S.nU R                  (       a  U R                  US'   [        R                  R                   (       a  [        R                  R                   US'   U R                  (       a  SU R                  S./US	'   U R"                  (       a  U R"                  US
'   U R$                  (       a  SUS'   OU R&                  (       a  SUS'   U R(                  b#  [*        R,                  " U R(                  5      US'   U R.                  b#  [*        R,                  " U R.                  5      US'   U R0                  b  U R0                  US'   U R2                  b  U R2                  US'   U R4                  b  U R4                  US'   U R6                  b  U R6                  US'   U R8                  (       a  U R8                  US'   U R:                  (       a  U R:                  US'   U R<                  b  U R<                  US'   [*        R>                  " U R@                  U RB                  U RD                  SU RF                  5      nUb  XS'   [*        RH                  " U RJ                  5      n	U	(       a  XS'   [*        RL                  " U RN                  5      n
U
(       a  XS'   U RP                  b  SU RP                  0US'   U RR                  b  U RR                  US'   U RT                  b  U RT                  US'   U RV                  bQ  [*        RX                  " U RV                  5        0 nU RV                  US'   U RZ                  b  U RZ                  US '   XS!'   U R\                  b  U R\                  US"'   U R^                  b  U R^                  US#'   U R`                  US$'   U Rb                  b#  [*        Rd                  " U Rb                  5      US%'   U Rf                  b  U Rf                  US&'   U Rh                  b  U Rh                  US''   U Rj                  b  U Rj                  US('   U Rl                  b  U Rl                  US)'   U Rn                  b  U Rn                  US*'   U Rp                  b  U Rp                  US+'   U Rr                  R                   b  U Rr                  R                   US,'   US-   S.:X  a  0 nU Rt                  b  U Rt                  US/'   U Rv                  b  U Rv                  US0'   U Rx                  b  U Rx                  US1'   S2US3'   U Rz                  b  U Rz                  S4:X  a  S2US3'   S5US6'   U R|                  b  U R|                  US6'   U R~                  b  U R~                  US7'   XS8'   US-   S9:X  au  0 nU R                  b  U R                  US:'   U R                  b  U R                  US;'   U R                  R                   b  U R                  R                   US<'   U(       a  XS='   U R                  R                  (       a  U R                  R                   US>'   [        R                  " XFU4S?U0UD6n[        R                  R                   (       a+  [*        R                  " [        R                  " U5      5        gU R                  U5        g)@a   Perform a load operation of source into destination_table.

Usage:
  load <destination_table> <source> [<schema>] [--session_id=[session]]

The <destination_table> is the fully-qualified table name of table to
create, or append to if the table already exists.

To load to a temporary table, specify the table name in <destination_table>
without a dataset and specify the session id with --session_id.

The <source> argument can be a path to a single local file, or a
comma-separated list of URIs.

The <schema> argument should be either the name of a JSON file or a text
schema. This schema should be omitted if the table already has one.

In the case that the schema is provided in text form, it should be a
comma-separated list of entries of the form name[:type], where type will
default to string if not specified.

In the case that <schema> is a filename, it should be a JSON file
containing a single array, each entry of which should be an object with
properties 'name', 'type', and (optionally) 'mode'. For more detail:
https://cloud.google.com/bigquery/docs/schemas#specifying_a_json_schema_file

Note: the case of a single-entry schema with no type specified is
ambiguous; one can use name:string to force interpretation as a
text schema.

Examples:
  bq load ds.new_tbl ./info.csv ./info_schema.json
  bq load ds.new_tbl gs://mybucket/info.csv ./info_schema.json
  bq load ds.small gs://mybucket/small.csv name:integer,value:string
  bq load ds.small gs://mybucket/small.csv field1,field2,field3
  bq load temp_tbl --session_id=my_session ./info.csv ./info_schema.json

Arguments:
  destination_table: Destination table name.
  source: Name of local file to import, or a comma-separated list of URI
    paths to data to import.
  schema: Either a text schema or JSON file, as above.
 _SESSION)id_fallbacks
identifierdefault_dataset_id)r   r   r    job_idr$   r,   r   locationrU   )keyvalueconnection_propertiesrV   WRITE_TRUNCATEwrite_dispositionWRITE_TRUNCATE_DATANr   r   r!   r"   r#   r-   schema_update_optionsr/   r0   time_partitioningr3   
clustering
kmsKeyName$destination_encryption_configurationr8   r9   modesourceUriPrefixhive_partitioning_optionsrO   rQ   r>   rB   rW   rX   rY   rZ   r[   r\   timestamp_target_precisionr$   r+   schema_idl_root_dirschema_idl_urischema_structTHRIFT_BINARY_PROTOCOL_OPTIONdeserialization_optionrI   rK   framing_optionboundary_bytesthrift_optionsr)   enum_as_stringenable_list_inferencemapTargetTypeparquet_optionsreservation_idr   )Lr   ClientGetrU   bq_client_utilsGetTableReferencer   r   r    r   get_job_id_from_flagsr$   r,   r   bq_flagsLOCATIONr   rV   r   r   r   rg   NormalizeFieldDelimiterr   r!   r"   r#   r-   r.   r/   r0   ParseTimePartitioningr1   r2   r4   r6   ParseRangePartitioningr3   ParseClusteringr7   r5   r8   r9   r<   ValidateHivePartitioningOptionsr=   rO   rQ   r>   rB   ParseFileSetSpecTyperW   rX   rY   rZ   r[   r\   rl   rE   rF   rG   rH   rJ   rN   r:   r;   rn   rp   presentr   r   SYNCHRONOUS_MODEPrintJobMessagesr   format_job_infoPrintJobStartInfo)rr   rw   rx   r   clientr   table_referenceoptsr   r3   r   r   r   r   jobs                  rt   RunWithArgsLoad.RunWithArgs  s   \ $$((*F%%77$-O MM!33!%!;!;335++!33D  $ 4 4d!**00d:
9'd"#  $ 4 4d||"2d			"7d' . F F


!d zz$<<TZZHd7m)"&"8"8d--9

0
0 ./ !!-&*&@&@d"#"??d<  &*&?&?d"# ,,d=$!..d>&<<##))$$%% $"3'>> #5 //0F0FGJ%<+
006d12 "".'+'B'Bd#$%%1*.*H*Hd&'"".44

%
% #%*.*E*E'		1	1	=44 	""34 +D&'&#22d%%1*.*H*Hd&'#'#<#<D	 *#1#F#F

!
!$d  ~~!..d;# ,,d=' $ 4 4d# ,,d=(!%!6!6d+$($<$<d !++11=

.
.
4
4 '( O(n		(	(	4040O0O,-		#	#	/+/+E+E'(		"	"	.*.*C*C'1Pn-.		$	$	0&&*==- 1
2 *6n%&				(+/+>+>'(		#	#	/+/+E+E'(-O	)o		$	$	0,0,G,G()		+	+	7.. 	/0 
	*	*	0	0	<--33 	( 
"1))11#AAGGd
//06:>C   &&%%&6&F&Fs&KL
S!rv   )rn   rp   rl   )N)__name__
__module____qualname____firstlineno__usagestrr   
FlagValuesr`   r   intr   __static_attributes____classcell__)rs   s   @rt   r   r      sd    
:%s3 sE$4$4 sl JNL""L",/L"9A#L"}L" L"rv   r   )__doc__
__future__r   r   r   datetimetimetypingr   abslr   r   clientsr   r	   r   frontendr
   r   rj   rg   r   r   BigqueryCmdr    rv   rt   <module>r      sM    $ &  %       , % % , ,   %D
"'' D
"rv   