<?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 How to create a csv using a Scala notebook that as &amp;quot; in some columns? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-create-a-csv-using-a-scala-notebook-that-as-quot-in-some/m-p/15177#M9534</link>
    <description>&lt;P&gt;In a project we use Azure Databricks to create csv files to be loaded in ThoughtSpot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is a sample to the code I use to write the file:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;val fileRepartition = 1
val fileFormat = "csv"
val fileSaveMode = "overwrite"
var fileOptions = Map (
                        "header" -&amp;gt; "true",
                        "overwriteSchema" -&amp;gt; "true",
                        "delimiter" -&amp;gt; "\t"
                      )
&amp;nbsp;
dfFinal
  .repartition (fileRepartition.toInt)
  .write
  .format  (fileFormat)
  .mode    (fileSaveMode)
  .options (fileOptions)
  .save    (filePath)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The csv created uses a tab as the column separator and some of the columns may have " in their values. When that happens in the csv file the value of that column is enclosed by ". E.g.:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ProductId	ProductCode	ProductDesc
1234	BD Plastipak	"BD Plastipak 1/4\" Syringes"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is it possible to change the parameters to write the file as described below?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ProductId	ProductCode	ProductDesc
1234	BD Plastipak	BD Plastipak 1/4" Syringes&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have a workaround to do it in a sub-sequent step to use &lt;B&gt;sed&lt;/B&gt; to update the csv, but it would be much easier if I were able to get the file in the correct format when saving it from the notebook.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Tiago R.&lt;/P&gt;</description>
    <pubDate>Sat, 18 Sep 2021 18:09:15 GMT</pubDate>
    <dc:creator>tarente</dc:creator>
    <dc:date>2021-09-18T18:09:15Z</dc:date>
    <item>
      <title>How to create a csv using a Scala notebook that as " in some columns?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-create-a-csv-using-a-scala-notebook-that-as-quot-in-some/m-p/15177#M9534</link>
      <description>&lt;P&gt;In a project we use Azure Databricks to create csv files to be loaded in ThoughtSpot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is a sample to the code I use to write the file:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;val fileRepartition = 1
val fileFormat = "csv"
val fileSaveMode = "overwrite"
var fileOptions = Map (
                        "header" -&amp;gt; "true",
                        "overwriteSchema" -&amp;gt; "true",
                        "delimiter" -&amp;gt; "\t"
                      )
&amp;nbsp;
dfFinal
  .repartition (fileRepartition.toInt)
  .write
  .format  (fileFormat)
  .mode    (fileSaveMode)
  .options (fileOptions)
  .save    (filePath)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The csv created uses a tab as the column separator and some of the columns may have " in their values. When that happens in the csv file the value of that column is enclosed by ". E.g.:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ProductId	ProductCode	ProductDesc
1234	BD Plastipak	"BD Plastipak 1/4\" Syringes"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is it possible to change the parameters to write the file as described below?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ProductId	ProductCode	ProductDesc
1234	BD Plastipak	BD Plastipak 1/4" Syringes&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have a workaround to do it in a sub-sequent step to use &lt;B&gt;sed&lt;/B&gt; to update the csv, but it would be much easier if I were able to get the file in the correct format when saving it from the notebook.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Tiago R.&lt;/P&gt;</description>
      <pubDate>Sat, 18 Sep 2021 18:09:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-create-a-csv-using-a-scala-notebook-that-as-quot-in-some/m-p/15177#M9534</guid>
      <dc:creator>tarente</dc:creator>
      <dc:date>2021-09-18T18:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a csv using a Scala notebook that as " in some columns?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-create-a-csv-using-a-scala-notebook-that-as-quot-in-some/m-p/15178#M9535</link>
      <description>&lt;P&gt;could you please try adding - &lt;B&gt;&lt;I&gt;&lt;U&gt;escape &lt;/U&gt;&lt;/I&gt;&lt;/B&gt;&lt;I&gt;as an &lt;/I&gt;option while writing to a csv?  &lt;/P&gt;&lt;P&gt;Please refer to the below additional options available during writing to a CSV -  &lt;A href="https://spark.apache.org/docs/latest/api/scala/org/apache/spark/sql/DataFrameWriter.html" alt="https://spark.apache.org/docs/latest/api/scala/org/apache/spark/sql/DataFrameWriter.html" target="_blank"&gt;&lt;I&gt;under CSV-specific option(s) for writing CSV  files.&lt;/I&gt;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Sep 2021 20:22:19 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-create-a-csv-using-a-scala-notebook-that-as-quot-in-some/m-p/15178#M9535</guid>
      <dc:creator>shan_chandra</dc:creator>
      <dc:date>2021-09-18T20:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a csv using a Scala notebook that as " in some columns?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-create-a-csv-using-a-scala-notebook-that-as-quot-in-some/m-p/15179#M9536</link>
      <description>&lt;P&gt;Hi Shan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the link.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I now know more options for creating different &lt;I&gt;csv&lt;/I&gt; files.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have not yet completed the problem, but that is related with a destination application (ThoughtSpot) not being able to load the data in the &lt;I&gt;csv&lt;/I&gt; file correctly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Tiago R.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 08:03:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-create-a-csv-using-a-scala-notebook-that-as-quot-in-some/m-p/15179#M9536</guid>
      <dc:creator>tarente</dc:creator>
      <dc:date>2021-09-21T08:03:14Z</dc:date>
    </item>
  </channel>
</rss>

