Commit 176e92a
committed
[SPARK-51936][SQL] ReplaceTableAsSelect should overwrite the new table instead of append
For file source v1, if you do
```
Seq(1 -> "a").toDF().write.option("path", p).saveAsTable("t")
Seq(2 -> "b").toDF().write.mode("overwrite").option("path", p).saveAsTable("t")
```
At the end, the data of `t` is `[2, "b"]`, because the v1 command `CreateDataSourceTableAsSelectCommand` uses `Overwrite` mode to write the data to the file directory.
With DS v2, we use the v2 command `ReplaceTableAsSelect`, which uses `AppendData` to write to the new table. If the new table still keeps the old data, which can happen for file source tables, as DROP TABLE won't delete the external location, then the behavior will be different from file source v1.
This PR fixes this inconsistency by using `OverwriteByExpression` in `ReplaceTableAsSelect` physical commands.
Fixes a potential inconsistency issue between file source v1 and v2, for now we are fine as we don't support file source v2 table yet.
This is also helpful for third-party v2 sources that may retain old data in the new table.
No, file source v2 table is not supported yet.
update an existing test
no
Closes #50739 from cloud-fan/RTAS.
Authored-by: Wenchen Fan <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>1 parent eb6cc4c commit 176e92a
File tree
1 file changed
+14
-11
lines changed- sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2
1 file changed
+14
-11
lines changedLines changed: 14 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
| 27 | + | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
| 221 | + | |
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
577 | | - | |
| 577 | + | |
| 578 | + | |
578 | 579 | | |
579 | 580 | | |
580 | | - | |
581 | | - | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
582 | 587 | | |
583 | | - | |
584 | 588 | | |
585 | 589 | | |
586 | 590 | | |
587 | 591 | | |
588 | | - | |
589 | 592 | | |
590 | 593 | | |
591 | 594 | | |
| |||
0 commit comments