DatabricksSubmitRunOperator

Use the DatabricksSubmitRunOperator to submit an existing Spark job run to Databricks api/2.0/jobs/runs/submit <https://docs.databricks.com/api/latest/jobs.html#runs-submit> 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.0/jobs/runs/submit endpoint and pass it directly to our DatabricksSubmitRunOperator through the json parameter.

Another way to accomplish the same thing is to use the named parameters of the DatabricksSubmitRunOperator directly. Note that there is exactly one named parameter for each top level parameter in the runs/submit endpoint.

Databricks Airflow Connection Metadata

Parameter

Input

spark_jar_task: dict

main class and parameters for the JAR task

notebook_task: dict

notebook path and parameters for the task

spark_python_task: dict

python file path and parameters to run the python file with

spark_submit_task: dict

parameters needed to run a spark-submit command

new_cluster: dict

specs for a new cluster on which this task will be run

existing_cluster_id: string

ID for existing cluster on which to run this task

libraries: list of dict

libraries which this run will use

run_name: string

run name used for this task

timeout_seconds: integer

The timeout for this run

databricks_conn_id: string

the name of the Airflow connection to use

polling_period_seconds: integer

controls the rate which we poll for the result of this run

databricks_retry_limit: integer

amount of times retry if the Databricks backend is unreachable

databricks_retry_delay: decimal

number of seconds to wait between retries

do_xcom_push: boolean

whether we should push run_id and run_page_url to xcom

An example usage of the DatabricksSubmitRunOperator is as follows:

airflow/providers/databricks/example_dags/example_databricks.pyView Source

    # Example of using the JSON parameter to initialize the operator.
    notebook_task = DatabricksSubmitRunOperator(task_id='notebook_task', json=notebook_task_params)

You can also use named parameters to initialize the operator and run the job.

airflow/providers/databricks/example_dags/example_databricks.pyView Source

    # Example of using the named parameters of DatabricksSubmitRunOperator
    # to initialize the operator.
    spark_jar_task = DatabricksSubmitRunOperator(
        task_id='spark_jar_task',
        new_cluster=new_cluster,
        spark_jar_task={'main_class_name': 'com.example.ProcessData'},
        libraries=[{'jar': 'dbfs:/lib/etl-0.1.jar'}],
    )

Was this entry helpful?