SQL MERGE throw if assigning null to non-null column#13535
SQL MERGE throw if assigning null to non-null column#13535electrum merged 2 commits intotrinodb:masterfrom
Conversation
88e421e to
518462f
Compare
|
are the build failures related? |
|
As commented under the issue #13526 (comment), this should ideally be enforced by the planner-injected checks. You can see #13462 for how this can be done. Alternatively we can merge this PR and @homar or someone else will follow up. |
518462f to
7c22429
Compare
core/trino-main/src/main/java/io/trino/operator/ChangeOnlyUpdatedColumnsMergeProcessor.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/operator/DeleteAndInsertMergeProcessor.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/operator/MergeProcessorOperator.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Do we want to filter out hidden columns? What happens if someone assigns to a hidden column?
There was a problem hiding this comment.
I didn't know it was possible to assign to a hidden column.
I'll have to look at everywhere else where I've excluded hidden columns.
...rino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeMinioConnectorTest.java
Outdated
Show resolved
Hide resolved
7c22429 to
229170b
Compare
I thought I'd responded to this but I don't see the response. Yes, since setting non-null target columns to null is a correctness issue, I think it's best if we merge this PR and then follow up with an alternative solution if we think it's beneficial. |
it is
it it solves the problem, yes but mind that similar approach for inserts didn't actually work: #13434 |
testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java
Outdated
Show resolved
Hide resolved
39e4a4c to
8787750
Compare
|
I really think this PR should be merged, since allowing null to be assigned to a non-null column is a big-time correctness issue. Can someone who agrees and has the ability to merge it please do so? |
There was a problem hiding this comment.
It would be useful to indicate which column has the issue
There was a problem hiding this comment.
We could add them to MergeParadigmAndTypes
There was a problem hiding this comment.
Added, and now the non-null column test lists the non-null column name assigned to.
There was a problem hiding this comment.
We could add them to MergeParadigmAndTypes
There was a problem hiding this comment.
Let's remove the hidden filter here. It seems unrelated to nullability. If we later allowed updating hidden columns (not unreasonable), it would be easy to miss updating the code here.
core/trino-main/src/main/java/io/trino/sql/planner/LogicalPlanner.java
Outdated
Show resolved
Hide resolved
This commit changes the two implementations of MergeRowChangeProcessor to throw an exception if a null value is assigned to a non-null column as a result of an SQL MERGE operation. An alternative approach would have been to change the query plan to insert such checks, but the chosen approach is simpler. This commit adds a BaseConnectorTest showing that SQL MERGE prevents assignment of NULL to non-null target table columns.
8787750 to
0d5a616
Compare
Description
SQL MERGE throw if assigning null to non-null column
This commit changes the two implementations of
MergeRowChangeProcessor to throw an exception if a
null value is assigned to a non-null column as a
result of an SQL MERGE operation. An alternative
approach would have been to change the query plan
to insert such checks, but the chosen approach is
simpler.
This commit adds a BaseConnectorTest showing that SQL MERGE
prevents assignment of NULL to non-null target table columns.
It's either a fix or a new feature, depending on how you look at it. It only applies to SQL MERGE which was merged two days ago.
These changes were to the machinery supporting SQL MERGE in the Trino engine.
Related issues, pull requests, and links
Fixes #13526
Documentation
( ) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.
Release notes
( ) No release notes entries required.
( ) Release notes entries required with the following suggested text: