Commit d1b8bd7
committed
[SPARK-34720][SQL] MERGE ... UPDATE/INSERT * should do by-name resolution
### What changes were proposed in this pull request?
In Spark, we have an extension in the MERGE syntax: INSERT/UPDATE *. This is not from ANSI standard or any other mainstream databases, so we need to define the behaviors by our own.
The behavior today is very weird: assume the source table has `n1` columns, target table has `n2` columns. We generate the assignments by taking the first `min(n1, n2)` columns from source & target tables and pairing them by ordinal.
This PR proposes a more reasonable behavior: take all the columns from target table as keys, and find the corresponding columns from source table by name as values.
### Why are the changes needed?
Fix the MEREG INSERT/UPDATE * to be more user-friendly and easy to do schema evolution.
### Does this PR introduce _any_ user-facing change?
Yes, but MERGE is only supported by very few data sources.
### How was this patch tested?
new tests
Closes #32192 from cloud-fan/merge.
Authored-by: Wenchen Fan <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>1 parent c1e995a commit d1b8bd7
File tree
2 files changed
+86
-36
lines changed- sql
- catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis
- core/src/test/scala/org/apache/spark/sql/execution/command
2 files changed
+86
-36
lines changedLines changed: 40 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1469 | 1469 | | |
1470 | 1470 | | |
1471 | 1471 | | |
1472 | | - | |
1473 | 1472 | | |
1474 | 1473 | | |
1475 | | - | |
| 1474 | + | |
| 1475 | + | |
1476 | 1476 | | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
1477 | 1480 | | |
1478 | 1481 | | |
1479 | | - | |
| 1482 | + | |
| 1483 | + | |
1480 | 1484 | | |
1481 | 1485 | | |
1482 | 1486 | | |
| |||
1487 | 1491 | | |
1488 | 1492 | | |
1489 | 1493 | | |
1490 | | - | |
| 1494 | + | |
1491 | 1495 | | |
1492 | 1496 | | |
1493 | 1497 | | |
1494 | 1498 | | |
1495 | 1499 | | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
1496 | 1503 | | |
1497 | 1504 | | |
1498 | | - | |
| 1505 | + | |
1499 | 1506 | | |
1500 | 1507 | | |
1501 | 1508 | | |
| |||
1513 | 1520 | | |
1514 | 1521 | | |
1515 | 1522 | | |
1516 | | - | |
| 1523 | + | |
1517 | 1524 | | |
1518 | 1525 | | |
1519 | | - | |
1520 | | - | |
1521 | | - | |
1522 | | - | |
1523 | | - | |
1524 | | - | |
1525 | | - | |
1526 | | - | |
1527 | | - | |
1528 | | - | |
1529 | | - | |
1530 | | - | |
1531 | | - | |
1532 | | - | |
1533 | | - | |
1534 | | - | |
1535 | | - | |
1536 | | - | |
1537 | | - | |
1538 | | - | |
1539 | | - | |
1540 | | - | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
1541 | 1531 | | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
1542 | 1553 | | |
| 1554 | + | |
1543 | 1555 | | |
1544 | 1556 | | |
1545 | 1557 | | |
| |||
Lines changed: 46 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
58 | 72 | | |
59 | 73 | | |
60 | 74 | | |
| |||
91 | 105 | | |
92 | 106 | | |
93 | 107 | | |
94 | | - | |
| 108 | + | |
| 109 | + | |
95 | 110 | | |
96 | 111 | | |
97 | 112 | | |
| |||
107 | 122 | | |
108 | 123 | | |
109 | 124 | | |
110 | | - | |
| 125 | + | |
111 | 126 | | |
112 | 127 | | |
113 | 128 | | |
| |||
1385 | 1400 | | |
1386 | 1401 | | |
1387 | 1402 | | |
1388 | | - | |
| 1403 | + | |
1389 | 1404 | | |
1390 | 1405 | | |
1391 | 1406 | | |
| |||
1405 | 1420 | | |
1406 | 1421 | | |
1407 | 1422 | | |
1408 | | - | |
| 1423 | + | |
1409 | 1424 | | |
1410 | 1425 | | |
1411 | 1426 | | |
| |||
1414 | 1429 | | |
1415 | 1430 | | |
1416 | 1431 | | |
1417 | | - | |
1418 | | - | |
| 1432 | + | |
1419 | 1433 | | |
1420 | 1434 | | |
1421 | 1435 | | |
| |||
1507 | 1521 | | |
1508 | 1522 | | |
1509 | 1523 | | |
1510 | | - | |
| 1524 | + | |
1511 | 1525 | | |
1512 | 1526 | | |
1513 | 1527 | | |
| |||
1516 | 1530 | | |
1517 | 1531 | | |
1518 | 1532 | | |
1519 | | - | |
| 1533 | + | |
1520 | 1534 | | |
1521 | 1535 | | |
1522 | 1536 | | |
1523 | 1537 | | |
1524 | 1538 | | |
1525 | 1539 | | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
1526 | 1564 | | |
1527 | 1565 | | |
1528 | 1566 | | |
| |||
0 commit comments