
    &                         d Z ddlmZ ddlmZ ddlmZ ddl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  G d
 dej                         Zy)zThe BigQuery CLI mkdef command.    )absolute_import)division)print_functionN)Optional)flags)bigquery_command)utilsc                   d     e Zd ZdZdedej                  f fdZ	 d	dedee   dee	   fdZ
 xZS )
MakeExternalTableDefinitionzmkdef <source_uri> [<schema>]namefvc                    t         t        |   ||       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g dd|       t        j
                  dd d|       t        j                  ddd|       t        j                  ddd|       t        j                  ddt        j                  |       t        j                  dd ddgd|       t        j                  dd d d!gd"|       t        j                  d#dd$|       t        j
                  d%d d&|       t        j                  d'd g d(d)d*|       t        j                  d+d d,d-gd.|       t        j                  |      | _        t        j                  |      | _        t        j                  |      | _        t        j                   |      | _        t        j$                  |      | _        t        j(                  |      | _        t        j,                  |      | _        t        j0                  |      | _        t        j4                  |      | _        | j9                  |       y )/N
autodetectz1Should schema and format options be autodetected.)flag_valuesignore_unknown_valuesz>Ignore any values in a row that are not present in the schema.i)
short_namer   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.require_hive_partition_filterzbWhether queries against a table are required to include a hive partition key in a query predicate.source_formatCSV)	r   GOOGLE_SHEETSNEWLINE_DELIMITED_JSONDATASTORE_BACKUP
DELTA_LAKEORCPARQUETAVROICEBERGzFormat of source data. Options include:
 CSV
 GOOGLE_SHEETS
 NEWLINE_DELIMITED_JSON
 DATASTORE_BACKUP
 DELTA_LAKE
 ORC
 PARQUET
 ICEBERG
 AVROconnection_ida  The connection specifying the credentials to be used to read external storage, such as Azure Blob, Cloud Storage, or S3. The connection_id can have the form "<project_id>.<location_id>.<connection_id>" or "projects/<project_id>/locations/<location_id>/connections/<connection_id>".use_avro_logical_typesTzIf 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).parquet_enum_as_stringFzHInfer Parquet ENUM logical type as STRING (instead of BYTES by default).parquet_enable_list_inferencemetadata_cache_mode	AUTOMATICMANUALzEnables metadata cache for an external table with a connection. Specify AUTOMATIC to automatically refresh the cached metadata. Specify MANUAL to stop the automatic refresh.object_metadata	DIRECTORYSIMPLEz/Object Metadata Type. Options include:
 SIMPLE.!preserve_ascii_control_characterszLWhether to preserve embedded Ascii Control characters in CSV External table reference_file_schema_urizqprovide a referencing file with the expected table schema, currently enabled for the formats: AVRO, PARQUET, ORC.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-16 LittleEndian)E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.)superr   __init__r   DEFINE_booleanDEFINE_stringDEFINE_enumfrontend_utils"PARQUET_LIST_INFERENCE_DESCRIPTIONfrontend_flagsdefine_null_markernull_marker_flagdefine_null_markersnull_markers_flagdefine_time_zonetime_zone_flagdefine_date_formatdate_format_flagdefine_datetime_formatdatetime_format_flagdefine_time_formattime_format_flagdefine_timestamp_formattimestamp_format_flagdefine_source_column_matchsource_column_match_flagdefine_parquet_map_target_typeparquet_map_target_type_flag_ProcessCommandRc)selfr   r   	__class__s      %platform/bq/frontend/command_mkdef.pyr3   z$MakeExternalTableDefinition.__init__   s   	
%t5dB?	;	 
H 
 	H  
-	0  
'	= 

	
		 14 
	
 	 
 	P  
 	) 
'99	 
	h	8  
	h: 
+	 
#	7 
O	,  
	;<	  +=="MD+??BOD(99bID*=="MD . E E!D +=="MD!/!G!G"D %3$M$M%D! 	55"E 	% 	2    source_urisschemareturnc                    t        j                  t        j                  d i d| j                  d|d|d| j
                  d| j                  d| j                  d| j                  d| j                  d	| j                  d
| j                  d| j                  d| j                  d| j                  d| j                  d| j                   d| j"                  d| j$                  d| j&                  d| j(                  j*                  d| j,                  j*                  d| j.                  j*                  d| j0                  j*                  d| j2                  j*                  d| j4                  j*                  d| j6                  j*                  d| j8                  j*                  d| j:                  j*                  t<        j>                  dd       y)!a  Emits a definition in JSON for an external table, such as GCS.

    The output of this command can be redirected to a file and used for the
    external_table_definition flag with the "bq query" and "bq mk" commands.
    It produces a definition with the most commonly used values for options.
    You can modify the output to override option values.

    The <source_uris> argument is a comma-separated list of URIs indicating
    the data referenced by this external table.

    The <schema> argument should be either the name of a JSON file or a text
    schema.

    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.

    Usage:
      mkdef <source_uris> [<schema>]

    Examples:
      bq mkdef 'gs://bucket/file.csv' field1:integer,field2:string

    Arguments:
      source_uris: Comma-separated list of URIs.
      schema: Either a text schema or JSON file, as above.
    r   rQ   rR   r   r!   r   r   r   r   r"   r#   r$   r%   r(   r+   r,   r-   r/   null_markernull_markers	time_zonedate_formatdatetime_formattime_formattimestamp_formatsource_column_matchparquet_map_target_typeT   )	sort_keysindentN ) jsondumpr7   CreateExternalTableDefinitionr   r   r!   r   r   r   r   r"   r#   r$   r%   r(   r+   r,   r-   r/   r;   valuer=   r?   rA   rC   rE   rG   rI   rK   sysstdout)rM   rQ   rR   s      rO   RunWithArgsz'MakeExternalTableDefinition.RunWithArgs   s   P 	II44 	
,,	
#	
 	
 		

 ,,	
 #'"<"<	
 $(#>#>	
 150X0X	
 +/*L*L	
 $(#>#>	
 $(#>#>	
 +/*L*L	
 !% 8 8	
 !00	
 /3.T.T	
  '+&D&D!	
" ]]#	
$  $66%	
& --33'	
( //55)	
* ))//+	
, --33-	
. !55;;/	
0 --331	
2 "77==3	
4 !% = = C C5	
6 %)$E$E$K$K7	
: 	

A!rP   )N)__name__
__module____qualname__usagestrr   
FlagValuesr3   r   intrh   __classcell__)rN   s   @rO   r   r      sS    
-%j3 jE$4$4 jZ 7;II&.smI}IrP   r   )__doc__
__future__r   r   r   rb   rf   typingr   abslr   frontendr   r9   r	   r7   BigqueryCmdr   ra   rP   rO   <module>rw      s;    % &  %  
   % , ,x"2">"> xrP   