<?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 Optimise Large number of CSV files to be read from Lakehouse as using spark.read in Data Science</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Science/Optimise-Large-number-of-CSV-files-to-be-read-from-Lakehouse-as/m-p/4036842#M241</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I've uploaded&amp;nbsp; ~40k csv files in Azure Lakehouse and I need to read it into a dataframe in a python notebook in fabric for further processing. I'm using spark.read for this, please suggest some methods to optimise this query and reduce the time complexity.&lt;BR /&gt;Some Constraints:&lt;BR /&gt;- There is an ID column in each row,&lt;BR /&gt;- All the csv files have the same schema&lt;/P&gt;&lt;P&gt;- There are around 10 rows in each csv&lt;/P&gt;&lt;P&gt;- The aim is to optimise code for 10 million records&lt;BR /&gt;&lt;BR /&gt;Right now, i'm using:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df = spark.read.option(&lt;/SPAN&gt;&lt;SPAN&gt;"header"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"true"&lt;/SPAN&gt;&lt;SPAN&gt;).csv(path_to_csv_files + &lt;/SPAN&gt;&lt;SPAN&gt;"/*/*.csv"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;Also, these csv files were created by delta table, i used zorder to optimise that query&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 11 Jul 2024 10:13:40 GMT</pubDate>
    <dc:creator>ritikesh</dc:creator>
    <dc:date>2024-07-11T10:13:40Z</dc:date>
    <item>
      <title>Optimise Large number of CSV files to be read from Lakehouse as using spark.read</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Science/Optimise-Large-number-of-CSV-files-to-be-read-from-Lakehouse-as/m-p/4036842#M241</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I've uploaded&amp;nbsp; ~40k csv files in Azure Lakehouse and I need to read it into a dataframe in a python notebook in fabric for further processing. I'm using spark.read for this, please suggest some methods to optimise this query and reduce the time complexity.&lt;BR /&gt;Some Constraints:&lt;BR /&gt;- There is an ID column in each row,&lt;BR /&gt;- All the csv files have the same schema&lt;/P&gt;&lt;P&gt;- There are around 10 rows in each csv&lt;/P&gt;&lt;P&gt;- The aim is to optimise code for 10 million records&lt;BR /&gt;&lt;BR /&gt;Right now, i'm using:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df = spark.read.option(&lt;/SPAN&gt;&lt;SPAN&gt;"header"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"true"&lt;/SPAN&gt;&lt;SPAN&gt;).csv(path_to_csv_files + &lt;/SPAN&gt;&lt;SPAN&gt;"/*/*.csv"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;Also, these csv files were created by delta table, i used zorder to optimise that query&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 11 Jul 2024 10:13:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Science/Optimise-Large-number-of-CSV-files-to-be-read-from-Lakehouse-as/m-p/4036842#M241</guid>
      <dc:creator>ritikesh</dc:creator>
      <dc:date>2024-07-11T10:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Optimise Large number of CSV files to be read from Lakehouse as using spark.read</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Science/Optimise-Large-number-of-CSV-files-to-be-read-from-Lakehouse-as/m-p/4038498#M242</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="773793" data-lia-user-login="ritikesh" class="lia-mention lia-mention-user"&gt;ritikesh&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;You can right click on one of the csv file that stored in your folder of thousands of files, then choose 'load data' -&amp;gt; 'spark' to generate spark code of the load file from specific file path.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;df = spark.read.format("csv").option("header","true").load("Files/churn/raw/churn.csv")
display(df)&lt;/LI-CODE&gt;
&lt;P&gt;After above steps, you can modify the generated code to remove the detail file path to load data from all the files of folder instead of specific file.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;df = spark.read.format("csv").option("header","true").load("Files/churn/raw/")
display(df)&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Notice: the sample has two files with 1k rows.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/databricks/spark-csv#features" target="_blank"&gt;GitHub - databricks/spark-csv: CSV Data Source for Apache Spark 1.x&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Xiaoxin Sheng&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2024 04:13:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Science/Optimise-Large-number-of-CSV-files-to-be-read-from-Lakehouse-as/m-p/4038498#M242</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-12T04:13:17Z</dc:date>
    </item>
  </channel>
</rss>

