title: How to overwrite a file with pyspark in Azure Spark Cluster
body: <p>I'm using the following script to output the results of a SPARQL query to a file in Azure Data Store. However, instead of creating a file called <code>myresults.json</code> and publishing the results to the <code>myresults.json</code> file, the script publishes the results to a random file name like <code>part-0000-tid</code> like in the image below:</p>
  
  <p><a href="https://i.stack.imgur.com/bg6mX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bg6mX.png" alt="pyspark"></a></p>
  
  <p>The code is as follows:</p>
  
  <pre><code>example1 = spark.sql("""SELECT
    CF.CountryName AS CountryCarsSold
   ,COUNT(CF.CountryName) AS NumberCountry
   ,MAX(CB.SalesDetailsID) AS TotalSold
  FROM Data_SalesDetails CB
  INNER JOIN Data_Sales CD
    ON CB.SalesID = CD.SalesID
  INNER JOIN Data_Customer CG
    ON CD.CustomerID = CG.CustomerID
  INNER JOIN Data_Country CF
    ON CG.Country = CF.CountryISO2
  GROUP BY CF.CountryName""")
  example1.coalesce(1).write.mode("append").json("adl://carlslake.azuredatalakestore.net/jfolder2/outputfiles/myoutput3/myresults.json")
  </code></pre>
  
  <p>Can someone let me know how to save as a single file and each file is overwritten each time it is saved.</p>
  
  <p>Thanks</p>