DatabricksRunNowOperator

Databricks

Runs an existing Spark job run to Databricks using the api/2.0/jobs/run-now API endpoint.

View on GitHub

Last Updated: May. 7, 2021

Access Instructions

Install the Databricks provider package into your Airflow environment.

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

Parameters

job_idstrthe job_id of the existing Databricks job. This field will be templated. See also https://docs.databricks.com/api/latest/jobs.html#run-now
jsondictA JSON object containing API parameters which will be passed directly to the api/2.0/jobs/run-now endpoint. The other named parameters (i.e. notebook_params, spark_submit_params..) to this operator will be merged with this json dictionary if they are provided. If there are conflicts during the merge, the named parameters will take precedence and override the top level json keys. (templated) See also For more information about templating see jinja-templating. https://docs.databricks.com/api/latest/jobs.html#run-now
notebook_paramsdictA dict from keys to values for jobs with notebook task, e.g. “notebook_params”: {“name”: “john doe”, “age”: “35”}. The map is passed to the notebook and will be accessible through the dbutils.widgets.get function. See Widgets for more information. If not specified upon run-now, the triggered run will use the job’s base parameters. notebook_params cannot be specified in conjunction with jar_params. The json representation of this field (i.e. {“notebook_params”:{“name”:”john doe”,”age”:”35”}}) cannot exceed 10,000 bytes. This field will be templated. See also https://docs.databricks.com/user-guide/notebooks/widgets.html
python_paramslist[str]A list of parameters for jobs with python tasks, e.g. “python_params”: [“john doe”, “35”]. The parameters will be passed to python file as command line parameters. If specified upon run-now, it would overwrite the parameters specified in job setting. The json representation of this field (i.e. {“python_params”:[“john doe”,”35”]}) cannot exceed 10,000 bytes. This field will be templated. See also https://docs.databricks.com/api/latest/jobs.html#run-now
spark_submit_paramslist[str]A list of parameters for jobs with spark submit task, e.g. “spark_submit_params”: [“–class”, “org.apache.spark.examples.SparkPi”]. The parameters will be passed to spark-submit script as command line parameters. If specified upon run-now, it would overwrite the parameters specified in job setting. The json representation of this field cannot exceed 10,000 bytes. This field will be templated. See also https://docs.databricks.com/api/latest/jobs.html#run-now
timeout_secondsint32The timeout for this run. By default a value of 0 is used which means to have no timeout. This field will be templated.
databricks_conn_idstrThe name of the Airflow connection to use. By default and in the common case this will be databricks_default. To use token based authentication, provide the key token in the extra field for the connection and create the key host and leave the host field empty.
polling_period_secondsintControls the rate which we poll for the result of this run. By default the operator will poll every 30 seconds.
databricks_retry_limitintAmount of times retry if the Databricks backend is unreachable. Its value must be greater than or equal to 1.
do_xcom_pushboolWhether we should push run_id and run_page_url to xcom.

Documentation

Runs an existing Spark job run to Databricks using the api/2.0/jobs/run-now API endpoint.

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.0/jobs/run-now endpoint and pass it directly to our DatabricksRunNowOperator through the json parameter. For example

json = {
"job_id": 42,
"notebook_params": {
"dry-run": "true",
"oldest-time-to-consider": "1457570074236"
}
}
notebook_run = DatabricksRunNowOperator(task_id='notebook_run', json=json)

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 run-now endpoint. In this method, your code would look like this:

job_id=42
notebook_params = {
"dry-run": "true",
"oldest-time-to-consider": "1457570074236"
}
python_params = ["douglas adams", "42"]
spark_submit_params = ["--class", "org.apache.spark.examples.SparkPi"]
notebook_run = DatabricksRunNowOperator(
job_id=job_id,
notebook_params=notebook_params,
python_params=python_params,
spark_submit_params=spark_submit_params
)

In the case where both the json parameter AND the named parameters are provided, they will be merged together. If there are conflicts during the merge, the named parameters will take precedence and override the top level json keys.

param job_id

the job_id of the existing Databricks job. This field will be templated.

type job_id

str

param json

A JSON object containing API parameters which will be passed directly to the api/2.0/jobs/run-now endpoint. The other named parameters (i.e. notebook_params, spark_submit_params..) to this operator will be merged with this json dictionary if they are provided. If there are conflicts during the merge, the named parameters will take precedence and override the top level json keys. (templated)

See also

For more information about templating see jinja-templating. https://docs.databricks.com/api/latest/jobs.html#run-now

type json

dict

param notebook_params

A dict from keys to values for jobs with notebook task, e.g. “notebook_params”: {“name”: “john doe”, “age”: “35”}. The map is passed to the notebook and will be accessible through the dbutils.widgets.get function. See Widgets for more information. If not specified upon run-now, the triggered run will use the job’s base parameters. notebook_params cannot be specified in conjunction with jar_params. The json representation of this field (i.e. {“notebook_params”:{“name”:”john doe”,”age”:”35”}}) cannot exceed 10,000 bytes. This field will be templated.

type notebook_params

dict

param python_params

A list of parameters for jobs with python tasks, e.g. “python_params”: [“john doe”, “35”]. The parameters will be passed to python file as command line parameters. If specified upon run-now, it would overwrite the parameters specified in job setting. The json representation of this field (i.e. {“python_params”:[“john doe”,”35”]}) cannot exceed 10,000 bytes. This field will be templated.

type python_params

list[str]

param spark_submit_params

A list of parameters for jobs with spark submit task, e.g. “spark_submit_params”: [“–class”, “org.apache.spark.examples.SparkPi”]. The parameters will be passed to spark-submit script as command line parameters. If specified upon run-now, it would overwrite the parameters specified in job setting. The json representation of this field cannot exceed 10,000 bytes. This field will be templated.

type spark_submit_params

list[str]

param timeout_seconds

The timeout for this run. By default a value of 0 is used which means to have no timeout. This field will be templated.

type timeout_seconds

int32

param databricks_conn_id

The name of the Airflow connection to use. By default and in the common case this will be databricks_default. To use token based authentication, provide the key token in the extra field for the connection and create the key host and leave the host field empty.

type databricks_conn_id

str

param polling_period_seconds

Controls the rate which we poll for the result of this run. By default the operator will poll every 30 seconds.

type polling_period_seconds

int

param databricks_retry_limit

Amount of times retry if the Databricks backend is unreachable. Its value must be greater than or equal to 1.

type databricks_retry_limit

int

param do_xcom_push

Whether we should push run_id and run_page_url to xcom.

type do_xcom_push

bool

Was this page helpful?