Hello! Let's dive into the next lesson on Delta Live Tables.
In our previous lesson, we focused on when a DLT pipeline runs by differentiating between triggered and continuous execution modes. This gave you control over the trade-off between data freshness and cost.
Now, we'll address the equally important question of where the pipeline's output data is stored. Properly managing the destination of your tables is crucial for organization, security, and discoverability within your lakehouse. By the end of this lesson, you will be able to configure DLT pipeline settings, including the target schema and storage location.
Understanding Target Schema and Storage Location
When a DLT pipeline runs, it creates tables and stores their underlying data files. These two aspects are managed through two key settings:
-
Target Schema: This is the logical identifier for your tables within Databricks. It specifies the database (or in Unity Catalog, the
catalogandschema) where your tables will be registered. Once registered, they become discoverable and can be queried by anyone with the correct permissions, just like any other table. -
Storage Location: This is the physical path in cloud storage (like Amazon S3 or Azure Data Lake Storage) where the actual data files (in Delta format) and pipeline metadata are saved.
While related, they serve different purposes. The target schema provides a user-friendly name for querying, while the storage location points to the data's physical home.
Configuring the Default Destination in the UI
The most straightforward way to manage your pipeline's destination is by setting a default location in the pipeline's configuration UI. Let's walk through where to find these settings.
Delta Live Table 101: Streamline your data pipeline
This article provides a clear, step-by-step guide to the DLT pipeline settings interface. It's a great starting point for understanding the various configuration options available.
Please read the section titled 'Step 8—Configuring Pipeline Settings'. Focus on the 'Destination' and 'Compute' settings, as they are central to our topic.
As you read, the Destination setting is key. You can specify a target schema (or database) where your pipeline will publish its tables. If you leave the Storage location blank, Databricks automatically creates a directory for your pipeline's data and metadata.
Let's see a quick demonstration of this in action.
Databricks : Delta Live Tables (DLT) | Azure Databricks DLT
This video clip shows the process of creating a new DLT pipeline and configuring its settings, including the target schema.
Watch from 03:18 to 04:49 and then from 06:11 to 08:14. Observe how the 'Target schema' is specified during creation and how you can revisit the settings later to see other options like storage location.
The interface has been updated since that video was made, especially with the deep integration of Unity Catalog. Here is what the modern UI for configuring the destination looks like:
As you can see, you now explicitly choose whether to publish your tables to the older Hive Metastore or to the modern Unity Catalog. For the certification and modern data engineering practices, Unity Catalog is the recommended choice. When you select it, you must provide:
- Catalog: The top-level container in Unity Catalog's three-level namespace.
- Target schema: The schema (or database) within that catalog.
Any tables created by this pipeline (e.g., CREATE LIVE TABLE my_bronze_table) will, by default, be created as your_catalog.your_schema.my_bronze_table.
Advanced Control: Overriding the Default Destination in Code
Setting a default destination is convenient, but what if you want to publish different tables from the same pipeline to different locations? For example, you might process Bronze and Silver tables in a development schema but want to publish the final Gold table to a separate, governed production schema.
DLT allows you to override the pipeline's default destination directly in your code. The official Databricks documentation explains this feature well.
Set the target catalog and schema
This documentation page is the authoritative source on how to target different schemas within a DLT pipeline. It provides clear code examples for both SQL and Python.
Please read the entire page. Pay close attention to the code examples in the section 'Target a dataset in a different catalog or schema', which demonstrate how to use a fully-qualified three-part name. Also, note the use of the USE CATALOG and USE SCHEMA commands.
Let's summarize the key techniques from the documentation:
1. Using Fully-Qualified Names
This is the most direct and explicit method. You can specify the full three-level namespace name (catalog.schema.table) when defining a table. This overrides any default pipeline settings for that specific table.
SQL Example:
-- This table will be created in the 'prod_analytics' catalog and 'gold' schema,
-- regardless of the pipeline's default destination settings.
CREATE OR REPLACE LIVE TABLE prod_analytics.gold.daily_sales_summary
COMMENT "Daily aggregated sales summary"
AS SELECT
transaction_date,
SUM(sales_amount) as total_sales
FROM LIVE.silver_sales
GROUP BY transaction_date;
Python Example:
import dlt
# This materialized view will be created in 'prod_analytics.gold',
# overriding the pipeline's default.
@dlt.table(
name="prod_analytics.gold.daily_sales_summary",
comment="Daily aggregated sales summary"
)
def daily_sales_summary():
return (
dlt.read("silver_sales")
.groupBy("transaction_date")
.agg(F.sum("sales_amount").alias("total_sales"))
)
This method gives you granular control and makes your code's intentions very clear.
2. Using USE CATALOG and USE SCHEMA
In SQL, you can use these commands at the top of a notebook. They change the default context for all subsequent DLT table definitions within that specific notebook.
USE CATALOG prod_analytics;
USE SCHEMA gold;
-- Because of the USE commands above, this table will be created as
-- 'prod_analytics.gold.daily_sales_summary' without needing the full name.
CREATE OR REPLACE LIVE TABLE daily_sales_summary
AS SELECT ...
This can be useful for organizing code but is less explicit than using fully-qualified names for each table.
Let's watch a video that demonstrates this powerful override capability.
52 Lakeflow Spark Declarative Pipelines | New Pipeline Code Editor | AUTO CDC |External Target Sinks
This clip explains and demonstrates the 'default publishing mode', which is exactly the concept of overriding the default schema from within your code.
Watch from 31:15 to 32:44. The presenter shows how to use a three-level namespace in the @dlt.materialized_view decorator to publish a table to a different location, overriding the pipeline's default schema.
Writing to External Locations with Sinks
Finally, sometimes you may need to write the output of a pipeline to a standard Delta table that is not managed by DLT. This is useful for integrating with other processes that expect a regular Delta table. DLT provides a mechanism called a sink for this purpose.
A sink allows you to take the final output of a transformation and write it to a specified external Delta table.
52 Lakeflow Spark Declarative Pipelines | New Pipeline Code Editor | AUTO CDC |External Target Sinks
Let's revisit the 'Ease With Data' video to learn about sinks. This demonstrates another way to control the final destination of your data.
Watch from 22:19 to 24:26. Focus on how a sync is created and configured to write to a specific target Delta table, identified by its catalog, schema, and table name.
Using a sink provides ultimate control over the output, effectively detaching it from the DLT pipeline's own managed tables and placing it in a location of your choice.
Conclusion
You now have a comprehensive understanding of how to control where your DLT pipeline's data is stored, both logically and physically.
Key Takeaways
- Target Schema vs. Storage Location: The target schema is the logical address in the metastore (e.g.,
my_catalog.my_schema), while the storage location is the physical path in cloud storage. - UI Configuration: You can set a default
CatalogandTarget schemafor your entire pipeline in the DLT settings UI. This is the primary destination for all tables created by the pipeline. - Code Overrides: For granular control, you can override the default destination for individual tables using fully-qualified three-part names (
catalog.schema.table) in your SQL or Python code. - Sinks: Use a
sinkto write a pipeline's output to a standard, external Delta table, giving you full control over the final destination.
Next Steps
You've learned how to configure when a pipeline runs and where it stores its data. The next logical step is to understand what happens during a run. In our next lesson, we will focus on monitoring pipeline runs and interpreting the DLT event log for troubleshooting, which is essential for maintaining healthy, production-grade data pipelines.