-
Notifications
You must be signed in to change notification settings - Fork 28k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-40000][SQL] Update INSERTs without user-specified fields to no…
…t automatically add default values ### What changes were proposed in this pull request? Update INSERTs without user-specified fields to not automatically add default values. For example, with the new behavior, this `INSERT INTO` command will fail with an error message reporting that the table has two columns but the command only inserted one: ``` CREATE TABLE t (a INT DEFAULT 1, b INT DEFAULT 2) USING PARQUET; INSERT INTO t VALUES (42); ``` For INSERTs with user-specified fields, these commands may now specify fewer field/value pairs than the number of columns in the target table. The analyzer will assign the default value for each remaining column (either NULL, or else the explicit DEFAULT value assigned to the column from a previous command). For example, with the new behavior, this `INSERT INTO` command will succeed, assigning the new row `(42, 2)` to the target table: ``` CREATE TABLE t (a INT DEFAULT 1, b INT DEFAULT 2) USING PARQUET; INSERT INTO t (a) VALUES (42); ``` To implement this behavior, this PR creates the following config which is true by default: `spark.sql.defaultColumn.addMissingValuesForInsertsWithExplicitColumns` To switch back to the previous behavior of returning errors for `INSERT INTO` commands with fewer user-specified fields than the number of columns in the target table, switch this new config to false. ### Why are the changes needed? After looking at desired SQL semantics, it is preferred to be strict and require that the number of inserted columns exactly matches the target table to prevent against accidental mistakes. ### Does this PR introduce _any_ user-facing change? Yes, see above. ### How was this patch tested? Updated unit test coverage. Closes #37430 from dtenedor/insert-fewer-columns. Lead-authored-by: Daniel Tenedorio <daniel.tenedorio@databricks.com> Co-authored-by: Gengliang Wang <gengliang@apache.org> Signed-off-by: Gengliang Wang <gengliang@apache.org>
- Loading branch information
1 parent
2511584
commit 13c1b59
Showing
6 changed files
with
194 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.