<?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 Accelerating row-wise Python UDF functions without using Pandas UDF ProblemSpark will not automatically parallelize UDF operations on smaller/medium d... in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/accelerating-row-wise-python-udf-functions-without-using-pandas/m-p/15328#M9663</link>
    <description>&lt;P&gt;Accelerating row-wise Python UDF functions without using Pandas UDF&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;Problem&lt;/B&gt;&lt;/P&gt;&lt;P&gt;Spark will not automatically parallelize UDF operations on smaller/medium dataframes. As a result, spark will process the UDF as a single non parallelized task. For row-wise operations, this can be a time-intensive task.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;Solution&lt;/B&gt;&lt;/P&gt;&lt;P&gt;Force Spark to parallelize the tasks across available workers using the &lt;B&gt;&lt;U&gt;repartition&lt;/U&gt;&lt;/B&gt; dataframe function.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df = sql('select * from table').repartition(&amp;lt;number of tasks&amp;gt;)
df = df.withColumn('column_name', python_udf(col('a_column')))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For best performance make the number of tasks equal to the cores available for maximum parallelization.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Sep 2021 20:23:22 GMT</pubDate>
    <dc:creator>Artem_Y</dc:creator>
    <dc:date>2021-09-14T20:23:22Z</dc:date>
    <item>
      <title>Accelerating row-wise Python UDF functions without using Pandas UDF ProblemSpark will not automatically parallelize UDF operations on smaller/medium d...</title>
      <link>https://community.databricks.com/t5/data-engineering/accelerating-row-wise-python-udf-functions-without-using-pandas/m-p/15328#M9663</link>
      <description>&lt;P&gt;Accelerating row-wise Python UDF functions without using Pandas UDF&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;Problem&lt;/B&gt;&lt;/P&gt;&lt;P&gt;Spark will not automatically parallelize UDF operations on smaller/medium dataframes. As a result, spark will process the UDF as a single non parallelized task. For row-wise operations, this can be a time-intensive task.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;Solution&lt;/B&gt;&lt;/P&gt;&lt;P&gt;Force Spark to parallelize the tasks across available workers using the &lt;B&gt;&lt;U&gt;repartition&lt;/U&gt;&lt;/B&gt; dataframe function.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df = sql('select * from table').repartition(&amp;lt;number of tasks&amp;gt;)
df = df.withColumn('column_name', python_udf(col('a_column')))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For best performance make the number of tasks equal to the cores available for maximum parallelization.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 20:23:22 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/accelerating-row-wise-python-udf-functions-without-using-pandas/m-p/15328#M9663</guid>
      <dc:creator>Artem_Y</dc:creator>
      <dc:date>2021-09-14T20:23:22Z</dc:date>
    </item>
  </channel>
</rss>

