<?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 PicklingError: Could not serialize object: Exception: It appears that you are attempting to reference SparkContext from a broadcast variable, action, or transformation. SparkContext can only be used on the driver, not in code that it run on workers. in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/picklingerror-could-not-serialize-object-exception-it-appears/m-p/27101#M18997</link>
    <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I am trying to write a function in Azure databricks. I would like to spark.sql inside the function. But it looks like I cannot use it with worker nodes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;def SEL_ID(value, index):
    # some processing on value here
    ans = spark.sql("SELECT id FROM table WHERE bin = index")
    return ans
spark.udf.register("SEL_ID", SEL_ID)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am getting the following error:&lt;/P&gt;
&lt;P&gt;PicklingError: Could not serialize object: Exception: It appears that you are attempting to reference SparkContext from a broadcast variable, action, or transformation. SparkContext can only be used on the driver, not in code that it run on workers. For more information, see SPARK-5063.&lt;/P&gt;
&lt;P&gt;Is there any way I can overcome this? I am using the above function to select from another table.&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Aug 2020 06:54:17 GMT</pubDate>
    <dc:creator>dtr</dc:creator>
    <dc:date>2020-08-05T06:54:17Z</dc:date>
    <item>
      <title>PicklingError: Could not serialize object: Exception: It appears that you are attempting to reference SparkContext from a broadcast variable, action, or transformation. SparkContext can only be used on the driver, not in code that it run on workers.</title>
      <link>https://community.databricks.com/t5/data-engineering/picklingerror-could-not-serialize-object-exception-it-appears/m-p/27101#M18997</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I am trying to write a function in Azure databricks. I would like to spark.sql inside the function. But it looks like I cannot use it with worker nodes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;def SEL_ID(value, index):
    # some processing on value here
    ans = spark.sql("SELECT id FROM table WHERE bin = index")
    return ans
spark.udf.register("SEL_ID", SEL_ID)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am getting the following error:&lt;/P&gt;
&lt;P&gt;PicklingError: Could not serialize object: Exception: It appears that you are attempting to reference SparkContext from a broadcast variable, action, or transformation. SparkContext can only be used on the driver, not in code that it run on workers. For more information, see SPARK-5063.&lt;/P&gt;
&lt;P&gt;Is there any way I can overcome this? I am using the above function to select from another table.&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 06:54:17 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/picklingerror-could-not-serialize-object-exception-it-appears/m-p/27101#M18997</guid>
      <dc:creator>dtr</dc:creator>
      <dc:date>2020-08-05T06:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: PicklingError: Could not serialize object: Exception: It appears that you are attempting to reference SparkContext from a broadcast variable, action, or transformation. SparkContext can only be used on the driver, not in code that it run on workers.</title>
      <link>https://community.databricks.com/t5/data-engineering/picklingerror-could-not-serialize-object-exception-it-appears/m-p/27102#M18998</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Hi there. i guess im a bit late but do you remember how and if you fixed this issue? im getting the same exact problem. &lt;A href="https://users/45435/dtr.html" target="_blank"&gt;@dtr&lt;/A&gt;&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 18:56:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/picklingerror-could-not-serialize-object-exception-it-appears/m-p/27102#M18998</guid>
      <dc:creator>MartinhoAzevedo</dc:creator>
      <dc:date>2021-02-01T18:56:58Z</dc:date>
    </item>
  </channel>
</rss>

