<?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>question Re: How to run spark df.write inside UDF called in rdd.foreach or  rdd.foreachpartition in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/How-to-run-spark-df-write-inside-UDF-called-in-rdd-foreach/m-p/412307#M253364</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/131645"&gt;@Jack_sparrow&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Glad to see you on the Community.&amp;nbsp;&lt;/P&gt;&lt;P&gt;As far as I know,&amp;nbsp;&lt;FONT face="terminal,monaco"&gt;df.write&lt;/FONT&gt; is not possible to be used on an rdd.foreach or rdd.foreachpartition.&amp;nbsp;&lt;BR /&gt;The reason is because&amp;nbsp;df.write is a driver-side action, it triggers a Spark job.&lt;BR /&gt;rdd.foreach or rdd.foreachpartition are executors, and executors cannot trigger jobs.&lt;/P&gt;&lt;P&gt;Check these references:&amp;nbsp;&lt;BR /&gt;&lt;A href="https://stackoverflow.com/questions/46964250/nullpointerexception-creating-dataset-dataframe-inside-foreachpartition-foreach?utm_source=chatgpt.com" target="_blank"&gt;https://stackoverflow.com/questions/46964250/nullpointerexception-creating-dataset-dataframe-inside-foreachpartition-foreach&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://stackoverflow.com/questions/46964250/nullpointerexception-creating-dataset-dataframe-inside-foreachpartition-foreach" target="_blank"&gt;https://stackoverflow.com/questions/46964250/nullpointerexception-creating-dataset-dataframe-inside-foreachpartition-foreach&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://sparkbyexamples.com/spark/spark-foreachpartition-vs-foreach-explained" target="_blank"&gt;https://sparkbyexamples.com/spark/spark-foreachpartition-vs-foreach-explained&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The option that looks like it works for you is this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;df.write.partitionBy&lt;/PRE&gt;&lt;P&gt;Something like this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;df.write.partitionBy("someColumn").parquet("/path/out")&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Sep 2025 20:12:38 GMT</pubDate>
    <dc:creator>vafs</dc:creator>
    <dc:date>2025-09-08T20:12:38Z</dc:date>
    <item>
      <title>How to run spark df.write inside UDF called in rdd.foreach or  rdd.foreachpartition</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-run-spark-df-write-inside-UDF-called-in-rdd-foreach/m-p/412304#M253361</link>
      <description>&lt;P&gt;How to run spark df.write inside UDF called in rdd.foreach or rdd.foreachpartition&lt;/P&gt;&lt;P&gt;I.e. spark session object inside executor.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 12:04:24 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-run-spark-df-write-inside-UDF-called-in-rdd-foreach/m-p/412304#M253361</guid>
      <dc:creator>Jack_sparrow</dc:creator>
      <dc:date>2025-09-08T12:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to run spark df.write inside UDF called in rdd.foreach or  rdd.foreachpartition</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-run-spark-df-write-inside-UDF-called-in-rdd-foreach/m-p/412306#M253363</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/131645"&gt;@Jack_sparrow&lt;/a&gt;,&amp;nbsp;Welcome to our community! To help you get the best possible answer, I have tagged in our Spark experts&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/86141"&gt;@haridjh&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/114383"&gt;@vafs&lt;/a&gt;, who may be able to assist you further.&lt;BR /&gt;&lt;BR /&gt;Please feel free to provide any additional information or details about your query. We hope that you will find a satisfactory solution to your question.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 15:32:10 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-run-spark-df-write-inside-UDF-called-in-rdd-foreach/m-p/412306#M253363</guid>
      <dc:creator>VidyaSargur</dc:creator>
      <dc:date>2025-09-08T15:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to run spark df.write inside UDF called in rdd.foreach or  rdd.foreachpartition</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-run-spark-df-write-inside-UDF-called-in-rdd-foreach/m-p/412307#M253364</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/131645"&gt;@Jack_sparrow&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Glad to see you on the Community.&amp;nbsp;&lt;/P&gt;&lt;P&gt;As far as I know,&amp;nbsp;&lt;FONT face="terminal,monaco"&gt;df.write&lt;/FONT&gt; is not possible to be used on an rdd.foreach or rdd.foreachpartition.&amp;nbsp;&lt;BR /&gt;The reason is because&amp;nbsp;df.write is a driver-side action, it triggers a Spark job.&lt;BR /&gt;rdd.foreach or rdd.foreachpartition are executors, and executors cannot trigger jobs.&lt;/P&gt;&lt;P&gt;Check these references:&amp;nbsp;&lt;BR /&gt;&lt;A href="https://stackoverflow.com/questions/46964250/nullpointerexception-creating-dataset-dataframe-inside-foreachpartition-foreach?utm_source=chatgpt.com" target="_blank"&gt;https://stackoverflow.com/questions/46964250/nullpointerexception-creating-dataset-dataframe-inside-foreachpartition-foreach&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://stackoverflow.com/questions/46964250/nullpointerexception-creating-dataset-dataframe-inside-foreachpartition-foreach" target="_blank"&gt;https://stackoverflow.com/questions/46964250/nullpointerexception-creating-dataset-dataframe-inside-foreachpartition-foreach&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://sparkbyexamples.com/spark/spark-foreachpartition-vs-foreach-explained" target="_blank"&gt;https://sparkbyexamples.com/spark/spark-foreachpartition-vs-foreach-explained&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The option that looks like it works for you is this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;df.write.partitionBy&lt;/PRE&gt;&lt;P&gt;Something like this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;df.write.partitionBy("someColumn").parquet("/path/out")&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 20:12:38 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-run-spark-df-write-inside-UDF-called-in-rdd-foreach/m-p/412307#M253364</guid>
      <dc:creator>vafs</dc:creator>
      <dc:date>2025-09-08T20:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to run spark df.write inside UDF called in rdd.foreach or  rdd.foreachpartition</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-run-spark-df-write-inside-UDF-called-in-rdd-foreach/m-p/412309#M253366</link>
      <description>&lt;P&gt;Thank you for the response.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Sep 2025 04:01:05 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-run-spark-df-write-inside-UDF-called-in-rdd-foreach/m-p/412309#M253366</guid>
      <dc:creator>Jack_sparrow</dc:creator>
      <dc:date>2025-09-09T04:01:05Z</dc:date>
    </item>
  </channel>
</rss>

