Start a Templated Cloud DataFlow job. The parameters of the operation will be passed to the job.

View Source

Last Updated: May. 7, 2021

Access Instructions

Install the Google provider package into your Airflow environment.

Import the module into your DAG file and instantiate it with your desired params.


templatestrThe reference to the DataFlow template.
job_nameOptional[str]The 'jobName' to use when executing the DataFlow template (templated).
optionsdictMap of job runtime environment options. It will update environment argument if passed.
dataflow_default_optionsdictMap of default job environment options.
parametersdictMap of job specific parameters for the template.
project_idstrOptional, the Google Cloud project ID in which to start a job. If set to None or missing, the default project_id from the Google Cloud connection is used.
locationstrJob location.
gcp_conn_idstrThe connection ID to use connecting to Google Cloud.
delegate_tostrThe account to impersonate using domain-wide delegation of authority, if any. For this to work, the service account making the request must have domain-wide delegation enabled.
poll_sleepintThe time in seconds to sleep between polling Google Cloud Platform for the dataflow job status while the job is in the JOB_STATE_RUNNING state.
impersonation_chainUnion[str, Sequence[str]]Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated).
environmentOptional[dict]Optional, Map of job runtime environment options.
cancel_timeoutOptional[int]How long (in seconds) operator should wait for the pipeline to be successfully cancelled when task is being killed.
wait_until_finishedOptional[bool](Optional) If True, wait for the end of pipeline execution before exiting. If False, only submits job. If None, default behavior.The default behavior depends on the type of pipeline:for the streaming pipeline, wait for jobs to start,for the batch pipeline, wait for the jobs to complete.You cannot call PipelineResult.wait_until_finish method in your pipeline code for the operator to work properly. i. e. you must use asynchronous execution. Otherwise, your pipeline will always wait until finished. For more information, look at: Asynchronous executionThe process of starting the Dataflow job in Airflow consists of two steps:running a subprocess and reading the stderr/stderr log for the job id.loop waiting for the end of the job ID from the previous step. This loop checks the status of the job.Step two is started just after step one has finished, so if you have wait_until_finished in your pipeline code, step two will not start until the process stops. When this process stops, steps two will run, but it will only execute one iteration as the job will be in a terminal state.If you in your pipeline do not call the wait_for_pipeline method but pass wait_until_finish=True to the operator, the second loop will wait for the job's terminal state.If you in your pipeline do not call the wait_for_pipeline method, and pass wait_until_finish=False to the operator, the second loop will check once is job not in terminal state and exit the loop.


Start a Templated Cloud DataFlow job. The parameters of the operation will be passed to the job.

It’s a good practice to define dataflow_* parameters in the default_args of the dag like the project, zone and staging location.

default_args = { 'dataflow_default_options': { 'zone': 'europe-west1-d', 'tempLocation': 'gs://my-staging-bucket/staging/', } } }

You need to pass the path to your dataflow template as a file reference with the template parameter. Use parameters to pass on parameters to your job. Use environment to pass on runtime environment variables to your job.

t1 = DataflowTemplateOperator( task_id='dataflow_example', template='{{var.value.gcp_dataflow_base}}', parameters={ 'inputFile': "gs://bucket/input/my_input.txt", 'outputFile': "gs://bucket/output/my_output.txt" }, gcp_conn_id='airflow-conn-id', dag=my-dag)

template, dataflow_default_options, parameters, and job_name are templated so you can use variables in them.

Note that dataflow_default_options is expected to save high-level options for project information, which apply to all dataflow operators in the DAG.

Was this page helpful?