Commit a7eef21
committed
[SPARK-43438][SQL] Error on missing input columns in
### What changes were proposed in this pull request?
In the PR, I propose to raise an error when an user uses V1 `INSERT` without a list of columns, and the number of inserting columns doesn't match to the number of actual table columns.
At the moment Spark inserts data successfully in such case after the PR #41262 which changed the behaviour of Spark 3.4.x.
### Why are the changes needed?
1. To conform the SQL standard which requires the number of columns must be the same:

Apparently, the insertion below must not succeed:
```sql
spark-sql (default)> CREATE TABLE tabtest(c1 INT, c2 INT);
spark-sql (default)> INSERT INTO tabtest SELECT 1;
```
2. To have the same behaviour as **Spark 3.4**:
```sql
spark-sql (default)> INSERT INTO tabtest SELECT 1;
`spark_catalog`.`default`.`tabtest` requires that the data to be inserted have the same number of columns as the target table: target table has 2 column(s) but the inserted data has 1 column(s), including 0 partition column(s) having constant value(s).
```
### Does this PR introduce _any_ user-facing change?
Yes.
After the changes:
```sql
spark-sql (default)> INSERT INTO tabtest SELECT 1;
[INSERT_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS] Cannot write to `spark_catalog`.`default`.`tabtest`, the reason is not enough data columns:
Table columns: `c1`, `c2`.
Data columns: `1`.
```
### How was this patch tested?
By running the modified tests:
```
$ build/sbt "test:testOnly *InsertSuite"
$ build/sbt "test:testOnly *ResolveDefaultColumnsSuite"
$ build/sbt -Phive "test:testOnly *HiveQuerySuite"
```
Closes #42393 from MaxGekk/fix-num-cols-insert.
Authored-by: Max Gekk <[email protected]>
Signed-off-by: Max Gekk <[email protected]>INSERT
1 parent 8505084 commit a7eef21
File tree
6 files changed
+69
-37
lines changed- sql
- catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis
- core/src
- main/scala/org/apache/spark/sql/execution/datasources
- test/scala/org/apache/spark/sql
- sources
- hive/src/test/scala/org/apache/spark/sql/hive
- execution
6 files changed
+69
-37
lines changedLines changed: 2 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 106 | + | |
117 | 107 | | |
118 | 108 | | |
119 | 109 | | |
120 | | - | |
121 | | - | |
| 110 | + | |
122 | 111 | | |
123 | 112 | | |
124 | 113 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
408 | 412 | | |
409 | 413 | | |
410 | 414 | | |
| |||
Lines changed: 47 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
41 | 47 | | |
42 | 48 | | |
43 | 49 | | |
| |||
57 | 63 | | |
58 | 64 | | |
59 | 65 | | |
60 | | - | |
61 | | - | |
62 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
63 | 75 | | |
64 | 76 | | |
65 | 77 | | |
66 | 78 | | |
67 | 79 | | |
68 | 80 | | |
69 | 81 | | |
70 | | - | |
71 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
72 | 91 | | |
73 | 92 | | |
74 | 93 | | |
| |||
77 | 96 | | |
78 | 97 | | |
79 | 98 | | |
80 | | - | |
81 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
82 | 109 | | |
83 | 110 | | |
84 | 111 | | |
| |||
87 | 114 | | |
88 | 115 | | |
89 | 116 | | |
90 | | - | |
91 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
92 | 127 | | |
93 | 128 | | |
94 | 129 | | |
| |||
Lines changed: 11 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
962 | 962 | | |
963 | 963 | | |
964 | 964 | | |
965 | | - | |
966 | | - | |
967 | | - | |
968 | | - | |
969 | | - | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
970 | 974 | | |
971 | 975 | | |
972 | 976 | | |
| |||
1027 | 1031 | | |
1028 | 1032 | | |
1029 | 1033 | | |
1030 | | - | |
| 1034 | + | |
1031 | 1035 | | |
1032 | 1036 | | |
1033 | 1037 | | |
| |||
1495 | 1499 | | |
1496 | 1500 | | |
1497 | 1501 | | |
1498 | | - | |
| 1502 | + | |
1499 | 1503 | | |
1500 | 1504 | | |
1501 | 1505 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
394 | | - | |
| 394 | + | |
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1258 | 1258 | | |
1259 | 1259 | | |
1260 | 1260 | | |
1261 | | - | |
| 1261 | + | |
1262 | 1262 | | |
1263 | 1263 | | |
1264 | | - | |
1265 | | - | |
| 1264 | + | |
| 1265 | + | |
1266 | 1266 | | |
1267 | 1267 | | |
1268 | 1268 | | |
| |||
0 commit comments