<?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 I have to read zipped csv file using spark without unzipping it. can anyone please provide pyspark/spark sql code for that? in Data Governance</title>
    <link>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17156#M603</link>
    <description>&lt;P&gt;Zipped csv files are receiving to s3 raw layer.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Dec 2022 07:41:23 GMT</pubDate>
    <dc:creator>joggiri</dc:creator>
    <dc:date>2022-12-13T07:41:23Z</dc:date>
    <item>
      <title>I have to read zipped csv file using spark without unzipping it. can anyone please provide pyspark/spark sql code for that?</title>
      <link>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17156#M603</link>
      <description>&lt;P&gt;Zipped csv files are receiving to s3 raw layer.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2022 07:41:23 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17156#M603</guid>
      <dc:creator>joggiri</dc:creator>
      <dc:date>2022-12-13T07:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: I have to read zipped csv file using spark without unzipping it. can anyone please provide pyspark/spark sql code for that?</title>
      <link>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17157#M604</link>
      <description>&lt;P&gt;Why can't you unzip it?  You can not read zipped files with spark as zip isn't a file type.  &lt;A href="https://docs.databricks.com/files/unzip-files.html" target="test_blank"&gt;https://docs.databricks.com/files/unzip-files.html&lt;/A&gt; has some instructions on how to unzip them and read them.  &lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2022 11:55:09 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17157#M604</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-12-13T11:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: I have to read zipped csv file using spark without unzipping it. can anyone please provide pyspark/spark sql code for that?</title>
      <link>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17158#M605</link>
      <description>&lt;P&gt;Additionally, if you don't want or can't unzip whole archive, you can list the contents of the archive and unzip only selected file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Still, as @Joseph Kambourakis​&amp;nbsp;asked - why can't you just unzip it? What's blocking you?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2022 22:07:40 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17158#M605</guid>
      <dc:creator>Bartek</dc:creator>
      <dc:date>2022-12-13T22:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: I have to read zipped csv file using spark without unzipping it. can anyone please provide pyspark/spark sql code for that?</title>
      <link>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17159#M606</link>
      <description>&lt;P&gt;We encountered a similar issue, but for gzip files.  If you can convert your files to gzip instead of ZIP, it is as easy as the following (in PySpark)&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df = spark.read.option("header", "true").csv(PATH + "/*.csv.gz")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As best as I can tell, this is not possible with ZIP files, but if you have a place where you can write the output to, writing a Python or Scala script to unzip and then gzip the files should not be too hard [if keeping them compressed is required, else do what @Joseph Kambourakis​&amp;nbsp;said and just unzip them &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ]&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 15:57:19 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17159#M606</guid>
      <dc:creator>belbert</dc:creator>
      <dc:date>2022-12-14T15:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: I have to read zipped csv file using spark without unzipping it. can anyone please provide pyspark/spark sql code for that?</title>
      <link>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17160#M607</link>
      <description>&lt;P&gt;Great you pointed out @Ben Elbert​&amp;nbsp;that spark allows to read compressed files (`compression` property mentioned here: &lt;A href="https://spark.apache.org/docs/latest/sql-data-sources-csv.html)" target="test_blank"&gt;https://spark.apache.org/docs/latest/sql-data-sources-csv.html)&lt;/A&gt;. Still, it won't work with .zip archive.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 16:29:41 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17160#M607</guid>
      <dc:creator>Bartek</dc:creator>
      <dc:date>2022-12-14T16:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: I have to read zipped csv file using spark without unzipping it. can anyone please provide pyspark/spark sql code for that?</title>
      <link>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17161#M608</link>
      <description>&lt;P&gt;one more solution - you can read .zip using old good pandas `read_csv` method (https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html#pandas.read_csv)&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import pandas as pd
&amp;nbsp;
simple_csv_zipped = pd.read_csv("/dbfs/FileStore/simple_file.zip")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;still there is one disclaimer: "If using ‘zip’ or ‘tar’, the ZIP file must contain only one data file to be read in."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and there is also obvious trade-off: using pandas means no distribution, no scalability and exposure to OOM errors - but maybe in your specific case it is acceptable&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 21:53:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17161#M608</guid>
      <dc:creator>Bartek</dc:creator>
      <dc:date>2022-12-14T21:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: I have to read zipped csv file using spark without unzipping it. can anyone please provide pyspark/spark sql code for that?</title>
      <link>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17162#M609</link>
      <description>&lt;P&gt;@Jog Giri​&amp;nbsp; I also recently encountered a similar scenario, the below code solved my purpose without any issues.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import zipfile
for i in dbutils.fs.ls('/mnt/zipfilespath/'):
  with zipfile.ZipFile(i.path.replace('dbfs:','/dbfs'), mode="r") as zip_ref:
    zip_ref.extractall(destination_path)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;where I mounted an ADLS Gen 2 container which consists of several .csv zip files, please let me know if you face any further issues, happy to help!!&lt;/P&gt;</description>
      <pubDate>Sat, 17 Dec 2022 02:42:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-governance/i-have-to-read-zipped-csv-file-using-spark-without-unzipping-it/m-p/17162#M609</guid>
      <dc:creator>Chaitanya_Raju</dc:creator>
      <dc:date>2022-12-17T02:42:57Z</dc:date>
    </item>
  </channel>
</rss>

