
    8                          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
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 rS rg)zBHelpers for writing commands interacting with Cloud Dataflow SQL.
    )absolute_import)division)unicode_literalsN)arg_parsers)
exceptions)concepts)dataflow_util)	job_utils)concept_parsers)presentation_specs)
propertiesc                    [         R                  " U 5        U R                  SSSS9  U R                  SSSS9  U R                  S	[        R                  " S
S5      S[
        R                  -   SS9  U R                  SSS9n[        R                  " [        R                  " S[        R                  " SS[        R                  " SSS9[        R                  " SSS9[        R                  " SSS9S9SSUS9[        R                  " S[        R                  " SS [        R                  " S!S"S9[        R                  " S#S$S9S%9S&SUS9/5      R                  U 5        U R                  S'S(/ S)QS*S+9  U R                  S,S-S.S//S.S+9  U R!                  5       nUR                  S0S1S2S39  UR                  S4S5S69  U R                  S7S8S9S39  U R                  S:SS;S<S=/S<S>9  U R                  S?SS@SA9  gB)CzsRegister flags for running a SQL query.

Args:
  parser: The argparse.ArgParser to configure with query arguments.
queryQUERYzThe SQL query to execute.)metavarhelpz
--job-namez4The unique name to assign to the Cloud Dataflow job.T)r   requiredz--regionz	\w+-\w+\dzmust provide a valid regionz*Region ID of the job's regional endpoint. )typer   r   z/The destination(s) for the output of the query.)r   r   --bigquery-tablezbigquery.tableszBigQuery tablezbigquery-tablezThe BigQuery table ID.)name	help_textzbigquery-projectzThe BigQuery project ID.zbigquery-datasetzThe BigQuery dataset ID.)resource_nametableId	projectId	datasetIdz,The BigQuery table to write query output to.F)prefixesgroupz--pubsub-topiczpubsub.projects.topicszPub/Sub topiczpubsub-topiczThe Pub/Sub topic ID.zpubsub-projectzThe Pub/Sub project ID.)r   topicsId
projectsIdz1The Cloud Pub/Sub topic to write query output to.z--bigquery-write-dispositionz-The behavior of the BigQuery write operation.write-emptyzwrite-truncatezwrite-appendr!   )r   choicesdefaultz--pubsub-create-dispositionz-The behavior of the Pub/Sub create operation.create-if-not-foundfail-if-not-foundz--parameterappendztParameters to pass to a query. Parameters must use the format name:type:value, for example min_word_count:INT64:250.)actionr   z--parameters-filezPath to a file containing query parameters in JSON format. e.g. [{"parameterType": {"type": "STRING"}, "parameterValue": {"value": "foo"}, "name": "x"}, {"parameterType": {"type": "FLOAT64"}, "parameterValue": {"value": "1.0"}, "name": "y"}])r   z	--dry-run
store_truez=Construct but do not run the SQL pipeline, for smoke testing.z--sql-launcher-template-enginez9The template engine to use for the SQL launcher template.flexdynamic)hiddenr   r"   r#   z--sql-launcher-templatea,  The full GCS path to a SQL launcher template spec, e.g. gs://dataflow-sql-templates-us-west1/cloud_dataflow_sql_launcher_template_20201208_RC00/sql_launcher_flex_template. If None is specified, default to the latest release in the region. Note that older releases are not guaranteed to be compatible.)r+   r   N)r
   
CommonArgsadd_argumentr   RegexpValidatorr	   DEFAULT_REGION_MESSAGE	add_groupr   ConceptParserr   ResourcePresentationSpecr   ResourceSpec ResourceParameterAttributeConfigAddToParseradd_mutually_exclusive_group)parseroutput_groupparameter_groups      3lib/googlecloudsdk/command_lib/dataflow/sql_util.pyArgsForSqlQueryr;   "   s    vw%@  B 	A  
 	&&|'DF9223   !!K " M, 11



,??'3KM AA)68 !AA)68
9 9  11



&+@@%1HJ!BB'578 >#! < [$:?	   	#:$&9:#	  % 779/?  @ G  H 	J  L
 	&Fy!   	F  G    c                    / nU R                   (       Ga  SnSnSnU R                   R                  S5      n[        U5      S:X  a  Uu  p#nO?[        U5      S:X  a  Uu  p4O+[        U5      S:X  a  Uu  nO[        R                  " SS5      eUcP  U R
                  (       a  U R
                  O1[        R                  R                  R                  R                  5       nORU R
                  (       aA  U R
                  U:w  a1  [        R                  " SS	R                  U R
                  U5      5      eUc5  U R                  (       d  [        R                  " S
S5      eU R                  nORU R                  (       aA  U R                  U:w  a1  [        R                  " S
SR                  U R                  U5      5      e[        R                  " SU4SU4SU4/5      nSSSS.U R                      n[        R                  " SSU4SU4/5      nUR#                  U5        U R$                  (       a  SSS.U R&                     n	[        R                  " SSU R(                  (       a  U R(                  O1[        R                  R                  R                  R                  5       4SU R$                  4SU	4/5      n
UR#                  U
5        [*        R,                  " U5      $ )zCParses outputs from args, returning a JSON string with the results.N.         r   z?Malformed table identifier. Use format "project.dataset.table".z--bigquery-projectzE"{}" does not match project "{}" set in qualified `--bigquery-table`.z--bigquery-datasetz9Must be specified when `--bigquery-table` is unqualified.zE"{}" does not match dataset "{}" set in qualified `--bigquery-table`.r   r   r   WRITE_EMPTYWRITE_TRUNCATEWRITE_APPENDr    )r   bigquerytablewriteDispositionCREATE_IF_NOT_FOUNDFAIL_IF_NOT_FOUND)r$   r%   )r   pubsubtopiccreateDisposition)bigquery_tablesplitlenr   InvalidArgumentExceptionbigquery_projectr   VALUEScoreproject	GetOrFailformatbigquery_datasetRequiredArgumentExceptioncollectionsOrderedDictbigquery_write_dispositionr&   pubsub_topicpubsub_create_dispositionpubsub_projectjsondumps)argsoutputs
bq_projectdatasetrF   table_partstable_configwrite_disposition	bq_configcreate_dispositionpubsub_configs              r:   ExtractOutputsrk      s   '	JGE%%++C0K
;1#. j5	[	Q	"ngu	[	Q	fe//

KM M ,0,A,A4((zGXGXG]G]GeGeGoGo Hj			4#8#8J#F//

Q6$''46 6
 ""22 GI 	I %%g			4#8#8G#C//

Q6$''13 3
 **[*,E-8',B-6,>,@ AL %*& %%	'
 '')=*1<)@*<*;*=)> ?I NN9	40 $$&  ++	 $ 3 3								'	'	1	1	3	5 
$##$	01- M NN=!	G	r<   )__doc__
__future__r   r   r   rY   r_   googlecloudsdk.callioper   r    googlecloudsdk.calliope.conceptsr   #googlecloudsdk.command_lib.dataflowr	   r
   (googlecloudsdk.command_lib.util.conceptsr   r   googlecloudsdk.corer   r;   rk    r<   r:   <module>rt      sA    '  '   / . 5 = 9 D G *hGVDr<   