<?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: ISSUE: PySpark task exception handling on &amp;quot;Shared Compute&amp;quot; cluster in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/issue-pyspark-task-exception-handling-on-quot-shared-compute/m-p/86646#M37322</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/118163"&gt;@geronimo_signol&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;Recently, other user has reported similar behavior on shared clusters, and both issues seem to be related to Spark Connect.&lt;BR /&gt;To verify whether your cluster is using Spark Connect, please run the following code in your notebook:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;print(type(spark))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the output shows &amp;lt;class 'pyspark.sql.connect.session.SparkSession'&amp;gt;, then your cluster is using Spark Connect. If it shows &amp;lt;class 'pyspark.sql.session.SparkSession'&amp;gt;, then it is normal spark.&lt;BR /&gt;If it occurs on the cluster that uses Spark Connect, it mostly does not handle well schema updates.&lt;/P&gt;&lt;P&gt;Try the following:&lt;BR /&gt;1.&amp;nbsp;Verify Schema Before Transformation.&amp;nbsp;Print the schema of the DataFrame to confirm that operator_lastname is present.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sdf = spark.table("`bronze_catalog`.`client_xyz`.`crew_data`")
sdf.printSchema()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2.&amp;nbsp;Check Column Existence.&amp;nbsp;Before applying transformations, explicitly check if the column exists.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if 'operator_lastname' in sdf.columns:
    sdf = sdf.withColumn('transformed_failed', F.expr("UPPER(CAST(`operator_lastname` AS STRING))"))
else:
    print("[ERROR] Column 'operator_lastname' does not exist in the DataFrame.")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Try to use caching to trigger schema refresh.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sdf = sdf.cache()  # Refresh the DataFrame schema&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Aug 2024 18:49:31 GMT</pubDate>
    <dc:creator>filipniziol</dc:creator>
    <dc:date>2024-08-29T18:49:31Z</dc:date>
    <item>
      <title>ISSUE: PySpark task exception handling on "Shared Compute" cluster</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-pyspark-task-exception-handling-on-quot-shared-compute/m-p/86368#M37315</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am experiencing an issue with a PySpark job that behaves differently depending on the compute environment in Databricks. And this is blocking us from deploying the job into the PROD environment for our planned release.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Specifically:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- When running the job on a personal cluster, everything works as expected. All exceptions within the try/catch blocks are successfully caught and handled.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- However, when I run the same job on a shared cluster, it fails, and no exceptions are being caught by the try/catch blocks.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Any guidance or insights you could provide would be greatly appreciated.&lt;/P&gt;&lt;P&gt;Example (running piece of code in a workspace notebook):&amp;nbsp;&lt;A href="https://github.com/user-attachments/assets/78b38c5a-98f6-4bb0-82c3-45946d6c5500" target="_blank" rel="noopener"&gt;https://github.com/user-attachments/assets/78b38c5a-98f6-4bb0-82c3-45946d6c5500&lt;/A&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;Any ideas?&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/85537"&gt;@andrews&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 13:15:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-pyspark-task-exception-handling-on-quot-shared-compute/m-p/86368#M37315</guid>
      <dc:creator>geronimo_signol</dc:creator>
      <dc:date>2024-08-29T13:15:27Z</dc:date>
    </item>
  </channel>
</rss>

