Commit 3424ec7
[SPARK-34720][SQL] MERGE ... UPDATE/INSERT * should do by-name resolution
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.
Fix the MEREG INSERT/UPDATE * to be more user-friendly and easy to do schema evolution.
Yes, but MERGE is only supported by very few data sources.
new tests
Closes apache#32192 from cloud-fan/merge.
Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>1 parent abf48b1 commit 3424ec7
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 | |
|---|---|---|---|
| |||
1646 | 1646 | | |
1647 | 1647 | | |
1648 | 1648 | | |
1649 | | - | |
1650 | 1649 | | |
1651 | 1650 | | |
1652 | | - | |
| 1651 | + | |
| 1652 | + | |
1653 | 1653 | | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
1654 | 1657 | | |
1655 | 1658 | | |
1656 | | - | |
| 1659 | + | |
| 1660 | + | |
1657 | 1661 | | |
1658 | 1662 | | |
1659 | 1663 | | |
| |||
1664 | 1668 | | |
1665 | 1669 | | |
1666 | 1670 | | |
1667 | | - | |
| 1671 | + | |
1668 | 1672 | | |
1669 | 1673 | | |
1670 | 1674 | | |
1671 | 1675 | | |
1672 | 1676 | | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
1673 | 1680 | | |
1674 | 1681 | | |
1675 | | - | |
| 1682 | + | |
1676 | 1683 | | |
1677 | 1684 | | |
1678 | 1685 | | |
| |||
1690 | 1697 | | |
1691 | 1698 | | |
1692 | 1699 | | |
1693 | | - | |
| 1700 | + | |
1694 | 1701 | | |
1695 | 1702 | | |
1696 | | - | |
1697 | | - | |
1698 | | - | |
1699 | | - | |
1700 | | - | |
1701 | | - | |
1702 | | - | |
1703 | | - | |
1704 | | - | |
1705 | | - | |
1706 | | - | |
1707 | | - | |
1708 | | - | |
1709 | | - | |
1710 | | - | |
1711 | | - | |
1712 | | - | |
1713 | | - | |
1714 | | - | |
1715 | | - | |
1716 | | - | |
1717 | | - | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
1718 | 1708 | | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
1719 | 1730 | | |
| 1731 | + | |
1720 | 1732 | | |
1721 | 1733 | | |
1722 | 1734 | | |
| |||
Lines changed: 46 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
61 | 75 | | |
62 | 76 | | |
63 | 77 | | |
| |||
86 | 100 | | |
87 | 101 | | |
88 | 102 | | |
89 | | - | |
| 103 | + | |
| 104 | + | |
90 | 105 | | |
91 | 106 | | |
92 | 107 | | |
| |||
102 | 117 | | |
103 | 118 | | |
104 | 119 | | |
105 | | - | |
| 120 | + | |
106 | 121 | | |
107 | 122 | | |
108 | 123 | | |
| |||
1369 | 1384 | | |
1370 | 1385 | | |
1371 | 1386 | | |
1372 | | - | |
| 1387 | + | |
1373 | 1388 | | |
1374 | 1389 | | |
1375 | 1390 | | |
| |||
1389 | 1404 | | |
1390 | 1405 | | |
1391 | 1406 | | |
1392 | | - | |
| 1407 | + | |
1393 | 1408 | | |
1394 | 1409 | | |
1395 | 1410 | | |
| |||
1398 | 1413 | | |
1399 | 1414 | | |
1400 | 1415 | | |
1401 | | - | |
1402 | | - | |
| 1416 | + | |
1403 | 1417 | | |
1404 | 1418 | | |
1405 | 1419 | | |
| |||
1491 | 1505 | | |
1492 | 1506 | | |
1493 | 1507 | | |
1494 | | - | |
| 1508 | + | |
1495 | 1509 | | |
1496 | 1510 | | |
1497 | 1511 | | |
| |||
1500 | 1514 | | |
1501 | 1515 | | |
1502 | 1516 | | |
1503 | | - | |
| 1517 | + | |
1504 | 1518 | | |
1505 | 1519 | | |
1506 | 1520 | | |
1507 | 1521 | | |
1508 | 1522 | | |
1509 | 1523 | | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
1510 | 1548 | | |
1511 | 1549 | | |
1512 | 1550 | | |
| |||
0 commit comments