<?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: data.write.format('com.databricks.spark.csv') added additional quotation marks in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/data-write-format-com-databricks-spark-csv-added-additional/m-p/29682#M21393</link>
    <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Could you possible supply some Python code that creates a small DataFrame that demonstrates this behavior?&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jun 2016 04:40:29 GMT</pubDate>
    <dc:creator>SiddSingal</dc:creator>
    <dc:date>2016-06-09T04:40:29Z</dc:date>
    <item>
      <title>data.write.format('com.databricks.spark.csv') added additional quotation marks</title>
      <link>https://community.databricks.com/t5/data-engineering/data-write-format-com-databricks-spark-csv-added-additional/m-p/29680#M21391</link>
      <description>&lt;P&gt;0favorite&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I am using the following code (pyspark) to export my data frame to csv:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;data.write.format('com.databricks.spark.csv').options(delimiter="\t", codec="org.apache.hadoop.io.compress.GzipCodec").save('s3a://myBucket/myPath')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I use &lt;PRE&gt;&lt;CODE&gt;delimiter="\t"&lt;/CODE&gt;&lt;/PRE&gt;, as I don't want to add additional quotation marks around each field. However, when I checked the output csv file, there are still some fields which are enclosed by quotation marks. e.g.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;abcdABCDAAbbcd ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE&gt;1234_3456ABCD  ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE&gt;"-12345678AbCd"...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It seems that the quotation mark appears when the leading character of a field is "-". Why is this happening and is there a way to avoid this? Thanks!&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 18:40:17 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/data-write-format-com-databricks-spark-csv-added-additional/m-p/29680#M21391</guid>
      <dc:creator>WenLin</dc:creator>
      <dc:date>2016-06-06T18:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: data.write.format('com.databricks.spark.csv') added additional quotation marks</title>
      <link>https://community.databricks.com/t5/data-engineering/data-write-format-com-databricks-spark-csv-added-additional/m-p/29681#M21392</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I also tried to use quoteMode = "NONE" , but doesn't work either&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 22:45:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/data-write-format-com-databricks-spark-csv-added-additional/m-p/29681#M21392</guid>
      <dc:creator>WenLin</dc:creator>
      <dc:date>2016-06-06T22:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: data.write.format('com.databricks.spark.csv') added additional quotation marks</title>
      <link>https://community.databricks.com/t5/data-engineering/data-write-format-com-databricks-spark-csv-added-additional/m-p/29682#M21393</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Could you possible supply some Python code that creates a small DataFrame that demonstrates this behavior?&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 04:40:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/data-write-format-com-databricks-spark-csv-added-additional/m-p/29682#M21393</guid>
      <dc:creator>SiddSingal</dc:creator>
      <dc:date>2016-06-09T04:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: data.write.format('com.databricks.spark.csv') added additional quotation marks</title>
      <link>https://community.databricks.com/t5/data-engineering/data-write-format-com-databricks-spark-csv-added-additional/m-p/29683#M21394</link>
      <description>&lt;P&gt;The way to turn off the default escaping of the double quote character (") with the backslash character (\) - i.e. to avoid escaping for all characters entirely, you must add an .option() method call with just the right parameters after the .write() method call. The goal of the option() method call is to change how the csv() method "finds" instances of the "quote" character as it is emitting the content. To do this, you must change the default of what a "quote" actually means; i.e. change the character sought from being a double quote character (") to a Unicode "\u0000" character (essentially providing the Unicode NUL character assuming it won't ever occur within the document).&lt;/P&gt;&lt;P&gt;Here's Scala code achieving the effect. The second to last line (ending with magic is happening here) is the critical line and looks exactly the same in Python (as it does here in Scala).&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;val dataFrame =
  spark.sql("SELECT * FROM some_table_with_odd_characters_column")
val unitEmitCsv =
  dataframe
    .write
    .option("header", true)
    .option("quote", "\u0000") //magic is happening here
    .csv("/FileStore/temp.csv")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This was only one of several lessons I learned attempting to work with Apache Spark and emitting .csv files. For more information and context on this, please see the blog post I wrote titled "Example Apache Spark ETL Pipeline Integrating a SaaS".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 00:37:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/data-write-format-com-databricks-spark-csv-added-additional/m-p/29683#M21394</guid>
      <dc:creator>chaotic3quilibr</dc:creator>
      <dc:date>2017-03-31T00:37:47Z</dc:date>
    </item>
  </channel>
</rss>

