<?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 &amp;quot;approxQuantile&amp;quot; not working as part of a delta live table workflow pipeline. in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/quot-approxquantile-quot-not-working-as-part-of-a-delta-live/m-p/18538#M12314</link>
    <description>&lt;P&gt;I am trying to compute outliers using approxQuantile on a Dataframe.&amp;nbsp;It works fine in a Databricks notebook, but the call doesn't work correctly when it is part of a delta live table pipeline.  (This is python.)  Here is the line that isn't working as part of the pipeline.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;quantiles = session_agg_df.approxQuantile('duration_minutes', [0.25, 0.75], 0)&lt;/P&gt;&lt;P&gt;Q1 = quantiles[0]  # &amp;lt;--  Fails as part of dlt pipeline, but works in notebook&lt;/P&gt;&lt;P&gt;Q3 = quantiles[1]  # &amp;lt;--  Fails as part of dlt pipeline, but works in notebook&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The pipeline fails with "IndexError: list index out of range".  Again, it works just fine in a notebook on the same data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(I am trying to look for outliers in my pipeline using a very basic +/- 1.5*IQR approach.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, if anybody has any suggestions on best practices for writing and debugging dlt pipelines, I'd love to hear them!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Miles Porter&lt;/P&gt;&lt;P&gt;Lead Data Scientist&lt;/P&gt;&lt;P&gt;Trimble, Inc.&lt;/P&gt;</description>
    <pubDate>Mon, 05 Dec 2022 17:01:24 GMT</pubDate>
    <dc:creator>899572</dc:creator>
    <dc:date>2022-12-05T17:01:24Z</dc:date>
    <item>
      <title>"approxQuantile" not working as part of a delta live table workflow pipeline.</title>
      <link>https://community.databricks.com/t5/data-engineering/quot-approxquantile-quot-not-working-as-part-of-a-delta-live/m-p/18538#M12314</link>
      <description>&lt;P&gt;I am trying to compute outliers using approxQuantile on a Dataframe.&amp;nbsp;It works fine in a Databricks notebook, but the call doesn't work correctly when it is part of a delta live table pipeline.  (This is python.)  Here is the line that isn't working as part of the pipeline.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;quantiles = session_agg_df.approxQuantile('duration_minutes', [0.25, 0.75], 0)&lt;/P&gt;&lt;P&gt;Q1 = quantiles[0]  # &amp;lt;--  Fails as part of dlt pipeline, but works in notebook&lt;/P&gt;&lt;P&gt;Q3 = quantiles[1]  # &amp;lt;--  Fails as part of dlt pipeline, but works in notebook&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The pipeline fails with "IndexError: list index out of range".  Again, it works just fine in a notebook on the same data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(I am trying to look for outliers in my pipeline using a very basic +/- 1.5*IQR approach.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, if anybody has any suggestions on best practices for writing and debugging dlt pipelines, I'd love to hear them!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Miles Porter&lt;/P&gt;&lt;P&gt;Lead Data Scientist&lt;/P&gt;&lt;P&gt;Trimble, Inc.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 17:01:24 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/quot-approxquantile-quot-not-working-as-part-of-a-delta-live/m-p/18538#M12314</guid>
      <dc:creator>899572</dc:creator>
      <dc:date>2022-12-05T17:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: "approxQuantile" not working as part of a delta live table workflow pipeline.</title>
      <link>https://community.databricks.com/t5/data-engineering/quot-approxquantile-quot-not-working-as-part-of-a-delta-live/m-p/18539#M12315</link>
      <description>&lt;P&gt;As it is returning a list, it can not work on the stream, especially with dlt, which is CREATE TABLE AS SELECT STATMENT&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 17:09:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/quot-approxquantile-quot-not-working-as-part-of-a-delta-live/m-p/18539#M12315</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2022-12-05T17:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: "approxQuantile" not working as part of a delta live table workflow pipeline.</title>
      <link>https://community.databricks.com/t5/data-engineering/quot-approxquantile-quot-not-working-as-part-of-a-delta-live/m-p/18540#M12316</link>
      <description>&lt;P&gt;Thanks for the quick answer, Hubert.  Could you provide a bit more information?  Is there a way to compute quantiles on columns in a dlt workflow? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Miles Porter &lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 17:38:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/quot-approxquantile-quot-not-working-as-part-of-a-delta-live/m-p/18540#M12316</guid>
      <dc:creator>899572</dc:creator>
      <dc:date>2022-12-05T17:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: "approxQuantile" not working as part of a delta live table workflow pipeline.</title>
      <link>https://community.databricks.com/t5/data-engineering/quot-approxquantile-quot-not-working-as-part-of-a-delta-live/m-p/18541#M12317</link>
      <description>&lt;P&gt;try that&lt;/P&gt;&lt;P&gt;&lt;A href="https://spark.apache.org/docs/3.1.3/api/python/reference/api/pyspark.sql.functions.percentile_approx.html" target="test_blank"&gt;https://spark.apache.org/docs/3.1.3/api/python/reference/api/pyspark.sql.functions.percentile_approx.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;there is also Psypark Pandas function but haven't used  Pandas on Spark with dlt&lt;/P&gt;&lt;P&gt;&lt;A href="https://spark.apache.org/docs/latest/api/python/reference/pyspark.pandas/api/pyspark.pandas.DataFrame.quantile.html" target="test_blank"&gt;https://spark.apache.org/docs/latest/api/python/reference/pyspark.pandas/api/pyspark.pandas.DataFrame.quantile.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 19:59:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/quot-approxquantile-quot-not-working-as-part-of-a-delta-live/m-p/18541#M12317</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2022-12-05T19:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: "approxQuantile" not working as part of a delta live table workflow pipeline.</title>
      <link>https://community.databricks.com/t5/data-engineering/quot-approxquantile-quot-not-working-as-part-of-a-delta-live/m-p/18542#M12318</link>
      <description>&lt;P&gt;Good recommendation.  I was able to do something similar that appears to work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Step 2.  Compute the is outlier sessions based on duration_minutes&lt;/P&gt;&lt;P&gt;    lc = session_agg_df.selectExpr("percentile(duration_minutes, 0.25) lower_quartile")&lt;/P&gt;&lt;P&gt;    session_agg_df = session_agg_df.join(lc, how="outer")&lt;/P&gt;&lt;P&gt;    uc = session_agg_df.selectExpr("percentile(duration_minutes, 0.75) upper_quartile")&lt;/P&gt;&lt;P&gt;    session_agg_df = session_agg_df.join(uc, how="outer")&lt;/P&gt;&lt;P&gt;    session_agg_df = session_agg_df.withColumn('iqr', session_agg_df['upper_quartile']-session_agg_df['lower_quartile']) &lt;/P&gt;&lt;P&gt;    session_agg_df = session_agg_df.withColumn('lower_limit', session_agg_df['lower_quartile'] - (1.5 * session_agg_df['iqr']))&lt;/P&gt;&lt;P&gt;    session_agg_df = session_agg_df.withColumn('upper_limit', session_agg_df['upper_quartile'] + (1.5 * session_agg_df['iqr']))&lt;/P&gt;&lt;P&gt;    session_agg_df = session_agg_df.withColumn('is_outlier', f.when( (session_agg_df['duration_minutes']&amp;lt;session_agg_df['lower_limit']) | \&lt;/P&gt;&lt;P&gt;    (session_agg_df['duration_minutes'] &amp;gt; session_agg_df['upper_limit']),1).otherwise(0))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am sure there are more optimal ways of doing this, but the above does appear to flag the outliers (based on the IQR method) on my data.  Posting incase anyone else gets stuck on this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Miles&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 20:24:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/quot-approxquantile-quot-not-working-as-part-of-a-delta-live/m-p/18542#M12318</guid>
      <dc:creator>899572</dc:creator>
      <dc:date>2022-12-05T20:24:07Z</dc:date>
    </item>
  </channel>
</rss>

