overwrite hive partitions using spark : <p>I am working with AWS and I have workflows that use Spark and Hive. My data is partitioned by the date, so everyday I have a new partition in my S3 storage. 
My problem is when one day the load data fails and I have to re-execute that partition. The code that writes is next:</p>

<pre><code>df                            // My data in a Dataframe
  .write
  .format(getFormat(target))  // csv by default, but could be parquet, ORC...
  .mode(getSaveMode("overwrite"))  // Append by default, but in future it should be Overwrite
  .partitionBy(partitionName) // Column of the partition, the date
  .options(target.options)    // header, separator...
  .option("path", target.path) // the path where it will be storage
  .saveAsTable(target.tableName)  // the table name
</code></pre>

<p>What happens in my flow? If I use the SaveMode.Overwrite, the complete table will be delete and I will have only the partition saved. If I use the SaveMode.Append I could have duplicate data. </p>

<p>Making a search, I found that Hive support this kind of overwrite, only partition, but using the hql sentences, I don´t have it.</p>

<p>We need the solution on Hive, so we can´t use this <a href="https://stackoverflow.com/questions/38487667/overwrite-specific-partitions-in-spark-dataframe-write-method">alternative option</a> (direct to csv).</p>

<p>I had found this <a href="https://issues.apache.org/jira/browse/SPARK-20236" rel="noreferrer">Jira ticket</a> that suppose to solve the problem that I´m having, but trying that with the last version of Spark (2.3.0), the situation was the same. It delete the whole table and save the partition instead of overwrite the partition that my data has.</p>

<p>Trying to make clearer this, this is an example:</p>

<p>Partitioned by A</p>

<p>Data: </p>

<pre><code>| A | B | C | 
|---|---|---| 
| b | 1 | 2 | 
| c | 1 | 2 |
</code></pre>

<p>Table:</p>

<pre><code>| A | B | C | 
|---|---|---| 
| a | 1 | 2 | 
| b | 5 | 2 | 
</code></pre>

<p>What I want is: In Table, the partition <code>a</code> stay in table, partition <code>b</code> overwrite with the Data, and add the partition <code>c</code>. Is there any solution using Spark that I can do this? </p>

<p>My last option to do this is first deleting the partition that is going to be saved and then use the SaveMode.Append, but I would try this in case no other solution.</p>
