<?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: Ways to write fast millions of rows inside a new delta table in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/ways-to-write-fast-millions-of-rows-inside-a-new-delta-table/m-p/99524#M40010</link>
    <description>&lt;P&gt;Someone can help me?&lt;/P&gt;</description>
    <pubDate>Wed, 20 Nov 2024 14:44:15 GMT</pubDate>
    <dc:creator>jeremy98</dc:creator>
    <dc:date>2024-11-20T14:44:15Z</dc:date>
    <item>
      <title>Ways to write fast millions of rows inside a new delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/ways-to-write-fast-millions-of-rows-inside-a-new-delta-table/m-p/99477#M39998</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hello everyone,&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I am facing an issue with writing 100–500 million rows (partitioned by a column) into a newly created Delta table. I have set up a cluster with 256 GB of memory and 64 cores. However, the following code takes a considerable amount of time even when writing around 70 million rows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;            df.repartition(num_partitions*4, partition_col).write \
                .format("delta") \
                .mode("overwrite") \
                .partitionBy(partition_col) \
                .option("mergeSchema", "true") \
                .option("optimizeBucket", "true") \
                .option("maxRecordsPerFile", "1000000") \
                .option("autoOptimize.optimizeWrite", "true") \
                .option("autoOptimize.autoCompact", "true") \
                .option("autoOptimize.autoRepartition", "true") \
                .saveAsTable(f"{bronze_layer}.{table_name}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;What Do i need to adjust to speed up this written step?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 09:23:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/ways-to-write-fast-millions-of-rows-inside-a-new-delta-table/m-p/99477#M39998</guid>
      <dc:creator>jeremy98</dc:creator>
      <dc:date>2024-11-20T09:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Ways to write fast millions of rows inside a new delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/ways-to-write-fast-millions-of-rows-inside-a-new-delta-table/m-p/99524#M40010</link>
      <description>&lt;P&gt;Someone can help me?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 14:44:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/ways-to-write-fast-millions-of-rows-inside-a-new-delta-table/m-p/99524#M40010</guid>
      <dc:creator>jeremy98</dc:creator>
      <dc:date>2024-11-20T14:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: Ways to write fast millions of rows inside a new delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/ways-to-write-fast-millions-of-rows-inside-a-new-delta-table/m-p/99555#M40024</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/133094"&gt;@jeremy98&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I would suggest to test:&lt;/P&gt;&lt;P&gt;1) remove repartition step or reduce number or partitions (start with number of cores and then try to increase it x2, x3)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;repartition(num_partitions*4, partition_col)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know repartitioning helps to divide data into equally smaller chunks and distribute tasks across the cores, however, on the other side, it triggers shuffle, which might be expensive.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) whats the cardinality of column You are partitioning the data in this step?&lt;/P&gt;&lt;P&gt;It triggers another shuffle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;.partitionBy(partition_col)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how many partitions does this one creates?&lt;/P&gt;&lt;P&gt;3) do You really need this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;.option("optimizeBucket", "true") \
.option("autoOptimize.optimizeWrite", "true") \
.option("autoOptimize.autoCompact", "true") \
.option("autoOptimize.autoRepartition", "true") \&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It requires shuffle.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe You could schedule a job that optimize the table (once per day or whatever frequency you need it to run) and tune the files size, here is an example of 128 mbs:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SET spark.databricks.delta.optimize.maxFileSize = 134217728;
OPTIMIZE my_delta_table;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4) whats the data structure under the table? partitioned? bucketed?&amp;nbsp;&lt;/P&gt;&lt;P&gt;5) while writing Your table You can investigate cluster metrics and check if all the cores are evenly loaded and the number of spark tasks being executed at the same time is what You would expect&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 21:24:41 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/ways-to-write-fast-millions-of-rows-inside-a-new-delta-table/m-p/99555#M40024</guid>
      <dc:creator>radothede</dc:creator>
      <dc:date>2024-11-20T21:24:41Z</dc:date>
    </item>
  </channel>
</rss>

