<?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 Autoloader streaming table - how to determine if new rows were updated from query? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/autoloader-streaming-table-how-to-determine-if-new-rows-were/m-p/111294#M43845</link>
    <description>&lt;P&gt;If I'm running a scheduled batch Autoloader query which read from csv files on S3 and incrementally loads a delta table, how can I determine if new rows were added?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm currently trying to do this from the streaming query.lastProgress as follows.&amp;nbsp; self._q is the query established elsewhere by the class.:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def new_data_appended(self):
        if hasattr(self, "_q"):
            self._q.awaitTermination()
            lastProgress = self._q.lastProgress
            sink = lastProgress.get("sink", None)
            if sink:
                numOutputRows = sink.get("numOutputRows", None)
            else:
                return None
            if numOutputRows:
                print(f"numOutputRows: {numOutputRows}")
                if numOutputRows == -1:
                    return False
                else:
                    return True
            else:
                return None
        else:
            raise ValueError("Query status (_q) is not available in self.")&lt;/LI-CODE&gt;&lt;P&gt;But, I'm finding numOutputRows seems to always be -1 whether rows were updated or not?&amp;nbsp; &amp;nbsp; I guess I could create a deltaTables object and look at the last history record.&amp;nbsp; but, seems like this would be available in the query.&lt;/P&gt;&lt;P&gt;I "think" my streaming operation is not stateful meaning that this really isn't a real time stream.&amp;nbsp; &amp;nbsp;My files change every few weeks but I'm using Auttoloader to simplify tracking what is new and incrementally loading.&amp;nbsp; So, no real time batch windows or watermarking, etc.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Feb 2025 17:56:09 GMT</pubDate>
    <dc:creator>lprevost</dc:creator>
    <dc:date>2025-02-26T17:56:09Z</dc:date>
    <item>
      <title>Autoloader streaming table - how to determine if new rows were updated from query?</title>
      <link>https://community.databricks.com/t5/data-engineering/autoloader-streaming-table-how-to-determine-if-new-rows-were/m-p/111294#M43845</link>
      <description>&lt;P&gt;If I'm running a scheduled batch Autoloader query which read from csv files on S3 and incrementally loads a delta table, how can I determine if new rows were added?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm currently trying to do this from the streaming query.lastProgress as follows.&amp;nbsp; self._q is the query established elsewhere by the class.:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def new_data_appended(self):
        if hasattr(self, "_q"):
            self._q.awaitTermination()
            lastProgress = self._q.lastProgress
            sink = lastProgress.get("sink", None)
            if sink:
                numOutputRows = sink.get("numOutputRows", None)
            else:
                return None
            if numOutputRows:
                print(f"numOutputRows: {numOutputRows}")
                if numOutputRows == -1:
                    return False
                else:
                    return True
            else:
                return None
        else:
            raise ValueError("Query status (_q) is not available in self.")&lt;/LI-CODE&gt;&lt;P&gt;But, I'm finding numOutputRows seems to always be -1 whether rows were updated or not?&amp;nbsp; &amp;nbsp; I guess I could create a deltaTables object and look at the last history record.&amp;nbsp; but, seems like this would be available in the query.&lt;/P&gt;&lt;P&gt;I "think" my streaming operation is not stateful meaning that this really isn't a real time stream.&amp;nbsp; &amp;nbsp;My files change every few weeks but I'm using Auttoloader to simplify tracking what is new and incrementally loading.&amp;nbsp; So, no real time batch windows or watermarking, etc.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 17:56:09 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/autoloader-streaming-table-how-to-determine-if-new-rows-were/m-p/111294#M43845</guid>
      <dc:creator>lprevost</dc:creator>
      <dc:date>2025-02-26T17:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Autoloader streaming table - how to determine if new rows were updated from query?</title>
      <link>https://community.databricks.com/t5/data-engineering/autoloader-streaming-table-how-to-determine-if-new-rows-were/m-p/111398#M43878</link>
      <description>&lt;P&gt;If you're using foreachBatch, it is possible that the numOutputRows will display 0, for a myriad of reasons. The easiest approach is to view the last entry in the Delta table you are inserting into.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;DeltaTable.forName(spark, table_name).history(1).collect() # ...

&lt;/LI-CODE&gt;
&lt;P&gt;If this isn't suitable, you can use the &lt;A href="https://api-docs.databricks.com/python/pyspark/latest/pyspark.sql/api/pyspark.sql.DataFrame.observe.html?highlight=observe#pyspark.sql.DataFrame.observe" target="_self"&gt;Observe API&lt;/A&gt;, which will collect metrics from your dataframe and put them into lastP&lt;SPAN class="token plain"&gt;rogress&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token plain"&gt;observedMetrics. More to read &lt;A href="https://docs.databricks.com/aws/en/structured-streaming/stream-monitoring#defining-observable-metrics-in-structured-streaming" target="_self"&gt;here&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2025 17:45:59 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/autoloader-streaming-table-how-to-determine-if-new-rows-were/m-p/111398#M43878</guid>
      <dc:creator>cgrant</dc:creator>
      <dc:date>2025-02-27T17:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: Autoloader streaming table - how to determine if new rows were updated from query?</title>
      <link>https://community.databricks.com/t5/data-engineering/autoloader-streaming-table-how-to-determine-if-new-rows-were/m-p/111468#M43902</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 15:02:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/autoloader-streaming-table-how-to-determine-if-new-rows-were/m-p/111468#M43902</guid>
      <dc:creator>lprevost</dc:creator>
      <dc:date>2025-02-28T15:02:01Z</dc:date>
    </item>
  </channel>
</rss>

