Orchestration

What is orchestration and how do Spark Declarative Pipelines work?


  • Orchestration coordinates data ingestion, transformations, dependencies, execution, and monitoring so an ETL (Extract, Transform, Load) workflow runs reliably.
  • Spark Declarative Pipelines (SDP) lets you declare what datasets should contain using SQL or Python rather than manually sequencing every operation. Databricks Lakeflow pipelines implement and extend SDP.
  • The pipeline analyses dataset references to build a directed acyclic graph (DAG) of dependencies, then determines the execution order and which independent steps can run in parallel.
  • A Medallion pipeline commonly moves through Bronze (raw ingested data), Silver (validated and standardised data), and Gold (business-ready aggregates).
  • Lakeflow Jobs orchestrate explicit tasks (such as notebooks) with task dependencies; Lakeflow pipelines orchestrate declared datasets and transformations automatically. A Job can also run a pipeline as a task.

How do streaming tables and materialized views differ?


  • A streaming table incrementally processes new incoming records, making it useful for Bronze ingestion from a growing folder of source files.
  • STREAM read_files(...) uses Auto Loader for incremental file ingestion; new files can be processed in subsequent updates without re-reading the entire folder.
  • A materialized view stores the results of a query and is refreshed as source data changes. It suits Silver cleaning and Gold aggregations; Databricks can use incremental refresh where supported.
  • Use CREATE OR REFRESH in pipeline SQL to define the desired datasets. The pipeline runtime executes these definitions; they are not ordinary interactive notebook commands.

How do you define a Bronze, Silver, and Gold pipeline in SQL?


  • Define a Bronze streaming table that ingests CSV files from a Unity Catalog volume. Replace the example catalog, schema, volume, and column names with your own.
CREATE OR REFRESH STREAMING TABLE employees_bronze
AS SELECT *
FROM STREAM read_files(
  '/Volumes/my_catalog/my_schema/myfiles/',
  format => 'csv',
  header => true,
  inferColumnTypes => true
);
  • Define Silver as a materialized view that standardises roles, adds a processing timestamp, and checks data quality. Here invalid IDs are counted but retained (the default expectation behaviour).
CREATE OR REFRESH MATERIALIZED VIEW employees_silver (
  CONSTRAINT valid_employee_id EXPECT (EmployeeID IS NOT NULL)
)
AS SELECT
  EmployeeID,
  Name,
  UPPER(Role) AS Role,
  current_timestamp() AS processed_at
FROM employees_bronze;
  • Define Gold as an aggregation of Silver. The dependency is inferred from FROM employees_silver, so no explicit task ordering is required.
CREATE OR REFRESH MATERIALIZED VIEW total_roles_gold
AS SELECT Role, COUNT(*) AS employee_count
FROM employees_silver
GROUP BY Role;
  • The column names above are illustrative; inspect the actual CSV schema first. In production, explicitly define or validate types rather than relying entirely on inference.

How do data quality expectations work?


  • CONSTRAINT name EXPECT (condition) checks whether records meet a rule, such as EmployeeID IS NOT NULL or Salary >= 0.
  • Warn (default): record expectation metrics but retain invalid rows.
  • Drop: add ON VIOLATION DROP ROW to exclude invalid rows from the target dataset.
  • Fail: add ON VIOLATION FAIL UPDATE to stop the pipeline update if invalid records are encountered.
  • Inspect expectation results on the relevant pipeline node and in monitoring/event logs. Choose actions according to business requirements; a warning alone does not clean the data.

How do you create, run, and verify an ETL pipeline?


  • In Databricks, select New → ETL pipeline (or navigate through Jobs & Pipelines), give the pipeline a name, and set its destination catalog and schema.
  • Add or select the SQL source file/notebook containing the streaming table and materialized view declarations. Unlike ordinary notebooks, the declarations are evaluated by the pipeline runtime, not by running each cell manually.
  • Confirm source-volume access, target-schema creation permissions, and the configured compute options; then select Run pipeline or Start as shown in your workspace.
  • View the pipeline graph: Bronze should feed Silver, which feeds Gold. Open nodes to inspect status, errors, processing details, and data quality expectation metrics.
  • Query the resulting Unity Catalog objects (use the actual names configured in your pipeline):
SELECT * FROM my_catalog.my_schema.employees_bronze LIMIT 10;
SELECT * FROM my_catalog.my_schema.employees_silver LIMIT 10;
SELECT * FROM my_catalog.my_schema.total_roles_gold;
  • Compare the Gold aggregates against a manually built Gold table to validate results. In Catalog Explorer, inspect Lineage to trace upstream and downstream dependencies.
  • For ongoing operation, configure pipeline updates or schedule the pipeline through Lakeflow Jobs. Monitor failed updates, expectation violations, and freshness; rerun after fixing issues.

Where can you learn more?