title: Save content of Spark DataFrame as a single CSV file
body: <p>Say I have a Spark DataFrame which I want to save as CSV file. After <strong>Spark 2.0.0</strong> , <strong>DataFrameWriter</strong> class directly supports saving it as a CSV file.</p>
  
  <p>The default behavior is to save the output in multiple <strong>part-*.csv</strong> files inside the path provided. </p>
  
  <p>How would I save a DF with :</p>
  
  <ol>
  <li>Path mapping to the exact file name instead of folder</li>
  <li>Header available in first line</li>
  <li>Save as a single file instead of multiple files.</li>
  </ol>
  
  <p>One way to deal with it, is to coalesce the DF and then save the file. </p>
  
  <pre><code>df.coalesce(1).write.option("header", "true").csv("sample_file.csv")
  </code></pre>
  
  <p>However this has disadvantage in collecting it on Master machine and needs to have a master with enough memory. </p>
  
  <p>Is it possible to write a single CSV file without using <strong>coalesce</strong> ? If not, is there a efficient way than the above code ?</p>