cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Delta Live table expectations

manish1987c
New Contributor II

I am able to ues expectation feature in delta live table using by creating the expectations as below 

 

 
checks = {}
checks["validate circuitId col for null values"] = "(circuitId IS not NULL)"
checks["validate name col for null values"] = "(name IS not NULL)"
dq_rules = "({0})".format("AND ".join(checks.values()))
 
and able to use it as 
 
@dlt.table(
    name = "stag_silver_table",
)
@dlt.expect_all_or_drop(checks)
def stag_silver_table():
    df= dlt.readStream("bronze_table").withColumn("is_valid", expr(dq_rules))
    return df
 
 
However if i change these expectation as 
 
checks = {}
checks["validate circuitId col for null values"] = "(circuitId IS NULL)"
checks["validate name col for null values"] = "(name IS NULL)"
dq_rules = "({0})".format("AND ".join(checks.values()))
 
and try to apply in another function then it is not working 
 
@dlt.table(
    name = "stag_silver_table1",
)
@dlt.expect_all_or_drop(checks)
def stag_silver_table1():
    df= dlt.readStream("bronze_table").withColumn("is_valid", expr(dq_rules))
    return df
 
 
Please suggest if there is any gap in understand as why it is not working
2 REPLIES 2

Kaniz
Community Manager
Community Manager

Hi @manish1987c, To dynamically generate expectations based on different conditions, you can create the dlt table inside an if condition.

If you encounter any further issues, feel free to ask for additional assistance! ๐Ÿ˜Š

manish1987c
New Contributor II

no i am not looking for any dynamic solution as of now i just want to perform data quality checks based on below checks in DLT 

 

checks = {}
checks["validate circuitId col for null values"= "(circuitId IS NULL)"
checks["validate name col for null values"= "(name IS NULL)"
dq_rules = "({0})".format("AND ".join(checks.values()))
 
but it is not working 
Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.