DatabricksRunNowOperator¶
Use the DatabricksRunNowOperator to trigger a run of an existing Databricks job
via api/2.2/jobs/run-now API endpoint.
Using the Operator¶
There are two ways to instantiate this operator. In the first way, you can take the JSON payload that you typically use
to call the api/2.2/jobs/run-now endpoint and pass it directly to our DatabricksRunNowOperator through the json parameter.
Another way to accomplish the same thing is to use the named parameters of the DatabricksRunNowOperator directly.
Note that there is exactly one named parameter for each top level parameter in the jobs/run-now endpoint.
The only required parameters are either:
job_id- to specify ID of the existing Databricks jobjob_name- Name of the existing Databricks job. It will throw exception if job isn’t found, of if there are multiple jobs with the same name.
All other parameters are optional and described in documentation for DatabricksRunNowOperator. For example, you can pass additional parameters to a job using one of the following parameters, depending on the type of tasks in the job:
notebook_paramspython_paramspython_named_paramsjar_paramsspark_submit_paramsidempotency_tokenrepair_runcancel_previous_runs
Forwarding Airflow Dag params as Databricks job parameters¶
The Databricks api/2.2/jobs/run-now endpoint accepts a top-level job_parameters field — a plain
Dict[str, str] mapping parameter name to value — that overrides the job’s defaults
for this run.
If job_parameters is not set in json and the operator’s params dict is
non-empty, params is forwarded as job_parameters as-is, so Airflow Dag params can
be passed dynamically to a run without hardcoding them in json. If json already
contains job_parameters, it is left untouched.
run_now = DatabricksRunNowOperator(
task_id="run_now",
job_id=123,
params={"env": "staging", "batch_size": "42"},
)
# The triggered run receives:
# job_parameters={"env": "staging", "batch_size": "42"}
# i.e. the same dict, passed straight through to the run-now request body.
DatabricksRunNowDeferrableOperator¶
Deferrable version of the DatabricksRunNowOperator operator.
It allows to utilize Airflow workers more effectively using new functionality introduced in Airflow 2.2.0