cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

SET configuration in SQL DLT pipeline not working

oteng
New Contributor III

I'm not able to get the SET command to work when using sql in DLT pipeline.

I am copying the code from this documentation https://docs.databricks.com/workflows/delta-live-tables/delta-live-tables-sql-ref.html#sql-spec (relevant code below). When I run something similar, I get empty value for ${startDate}. Any way to set a variable for the sql inside a notebook for DLT pipelines?

This is the code in the documentation

SET startDate='2020-01-01';
 
CREATE OR REFRESH LIVE TABLE filtered
AS SELECT * FROM src
WHERE date > ${startDate}

This is the code I tried running:

SET startDate='2020-01-01';
 
CREATE OR REFRESH LIVE TABLE filtered
AS SELECT * FROM (select '2021-01-01' as date)
WHERE date > ${startDate}

This is my error message when running dlt pipeline. It is setting ${startDate} to empty string. It works when I set the configuration value inside the settings of the dlt pipeline but not when I specify it in the notebook.:

image

2 REPLIES 2

Kaniz_Fatma
Community Manager
Community Manager

Hi @Oliver Tengโ€‹, Since the date column is not part of any table in the query, the condition WHERE date > ${startDate}will result in an error.

To fix this, you can either remove the subquery and directly specify the value of '2021-01-01'

in the WHERE clause:

SET startDate='2020-01-01';
 
CREATE OR REFRESH LIVE TABLE filtered
AS SELECT * FROM (SELECT '2021-01-01' as date)
WHERE '2021-01-01' > ${startDate};

Or you can modify the subquery to include the date column in a table:

SET startDate='2020-01-01';
 
CREATE OR REFRESH LIVE TABLE filtered
AS SELECT * FROM (
  SELECT โ€™2021-01-01โ€™ as date
  FROM (SELECT 1) -- Add a ***** table to create a single-row subquery
) t
WHERE date > ${startDate};

In this example, we add a ***** table with a single row to the subquery to create a table alias t with a single column date. We can then reference the date in the WHERE clause.

Anonymous
Not applicable

Hi @Oliver Tengโ€‹ 

Hope all is well! Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help. 

We'd love to hear from you.

Thanks!

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group