<?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: Error when accessing 'num_inserted_rows' in Spark SQL (DBR 15.4 LTS) in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/error-when-accessing-num-inserted-rows-in-spark-sql-dbr-15-4-lts/m-p/107388#M42793</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;we are experiencing the same issue. We also turned on liquid clustering on table and we had additional checks on the inserted data information, which was really helpful.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/136362"&gt;@GavinReeves3&lt;/a&gt;&amp;nbsp;did you manage to solve the issue?&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/89478"&gt;@MuthuLakshmi&lt;/a&gt;&amp;nbsp;any idea? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;&lt;P&gt;George&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jan 2025 11:24:48 GMT</pubDate>
    <dc:creator>GeorgeP1</dc:creator>
    <dc:date>2025-01-28T11:24:48Z</dc:date>
    <item>
      <title>Error when accessing 'num_inserted_rows' in Spark SQL (DBR 15.4 LTS)</title>
      <link>https://community.databricks.com/t5/data-engineering/error-when-accessing-num-inserted-rows-in-spark-sql-dbr-15-4-lts/m-p/92372#M38417</link>
      <description>&lt;P&gt;Hello Databricks Community,&lt;/P&gt;&lt;P&gt;I've encountered an issue while trying to capture the number of rows inserted after executing an SQL insert statement in Databricks (DBR 15.4 LTS). My code is attempting to access the number of inserted rows as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;rows_insert = spark.sql(insert_statement).first()['num_inserted_rows']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I am receiving the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;TypeError: 'NoneType' object is not subscriptable&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Upon further investigation, I noticed that in the SQL execution result, the fields &lt;STRONG&gt;num_affected_rows&lt;/STRONG&gt; and &lt;STRONG&gt;num_inserted_rows&lt;/STRONG&gt; are shown, but no rows are actually returned. This can be seen in the screenshots I've attached:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The first image shows the result of my SQL insert, which displays the columns num_affected_rows and num_inserted_rows but with no actual rows returned.&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Buranapat_4-1727751428815.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11604i6801EA387C2A5A78/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Buranapat_4-1727751428815.png" alt="Buranapat_4-1727751428815.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;The second image shows the subsequent Python error when I try to access &lt;STRONG&gt;num_inserted_rows&lt;/STRONG&gt; from the result.&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Buranapat_3-1727750986067.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11603iAF9B3417305BC30E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Buranapat_3-1727750986067.png" alt="Buranapat_3-1727750986067.png" /&gt;&lt;/span&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;Has anyone else faced a similar issue? I would greatly appreciate any insights or suggestions on how to work around this problem.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 03:00:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-when-accessing-num-inserted-rows-in-spark-sql-dbr-15-4-lts/m-p/92372#M38417</guid>
      <dc:creator>Buranapat</dc:creator>
      <dc:date>2024-10-01T03:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: Error when accessing 'num_inserted_rows' in Spark SQL (DBR 15.4 LTS)</title>
      <link>https://community.databricks.com/t5/data-engineering/error-when-accessing-num-inserted-rows-in-spark-sql-dbr-15-4-lts/m-p/98111#M39612</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/123957"&gt;@Buranapat&lt;/a&gt;&amp;nbsp;Can you please try this check as a workaround?&lt;BR /&gt;result = spark.sql(insert_statement).first() &lt;BR /&gt;&lt;SPAN class="hljs-keyword"&gt;if&lt;/SPAN&gt; result &lt;SPAN class="hljs-keyword"&gt;is&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;not&lt;/SPAN&gt; &lt;SPAN class="hljs-literal"&gt;None&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;and&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;'num_inserted_rows'&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;in&lt;/SPAN&gt; result: &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num_inserted_rows = result[&lt;SPAN class="hljs-string"&gt;'num_inserted_rows'&lt;/SPAN&gt;] &lt;BR /&gt;&lt;SPAN class="hljs-keyword"&gt;else&lt;/SPAN&gt;: &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num_inserted_rows = &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 16:34:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-when-accessing-num-inserted-rows-in-spark-sql-dbr-15-4-lts/m-p/98111#M39612</guid>
      <dc:creator>MuthuLakshmi</dc:creator>
      <dc:date>2024-11-07T16:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: Error when accessing 'num_inserted_rows' in Spark SQL (DBR 15.4 LTS)</title>
      <link>https://community.databricks.com/t5/data-engineering/error-when-accessing-num-inserted-rows-in-spark-sql-dbr-15-4-lts/m-p/98300#M39676</link>
      <description>&lt;P&gt;Thank you for the suggestion! The workaround seems like a helpful way to quickly check insert success, though I’ve noticed that it sometimes returns None even when records appear to be successfully inserted. Do you know if this is a known issue, or if there are any plans to improve this behavior in future updates?&lt;/P&gt;&lt;P&gt;Thanks again for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2024 01:04:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-when-accessing-num-inserted-rows-in-spark-sql-dbr-15-4-lts/m-p/98300#M39676</guid>
      <dc:creator>Buranapat</dc:creator>
      <dc:date>2024-11-11T01:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Error when accessing 'num_inserted_rows' in Spark SQL (DBR 15.4 LTS)</title>
      <link>https://community.databricks.com/t5/data-engineering/error-when-accessing-num-inserted-rows-in-spark-sql-dbr-15-4-lts/m-p/102115#M40970</link>
      <description>&lt;P&gt;Hey all, commenting here for my own experience.&lt;/P&gt;&lt;P&gt;I am also experiencing the same issue but the problem seems to be Liquid Clustering that is removing all metadata from an inserted rows statement. Whenever I insert rows, it always returns None and some of my error handling fails. Is this a known bug?&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/89478"&gt;@MuthuLakshmi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2024 17:58:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-when-accessing-num-inserted-rows-in-spark-sql-dbr-15-4-lts/m-p/102115#M40970</guid>
      <dc:creator>GavinReeves3</dc:creator>
      <dc:date>2024-12-13T17:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: Error when accessing 'num_inserted_rows' in Spark SQL (DBR 15.4 LTS)</title>
      <link>https://community.databricks.com/t5/data-engineering/error-when-accessing-num-inserted-rows-in-spark-sql-dbr-15-4-lts/m-p/107388#M42793</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;we are experiencing the same issue. We also turned on liquid clustering on table and we had additional checks on the inserted data information, which was really helpful.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/136362"&gt;@GavinReeves3&lt;/a&gt;&amp;nbsp;did you manage to solve the issue?&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/89478"&gt;@MuthuLakshmi&lt;/a&gt;&amp;nbsp;any idea? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;&lt;P&gt;George&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 11:24:48 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-when-accessing-num-inserted-rows-in-spark-sql-dbr-15-4-lts/m-p/107388#M42793</guid>
      <dc:creator>GeorgeP1</dc:creator>
      <dc:date>2025-01-28T11:24:48Z</dc:date>
    </item>
  </channel>
</rss>

