
                            S 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
S.r\R                  " \R                  R                  \R                  R                   5       " S S\R"                  5      5       rg)z6Implementation of `gcloud dataflow sql query` command.    N)apis)sql_query_parameters)base)dataflow_util)sql_util)
propertieszExecute the user-specified SQL query on Dataflow. Queries must comply to the ZetaSQL dialect (https://github.com/google/zetasql). Results may be written to either BigQuery or Cloud Pub/Sub.a        To execute a simple SQL query on Dataflow that reads from and writes to BigQuery, run:

        $ {command} 'SELECT word FROM bigquery.table.`my-project`.input_dataset.input_table where count > 3' --job-name=my-job --region=us-west1 --bigquery-dataset=my_output_dataset --bigquery-table=my_output_table

      To execute a simple SQL query on Dataflow that reads from and writes to Cloud
      Pub/Sub, run:

        $ {command} 'SELECT word FROM pubsub.topic.`my-project`.input_topic where count > 3' --job-name=my-job --region=us-west1 --pubsub-topic=my_output_topic

      To join data from BigQuery and Cloud Pub/Sub and write the result to Cloud
      Pub/Sub, run:

        $ {command} 'SELECT bq.name AS name FROM pubsub.topic.`my-project`.input_topic p INNER JOIN bigquery.table.`my-project`.input_dataset.input_table bq ON p.id = bq.id' --job-name=my-job --region=us-west1 --pubsub-topic=my_output_topic

      To execute a parameterized SQL query that reads from and writes to BigQuery, run:

        $ {command} 'SELECT word FROM bigquery.table.`my-project`.input_dataset.input_table where count > @threshold' --parameter=threshold:INT64:5 --job-name=my-job --region=us-west1 --bigquery-dataset=my_output_dataset --bigquery-table=my_output_table

    )DESCRIPTIONEXAMPLESc                   2    \ rS rSrSr\r\S 5       rS r	Sr
g)Query8   z1Execute the user-specified SQL query on Dataflow.c                 0    [         R                  " U 5        g)zfRegister flags for this command.

Args:
  parser: argparse.ArgumentParser to register arguments with.
N)r   ArgsForSqlQuery)parsers    !lib/surface/dataflow/sql/query.pyArgs
Query.Args>   s     V$    c                    UR                   S:H  n[        R                  " U5      nUR                  (       a  UR                  nOU(       a  SnOSnSR	                  X55      nUR
                  (       a!  [        R                  " UR
                  5      nO4UR                  (       a!  [        R                  " UR                  5      nOSn[        R                  " SUR                  (       a  SOS4S	[        R                  " U5      4S
U4SUR                  4/5      n[         R"                  " S0 S[$        R&                  R(                  R*                  R-                  5       _SU_SUR.                  _SU_SUR0                  _SUR2                  _S[$        R&                  R4                  R6                  R9                  5       _SU_SUR:                  _SUR<                  _SUR>                  _SUR@                  _SURB                  _SURD                  _SURF                  _SURH                  _6nU(       a  [         RJ                  RM                  U5      $ [         RJ                  RO                  U5      $ )Ndynamicsql_launcher_templatesql_launcher_flex_templatez(gs://dataflow-sql-templates-{}/latest/{}z[]dryRuntruefalseoutputsqueryParametersqueryString
project_id	region_idjob_namegcs_locationzonemax_workersdisable_public_ips
parametersservice_account_emailkms_key_namenum_workersnetwork
subnetworkworker_machine_typeworker_regionworker_zone )(sql_launcher_template_enginer   	GetRegionr   formatparameters_filer   ParseParametersFile	parameterParseParametersListcollectionsOrderedDictdry_runr   ExtractOutputsqueryr   TemplateArgumentsr   VALUEScoreproject	GetOrFailr!   r#   r$   dataflowr%   GetBoolr'   dataflow_kms_keyr)   r*   r+   r,   r-   r.   	TemplatesLaunchDynamicTemplateCreateJobFromFlexTemplate)	selfargsuse_dynamic_engineregionr"   suffixquery_parameterstemplate_parameters	argumentss	            r   Run	Query.RunG   s:   ;;yH$$T*F!!//l	(-?FF
l-AA


 	-AA
.. %11	T\\6w7	H++D12	,-	

#	3  && &$$))11;;=&& & "	&
 YY& $$& &,,55HH	& '& #88& **& $$& & ??& !44&  ((!&" $$#&I$ ^^11)<<>>33I>>r   r/   N)__name__
__module____qualname____firstlineno____doc__DETAILED_HELPdetailed_helpstaticmethodr   rO   __static_attributes__r/   r   r   r   r   8   s!    9-% %.?r   r   )rU   r7   googlecloudsdk.api_lib.dataflowr   r   googlecloudsdk.callioper   #googlecloudsdk.command_lib.dataflowr   r   googlecloudsdk.corer   rV   ReleaseTracksReleaseTrackBETAGACommandr   r/   r   r   <module>rc      sx    =  0 @ ( = 8 *	F	: D%%**D,=,=,@,@A<?DLL <? B<?r   