<?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: org.apache.spark.SparkRuntimeException: [UDF_USER_CODE_ERROR.GENERIC] in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/org-apache-spark-sparkruntimeexception-udf-user-code-error/m-p/136779#M50647</link>
    <description>&lt;P&gt;thank you&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/74780"&gt;@KaushalVachhani&lt;/a&gt;, I want this as an AI Tool. I actually created this logic as a databricks job and used it as a tool in an agent. But it did not work as expected. Let me explore this further.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Oct 2025 16:18:15 GMT</pubDate>
    <dc:creator>GiriSreerangam</dc:creator>
    <dc:date>2025-10-30T16:18:15Z</dc:date>
    <item>
      <title>org.apache.spark.SparkRuntimeException: [UDF_USER_CODE_ERROR.GENERIC]</title>
      <link>https://community.databricks.com/t5/data-engineering/org-apache-spark-sparkruntimeexception-udf-user-code-error/m-p/136597#M50597</link>
      <description>&lt;P&gt;Hi Everyone&lt;/P&gt;&lt;P&gt;I am writing a small function, with spark read from a csv and spark write into a table. I could execute this function within the notebook. But, when I register the same function as a unity catalog function and calling it from Playground, it is throwing Spark Exception. can someone tell what am I missing?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code for reference:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GiriSreerangam_0-1761761391719.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/21161i3CF3AEDF42D2D460/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GiriSreerangam_0-1761761391719.png" alt="GiriSreerangam_0-1761761391719.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;error:&amp;nbsp;== Error ==&lt;BR /&gt;SystemExit: -1&lt;BR /&gt;== Stacktrace ==&lt;BR /&gt;File "&amp;lt;udfbody&amp;gt;", line 28, in main&lt;BR /&gt;return ingest_csv(csv_path, table_name)&lt;BR /&gt;File "&amp;lt;udfbody&amp;gt;", line 14, in ingest_csv&lt;BR /&gt;spark = SparkSession.builder.getOrCreate()&lt;BR /&gt;File "/databricks/spark/python/pyspark/sql/session.py", line 574, in getOrCreate&lt;BR /&gt;else SparkContext.getOrCreate(sparkConf)&lt;BR /&gt;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&lt;BR /&gt;File "/databricks/spark/python/pyspark/core/context.py", line 579, in getOrCreate&lt;BR /&gt;SparkContext(conf=conf or SparkConf())&lt;BR /&gt;File "/databricks/spark/python/pyspark/core/context.py", line 207, in __init__&lt;BR /&gt;SparkContext._ensure_initialized(self, gateway=gateway, conf=conf)&lt;BR /&gt;File "/databricks/spark/python/pyspark/core/context.py", line 500, in _ensure_initialized&lt;BR /&gt;SparkContext._gateway = gateway or launch_gateway(conf)&lt;BR /&gt;^^^^^^^^^^^^^^^^^^^^&lt;BR /&gt;File "/databricks/spark/python/pyspark/java_gateway.py", line 63, in launch_gateway&lt;BR /&gt;SPARK_HOME = _find_spark_home()&lt;BR /&gt;^^^^^^^^^^^^^^^^^^&lt;BR /&gt;File "/databricks/spark/python/pyspark/find_spark_home.py", line 91, in _find_spark_home&lt;BR /&gt;sys.exit(-1) SQLSTATE: 39000&lt;/P&gt;&lt;P&gt;Any help here would be of great help.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Regards\Giri&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2025 18:17:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/org-apache-spark-sparkruntimeexception-udf-user-code-error/m-p/136597#M50597</guid>
      <dc:creator>GiriSreerangam</dc:creator>
      <dc:date>2025-10-29T18:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: org.apache.spark.SparkRuntimeException: [UDF_USER_CODE_ERROR.GENERIC]</title>
      <link>https://community.databricks.com/t5/data-engineering/org-apache-spark-sparkruntimeexception-udf-user-code-error/m-p/136745#M50638</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/169270"&gt;@GiriSreerangam&lt;/a&gt;, You cannot use a Unity Catalog user-defined function (UDF) in Databricks to perform Spark read from a CSV and write to a table. Unity Catalog Python UDFs execute in a secure, isolated environment without access to the file system or the Spark context, and hence results in errors because spark home is not found.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;They are intended for value transformations and can only return a single value (scalar), not perform data read/write operations or return DataFrames.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A recommended approach is to register your Spark read/write logic notebook as a Databricks Job, which can then be triggered either from the Databricks UI or programmatically via the Jobs API. If you wish to integrate this with an AI tool, you can encapsulate the Jobs API as a “function tool” to automate these workflows when needed.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2025 13:08:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/org-apache-spark-sparkruntimeexception-udf-user-code-error/m-p/136745#M50638</guid>
      <dc:creator>KaushalVachhani</dc:creator>
      <dc:date>2025-10-30T13:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: org.apache.spark.SparkRuntimeException: [UDF_USER_CODE_ERROR.GENERIC]</title>
      <link>https://community.databricks.com/t5/data-engineering/org-apache-spark-sparkruntimeexception-udf-user-code-error/m-p/136779#M50647</link>
      <description>&lt;P&gt;thank you&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/74780"&gt;@KaushalVachhani&lt;/a&gt;, I want this as an AI Tool. I actually created this logic as a databricks job and used it as a tool in an agent. But it did not work as expected. Let me explore this further.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2025 16:18:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/org-apache-spark-sparkruntimeexception-udf-user-code-error/m-p/136779#M50647</guid>
      <dc:creator>GiriSreerangam</dc:creator>
      <dc:date>2025-10-30T16:18:15Z</dc:date>
    </item>
  </channel>
</rss>

