Commit 73dd6ed
[SPARK-55690] Schema evolution in DSv2 AppendData, OverwriteByExpression, OverwritePartitionsDynamic
### What changes were proposed in this pull request?
Adds support for schema evolution during INSERT operations (AppendData, OverwriteByExpression, OverwritePartitionsDynamic)
When the table reports capability `AUTOMATIC_SCHEMA_EVOLUTION`, a new analyzer rule `ResolveInsertSchemaEvolution` collects new columns and nested fields present in the source query but not in the table schema, and adds them to the target table by calling `catalog.alterTable()`
Identifying new columns/fields respects the resolution semantics of INSERT operations: matching fields by-name vs by-position.
This builds on previous from szehon-ho , in particular #51698.
The first two commits move this previous code around to reuse it, the core of the implementation is in the [third commit](7be9d2a).
### Why are the changes needed?
The `WITH SCHEMA EVOLUTION` syntax for SQL inserts was added recently: #53732. This actually implements schema evolution behind this syntax.
### Does this PR introduce _any_ user-facing change?
Yes, when the `WITH SCHEMA EVOLUTION` clause is specified in SQL INSERT operations, new columns and nested fields in the source data will be added to the target table - assuming the data source supports schema evolution (capability AUTOMATIC_SCHEMA_EVOLUTION):
```
CREATE TABLE target (id INT);
INSERT INTO target VALUES (1);
INSERT WITH SCHEMA EVOLUTION INTO target SELECT 2 AS id, "two" AS value;
SELECT * FROM target;
| id | value |
|----|-------|
| 1 | null |
| 2 | "two" |
```
### How was this patch tested?
Added basic testing in `DataSourceV2SQLSuite`.
Integrated with Delta and ran extensive Delta test harness for schema evolution against this implementation.
See delta-io/delta#6140. A number of expected failures for tests that would need to be updated on Delta side (different error class returned, negative tests checking something specifically doesn't work if a fix is disabled, ..)
Closes #54488 from johanl-db/dsv2-schema-evolution-insert.
Authored-by: Johan Lasperas <[email protected]>
Signed-off-by: Anton Okolnychyi <[email protected]>1 parent cbbbd41 commit 73dd6ed
File tree
16 files changed
+1041
-322
lines changed- common/utils/src/main/resources/error
- sql
- catalyst/src
- main/scala/org/apache/spark/sql
- catalyst
- analysis
- parser
- plans/logical
- errors
- test/scala/org/apache/spark/sql/connector/catalog
- core/src
- main/scala/org/apache/spark/sql/execution/datasources
- v2
- test/scala/org/apache/spark/sql
- connector
- execution/command
16 files changed
+1041
-322
lines changedLines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7126 | 7126 | | |
7127 | 7127 | | |
7128 | 7128 | | |
| 7129 | + | |
| 7130 | + | |
| 7131 | + | |
| 7132 | + | |
| 7133 | + | |
7129 | 7134 | | |
7130 | 7135 | | |
7131 | 7136 | | |
| |||
Lines changed: 9 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
453 | | - | |
| 453 | + | |
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
| |||
1167 | 1167 | | |
1168 | 1168 | | |
1169 | 1169 | | |
1170 | | - | |
1171 | | - | |
1172 | | - | |
1173 | 1170 | | |
1174 | 1171 | | |
1175 | 1172 | | |
| |||
1179 | 1176 | | |
1180 | 1177 | | |
1181 | 1178 | | |
1182 | | - | |
| 1179 | + | |
1183 | 1180 | | |
1184 | 1181 | | |
1185 | 1182 | | |
1186 | 1183 | | |
1187 | | - | |
| 1184 | + | |
1188 | 1185 | | |
1189 | 1186 | | |
1190 | 1187 | | |
1191 | 1188 | | |
1192 | 1189 | | |
1193 | 1190 | | |
1194 | | - | |
| 1191 | + | |
1195 | 1192 | | |
1196 | 1193 | | |
1197 | 1194 | | |
1198 | 1195 | | |
1199 | | - | |
| 1196 | + | |
1200 | 1197 | | |
1201 | 1198 | | |
1202 | 1199 | | |
1203 | 1200 | | |
1204 | 1201 | | |
1205 | 1202 | | |
1206 | 1203 | | |
1207 | | - | |
| 1204 | + | |
1208 | 1205 | | |
1209 | 1206 | | |
1210 | 1207 | | |
1211 | 1208 | | |
1212 | 1209 | | |
1213 | | - | |
| 1210 | + | |
1214 | 1211 | | |
1215 | 1212 | | |
1216 | 1213 | | |
| |||
3637 | 3634 | | |
3638 | 3635 | | |
3639 | 3636 | | |
3640 | | - | |
| 3637 | + | |
| 3638 | + | |
3641 | 3639 | | |
3642 | 3640 | | |
3643 | 3641 | | |
| |||
Lines changed: 0 additions & 98 deletions
This file was deleted.
0 commit comments