Skip to content
  • There are no suggestions because the search field is empty.

Databricks - Load data - Apache Airflow Load Control

Applies to
Platform: Databricks

Load the deployed Databricks solution with Apache Airflow by running the DAG that the generator writes. The DAG has one task per loader, runs them in dependency order and starts for each one a Databricks job that runs the loader notebook. Afterwards the Graph of the run shows the state of every loader task.

The DAG is written for Apache Airflow 2. It uses DatabricksRunNowOperator of the provider apache-airflow-providers-databricks and the Airflow connection databricks_default.

Prerequisites

Create the Databricks jobs

The folder LoadControl of the artifacts holds one job file <loader>_Loader_Job.json per loader. The DAG starts these jobs by name.

  1. Download deploy_jobs.ps1 into the artifacts folder, next to LoadControl:
    Artifacts folder with deploy_jobs.ps1 next to the Helpers, Jupyter and LoadControl folders
  2. Open PowerShell 7 in the artifacts folder and run:
    .\deploy_jobs.ps1 -databricksAccountName <workspace host> `
      -jobsFolderName LoadControl -databricksToken <token>
    Here <workspace host> is the host name of the workspace URL without https://, and <token> the personal access token.
  3. Check the output. For each job file, the script prints creating job <job name>. A job with the same name is deleted first: job already present, removing <job name>.

Run the DAG

  1. Copy LoadControl\<project>_dag.py into the folder dags of Airflow. <project> is the project name in lower case without spaces, with underscores for dots; the DAG ID is the file name without _dag.py.
  2. In the Airflow UI, open Admin, choose Connections and select + (Add a new record).
    Airflow Admin menu with Connections highlighted
    Airflow List Connection page with the add button highlighted
  3. Enter the connection:
    • Connection Id: databricks_default
    • Connection Type: Databricks
    • Host: the workspace URL, https://<workspace host>
    • Login: leave it empty
    • Password: the personal access token
    Airflow Add Connection form for connection type Databricks with empty fields
  4. Select Test; it shows Connection successfully tested when Airflow reaches the workspace. Then select Save.
    Test button on the connection form
    Connection successfully tested message
    Save button on the connection form
  5. Open DAGs and switch on the toggle left of the DAG.
    Airflow menu bar with DAGs highlighted
  6. Select Trigger DAG in the column Actions.
    Trigger DAG button in the Actions column

All tasks of a DAG run pass the same load timestamp to their loaders: the logical date of the run. The DAG has no schedule; it runs when you trigger it. After each loader task, a task log_<loader> prints the result of the Databricks job run.

Check the result

Select the DAG, then the run, and open the tab Graph. The run succeeded when every task shows the state success:

Graph of a DAG run with loader tasks of type DatabricksRunNowOperator, their log tasks and the tasks begin and end

The log of each log_<loader> task prints the link to the Databricks job run. In Databricks, the result views show the rows, for example SELECT COUNT(*), MAX(bg_loadtimestamp) FROM <catalog>.rawvault.rdv_hub_<hub>_result;.

Example

The DAG test_vaultandmart_spark_databricks of a Data Vault and Mart project has one task per loader between the tasks begin and end:

run_rdv_hub_bdc_customer_loader = DatabricksRunNowOperator(
    task_id='RDV_HUB_BDC_CUSTOMER_Loader',
    databricks_conn_id='databricks_default',
    job_name='RDV_HUB_BDC_CUSTOMER_Loader_Job',
    notebook_params={'bg_loadtimestamp':
      "{{ logical_date.strftime('%Y-%m-%d %H:%M:%S.%f') }}"}
)

Its job RDV_HUB_BDC_CUSTOMER_Loader_Job runs the notebook <notebook_task_path>RDV_HUB_BDC_CUSTOMER_Loader on the cluster of existing_cluster_id.

Failure symptoms and recovery

A task fails because the job does not exist

Cause: deploy_jobs.ps1 did not run, or ran in another workspace than the connection names.
Fix: Run it as in Create the Databricks jobs, then clear the failed task and its downstream tasks in the Graph.

The job does not find the loader notebook

Cause: notebook_task_path does not point to the folder Jupyter of the uploaded artifacts, or lacks the trailing slash.
Fix: Correct notebook_task_path in replacement_config.json, unzip the artifacts again, replace the placeholders and rerun deploy_jobs.ps1.

The DAG shows an import error

Cause: The Airflow environment has no Databricks provider, or it runs Airflow 3, which no longer accepts the DAG parameters schedule_interval and concurrency.
Fix: Use an Airflow 2 environment with apache-airflow-providers-databricks, as described in Apache Airflow - Load control environment.

For failures in other steps, see Troubleshoot generation, deployment and load failures.

Related articles