Delta Live Tables (DLT) in Databricks is a framework. It is designed to simplify building reliable and efficient data pipelines. These pipelines cater to streaming and batch workloads. It provides built-in capabilities for managing, monitoring, and optimizing data workflows on Delta Lake using the Databricks platform. Some key features include.
Delta Live Tables in Databricks
Databricks DLT with Python and SQL
DLT allows you to define transformations using SQL or Python. Here’s an example of both.
SQL Example:
-- Define a raw table to ingest the data
CREATE LIVE TABLE raw_user_logs
COMMENT "Ingested raw user activity logs"
TBLPROPERTIES ("quality" = "bronze")
AS SELECT * FROM cloud_files("/mnt/data/logs/", "json");
-- Define a cleaned table with filters and transformations
CREATE LIVE TABLE clean_user_logs
COMMENT "Cleaned user activity logs"
TBLPROPERTIES ("quality" = "silver")
AS
SELECT
user_id,
action,
timestamp,
CAST(timestamp AS DATE) AS action_date
FROM LIVE.raw_user_logs
WHERE user_id IS NOT NULL AND action IS NOT NULL;
Python Example:
import dlt
from pyspark.sql.functions import col, to_date
# Bronze layer: raw ingestion
@dlt.table(
name="raw_user_logs",
comment="Ingested raw user activity logs",
table_properties={"quality": "bronze"}
)
def raw_user_logs():
return spark.read.format("json").load("/mnt/data/logs/")
# Silver layer: cleaned data
@dlt.table(
name="clean_user_logs",
comment="Cleaned user activity logs",
table_properties={"quality": "silver"}
)
def clean_user_logs():
return (
dlt.read("raw_user_logs")
.filter(col("user_id").isNotNull() & col("action").isNotNull())
.withColumn("action_date", to_date("timestamp"))
.select("user_id", "action", "timestamp", "action_date")
)
In this case, you’re creating a table silver_table. It filters out rows where age is less than or equal to 18.
Automated Data Management
DLT automatically manages the optimization and metadata. Also, automation batch and streaming jobs. Here’s how you can declare a streaming table in Python and DLT will handle the stream’s incremental ingestion:
import dlt
@dlt.table
def streaming_table():
return (
spark.readStream.format("json").load("/path/to/stream/data")
.select("event_id", "timestamp", "user_id")
)
DLT will automatically handle the complexities of stream processing, like checkpointing and incremental loads.
Built-in Quality Checks
You can enforce data quality checks using expectations. If a record fails to meet expectations, the DLT handles the failure or triggers appropriate actions.
import dlt
@dlt.expect_or_drop("valid_age", "age > 0")
@dlt.expect("non_empty_name", "name IS NOT NULL")
@dlt.table
def validated_table():
return spark.read("bronze_table").select("id", "name", "age")
In this example, DLT ensures that the age column is positive and not null. Records not meeting these criteria are dropped or logged based on the expectation definition.
streaming and batch pipelines in Databricks
Natively, DLT supports both batch and streaming data, allowing you to create tables for each in the same pipeline. Here’s an example of how to manage both.
# Python Example for Batch and Streaming:
# Ingest batch data
import dlt
from pyspark.sql.functions import col
@dlt.table(
name="users",
comment="Batch user profile data",
table_properties={"quality": "bronze"}
)
def users():
return spark.read.format("json").load("/mnt/data/users/")
# Ingest streaming data
@dlt.table(
name="user_events_streaming",
comment="Streaming user clickstream events",
table_properties={"quality": "bronze"}
)
def user_events_streaming():
return (
spark.readStream
.format("json")
.option("maxFilesPerTrigger", 1)
.load("/mnt/data/events/")
)
# Join batch and streaming
@dlt.table(
name="enriched_user_events",
comment="User events joined with profile data",
table_properties={"quality": "silver"}
)
def enriched_user_events():
users_df = dlt.read("users") # batch
events_df = dlt.read_stream("user_events_streaming") # streaming
return events_df.join(users_df, on="user_id", how="left")
DLT will handle the batch and streaming ingestion separately, but you can unify the tables in downstream transformations if needed.
Monitoring and Alerts
DLT provides built-in metrics, monitoring, and alerting. You can see these in the Databricks UI, but DLT also lets you define custom metrics using Python:
Python Example with Monitoring:
import dlt
@dlt.table
def monitored_table():
return spark.read("bronze_table").filter("status = 'active'")
# DLT automatically generates metrics for rows processed, errors, etc., and you can view these in the Databricks dashboard.
How to Use Delta Live Tables
Create a Notebook or Python Script
You can create DLT pipelines using Databricks notebooks or scripts. Within the framework provided by Delta Live Tables, you can define transformations using SQL or Python functions.
Define a simple Delta Live Table pipeline
Using SQL:
CREATE LIVE TABLE filtered_view
AS SELECT * FROM bronze_table WHERE status = 'active';
Using Python (with PySpark):
import dlt
@dlt.table
def filtered_view():
return spark.read("bronze_table").filter("status = 'active'")
Define Data Quality Expectations
You can define expectations on tables to guarantee data quality, and DLT will handle validation automatically.
import dlt
@dlt.expect_or_fail("valid_status", "status IN ('active', 'inactive')")
@dlt.table
def filtered_view():
return spark.read("bronze_table")
Deployment
To deploy a Delta Live Table pipeline, you must set it up in the Databricks UI. Specify the source, target, and any relevant settings, and then run the pipeline.
Monitoring and Managing Pipelines
DLT integrates with the Databricks UI. It lets you view metrics and logs. You can check the pipeline status and view detailed lineage information for the tables created.
Benefits of Delta Live Tables
- Reduced Manual Work: DLT automates several aspects of the pipeline like retries, optimizations, and alerting.
- Data Consistency: It uses Delta Lake ensuring ACID transactions, schema enforcement, and data versioning.
- Scalability: With built-in support for handling batch and streaming data, DLT can scale up for complex, large data applications.






