<?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 Setting Compression in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Setting-Compression/m-p/269714#M207038</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm just starting off and was wondering if there's any concrete way of setting the compression when writing to a file in Spark?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used to use option when writing files:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;exampleDF.write.option("compression", "snappy").avro("output path")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but when I go to check where the Avro files are saved I can't tell from the name of the files whether they've been compressed or not. Also just to say this is after I've imported "com.databricks.spark.avro._" so I'm not having any trouble using Avro files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way I've seen is to use "sqlContext.setConf" and these would be the commands I'd use in this instance:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;import org.apache.spark.sql.hive.HiveContext&lt;/P&gt;
&lt;P&gt;val sqlContext = new HiveContext(sc)&lt;/P&gt;
&lt;P&gt;sqlContext.setConf("spark.sql.avro.compression.codec", "snappy")&lt;/P&gt;
&lt;P&gt;exampleDF.write.avro("output path")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Neither way causes any errors so I was wondering which would be the better way and if there are any other more reliable ways of setting the compression when writing files?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The version of Spark I'm using is Spark version 2.2.0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
    <pubDate>Wed, 04 Sep 2019 15:44:15 GMT</pubDate>
    <dc:creator>RandomT</dc:creator>
    <dc:date>2019-09-04T15:44:15Z</dc:date>
    <item>
      <title>Setting Compression</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Setting-Compression/m-p/269714#M207038</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm just starting off and was wondering if there's any concrete way of setting the compression when writing to a file in Spark?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used to use option when writing files:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;exampleDF.write.option("compression", "snappy").avro("output path")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but when I go to check where the Avro files are saved I can't tell from the name of the files whether they've been compressed or not. Also just to say this is after I've imported "com.databricks.spark.avro._" so I'm not having any trouble using Avro files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way I've seen is to use "sqlContext.setConf" and these would be the commands I'd use in this instance:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;import org.apache.spark.sql.hive.HiveContext&lt;/P&gt;
&lt;P&gt;val sqlContext = new HiveContext(sc)&lt;/P&gt;
&lt;P&gt;sqlContext.setConf("spark.sql.avro.compression.codec", "snappy")&lt;/P&gt;
&lt;P&gt;exampleDF.write.avro("output path")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Neither way causes any errors so I was wondering which would be the better way and if there are any other more reliable ways of setting the compression when writing files?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The version of Spark I'm using is Spark version 2.2.0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 15:44:15 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Setting-Compression/m-p/269714#M207038</guid>
      <dc:creator>RandomT</dc:creator>
      <dc:date>2019-09-04T15:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Compression</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Setting-Compression/m-p/269945#M207179</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/69167"&gt;@RandomT&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can check compression on &lt;STRONG&gt;.avro&lt;/STRONG&gt; files using &lt;STRONG&gt;avro-tools&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;bash$ avro-tools getmeta &amp;lt;file_path&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;For more details refer to&amp;nbsp;&lt;A title="this" href="https://community.cloudera.com/t5/Support-Questions/Verify-the-file-s-compression-properties/m-p/78888" target="_blank" rel="noopener"&gt;this link&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;sqlContext.setConf //sets global config and every write will be snappy compressed if you are writing all your data as snappy compressed then you should use this method.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In case if you are compressing &lt;U&gt;&lt;STRONG&gt;only the selected data&lt;/STRONG&gt;&lt;/U&gt; then use&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;exampleDF.write.option("compression", "snappy").avro("output path") &lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;for better control over on compression.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Sep 2019 06:16:06 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Setting-Compression/m-p/269945#M207179</guid>
      <dc:creator>Shu_ashu</dc:creator>
      <dc:date>2019-09-07T06:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Compression</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Setting-Compression/m-p/270006#M207221</link>
      <description>&lt;P&gt;Thanks for the info, was very helpful!&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 08:11:04 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Setting-Compression/m-p/270006#M207221</guid>
      <dc:creator>RandomT</dc:creator>
      <dc:date>2019-09-09T08:11:04Z</dc:date>
    </item>
  </channel>
</rss>

