Uh oh!
There was an error while loading. Please reload this page.
[SPARK-43438][SQL] Error on missing input columns in INSERT - #42393
[SPARK-43438][SQL] Error on missing input columns in INSERT#42393MaxGekk wants to merge 17 commits into
INSERT#42393Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
INSERTINSERTUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| } | ||
| withTable("t") { | ||
| sql("create table t(i int, s bigint default 42, x bigint) using parquet") | ||
| sql("insert into t values(1)") |
There was a problem hiding this comment.
which Spark version added this test?
There was a problem hiding this comment.
Added by #41262 which haven't been released yet.
dtenedor
left a comment
There was a problem hiding this comment.
LGTM, there's enough test coverage for INSERT commands with and without user-specified column lists, and with correct and incorrect numbers of attributes from the source table.
MaxGekk
commented
Aug 29, 2023
Merging to master/3.5. Thank you, @cloud-fan and @dtenedor for review. |
### 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 <max.gekk@gmail.com> Signed-off-by: Max Gekk <max.gekk@gmail.com> (cherry picked from commit a7eef21) Signed-off-by: Max Gekk <max.gekk@gmail.com>
What changes were proposed in this pull request?
In the PR, I propose to raise an error when an user uses V1
INSERTwithout 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?
Apparently, the insertion below must not succeed:
Does this PR introduce any user-facing change?
Yes.
After the changes:
How was this patch tested?
By running the modified tests: