<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to use dlt.expect to validate table level constraints? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-use-dlt-expect-to-validate-table-level-constraints/m-p/88670#M37567</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/109070"&gt;@guangyi&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Unfortunately, there is no out of the box solution for this requirement in dlt. But as a workaround you can add an&amp;nbsp;&lt;SPAN&gt;additional view/table to your pipeline that defines an expectation in similar way to below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;CREATE OR REFRESH MATERIALIZED VIEW count_verification(
  CONSTRAINT no_rows_dropped EXPECT (a_count == your_numbers)
) AS SELECT * FROM
  (SELECT COUNT(*) AS a_count FROM LIVE.tbla)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The results of this expectation appear in the event log and the Delta Live Tables UI.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/azure/databricks/delta-live-tables/expectations#validate-row-counts-across-tables" target="_blank" rel="noopener"&gt;Manage data quality with Delta Live Tables - Azure Databricks | Microsoft Learn&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Sep 2024 08:12:23 GMT</pubDate>
    <dc:creator>szymon_dybczak</dc:creator>
    <dc:date>2024-09-05T08:12:23Z</dc:date>
    <item>
      <title>How to use dlt.expect to validate table level constraints?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-dlt-expect-to-validate-table-level-constraints/m-p/88665#M37566</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I know how to validate the column level constraint, like checking whether the specified column value is larger than target value.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Can I validate some table level constraints? For example, validate whether the total records count of a table is larger than the specified number. Or validate the foreign key between two tables.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I tried this way but it is now working:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/97035"&gt;@Dlt&lt;/a&gt;.expect("valid records count", "count('*') &amp;gt; 7500000")&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;I also tried to do `expect` inside the DLT pipeline function. The function can run successfully but I cannot find the result in the quality tab or the in &lt;A href="https://docs.databricks.com/en/delta-live-tables/observability.html" target="_self"&gt;event logs&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/97035"&gt;@Dlt&lt;/a&gt;.table
def bronze_table():
  df = spark.read.table("samples.tpch.orders")
  dlt.expect("valid records count", df.count() &amp;gt; 7500000)
  return df&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;Can I achieve this with dlt.expect?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2024 07:27:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-dlt-expect-to-validate-table-level-constraints/m-p/88665#M37566</guid>
      <dc:creator>guangyi</dc:creator>
      <dc:date>2024-09-05T07:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to use dlt.expect to validate table level constraints?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-dlt-expect-to-validate-table-level-constraints/m-p/88670#M37567</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/109070"&gt;@guangyi&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Unfortunately, there is no out of the box solution for this requirement in dlt. But as a workaround you can add an&amp;nbsp;&lt;SPAN&gt;additional view/table to your pipeline that defines an expectation in similar way to below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;CREATE OR REFRESH MATERIALIZED VIEW count_verification(
  CONSTRAINT no_rows_dropped EXPECT (a_count == your_numbers)
) AS SELECT * FROM
  (SELECT COUNT(*) AS a_count FROM LIVE.tbla)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The results of this expectation appear in the event log and the Delta Live Tables UI.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/azure/databricks/delta-live-tables/expectations#validate-row-counts-across-tables" target="_blank" rel="noopener"&gt;Manage data quality with Delta Live Tables - Azure Databricks | Microsoft Learn&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2024 08:12:23 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-dlt-expect-to-validate-table-level-constraints/m-p/88670#M37567</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2024-09-05T08:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use dlt.expect to validate table level constraints?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-dlt-expect-to-validate-table-level-constraints/m-p/88685#M37576</link>
      <description>&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2024 08:57:59 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-dlt-expect-to-validate-table-level-constraints/m-p/88685#M37576</guid>
      <dc:creator>guangyi</dc:creator>
      <dc:date>2024-09-05T08:57:59Z</dc:date>
    </item>
  </channel>
</rss>

