Sub topic 2
Creating a pipeline: source files, target schema and compute
This chapter walks through creating a pipeline object. It assumes you know Unity Catalog catalogs and schemas, can read basic SQL or PySpark, and have seen the idea of a declarative pipeline from the previous chapter.
What a pipeline is
A pipeline is the unit Databricks runs, monitors and bills. It is a settings object that points at your source code, names a place to publish results, and picks compute. The source files hold the dataset definitions. The pipeline holds everything else.
You do not call the files in order. When you start an update, the pipeline reads all of its source files, works out which datasets depend on which, and runs them in a valid order.
The settings that matter
| Setting | What it controls | Common mistake |
|---|---|---|
| Source code | Files or folders of SQL and Python that define datasets | Adding a file but not including it in the pipeline's libraries |
| Catalog | The Unity Catalog catalog where datasets are published | Assuming the default catalog of your notebook applies |
| Schema | The default schema for datasets in this pipeline | Expecting tables to appear in a schema you did not set |
| Compute | Serverless or classic clusters | Sizing a cluster by hand when serverless would do |
| Mode | Triggered or continuous | Choosing continuous for data that arrives once a day |
Each dataset is published as catalog.schema.dataset_name. A dataset defined as orders_bronze in a pipeline with catalog main and schema demo becomes main.demo.orders_bronze.
Creating the pipeline in the UI
- In the workspace sidebar, open Jobs & Pipelines and choose Create, then ETL pipeline.
- Enter a name.
- Select the target catalog and schema.
- Choose to create a new source file, or add existing files. Pick SQL or Python for a new file.
- Review the compute option. Serverless is the simplest choice if your workspace offers it.
- Save, then run an update.
Menu names change between releases, so check your workspace if a label differs.
A minimal source file
Put one dataset in a SQL file to check that the pipeline works.
CREATE OR REFRESH STREAMING TABLE orders_bronze
AS SELECT *
FROM STREAM read_files(
'/Volumes/main/demo/raw/orders/',
format => 'json'
);The query does not use a fully qualified name for the table. The pipeline's catalog and schema supply it. Run an update, then check Catalog for main.demo.orders_bronze.
The same pipeline as configuration
A pipeline can also be written as configuration. Later chapters use this form to deploy with Databricks Asset Bundles. The settings map directly to the table above.
resources:
pipelines:
orders_pipeline:
name: orders_pipeline
catalog: main
schema: demo
serverless: true
continuous: false
libraries:
- file:
path: ../src/orders.sqlHere libraries lists the source files, serverless: true picks compute, and continuous: false selects triggered mode.
Common errors
- Table not found after a run. The file is probably not listed in the pipeline's source code. Add it and run again.
- Datasets appear in the wrong schema. The pipeline's default schema applies unless a dataset name includes its own schema. Check the pipeline settings first.
- Permission denied on the volume or schema. The identity running the pipeline needs access to the source location and the right to create tables in the target schema.
Exercise
A pipeline has catalog main and schema sales. A source file defines CREATE OR REFRESH MATERIALIZED VIEW daily_totals AS SELECT .... Under what full name is the view published, and what would you check if it is missing after an update?
Show answer
It is published as main.sales.daily_totals. If it is missing, check that the file is included in the pipeline's source code, then check the update's event messages for errors such as missing permissions.