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: 

Delta Live Tables Quality check for distinct Values

Zii
New Contributor II

Hi All,

I have been having an issue identifying how to do a uniqueness check for the quality check. Below is an example.

@dlt.expect("origin_not_dup", "origin is distinct from origin")
def harmonized_data():
    df=dlt.read("raw_data")
    for col in df.columns:
        df = df.withColumnRenamed(col, col.lower())
    df=df.select("car", "mpg", "origin")
    return df

 options that i tried.

  • @dlt.expect("origin_not_dup", "origin is distinct from origin")
  • @dlt.expect("origin_not_dup", "origin is distinct")
  • @dlt.expect("origin_not_dup", "origin is unique")

they all end up with an error.

Since Delta live table is still relatively new, i wasn't able find how to do so. Any guidance is appreciated.

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions

Kaniz_Fatma
Community Manager
Community Manager

Hi @Ramzi Alashabi​ , Use the expect, expect or drop, and expect or fail expectations with Python or SQL queries to define a single data quality constraint.

You can define expectations with one or more data quality constraints in Python pipelines using the @expect_all, @expect_all_or_drop, and @expect_all_or_fail decorators.

These decorators accept a Python dictionary as an argument, where the key is the expectation name and the value is the expectation constraint.

  • You can explore a few examples here.

View solution in original post

2 REPLIES 2

Kaniz_Fatma
Community Manager
Community Manager

Hi @Ramzi Alashabi​ , Use the expect, expect or drop, and expect or fail expectations with Python or SQL queries to define a single data quality constraint.

You can define expectations with one or more data quality constraints in Python pipelines using the @expect_all, @expect_all_or_drop, and @expect_all_or_fail decorators.

These decorators accept a Python dictionary as an argument, where the key is the expectation name and the value is the expectation constraint.

  • You can explore a few examples here.

Kaniz_Fatma
Community Manager
Community Manager

Hi @Ramzi Alashabi​ , We haven’t heard from you on the last response from me, and I was checking back to see if you have a resolution yet. If you have any solution, please share it with the community as it can be helpful to others. Otherwise, we will respond with more details and try to help.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!