Prevent inserting nulls coming from expressions into non nullable columns#13462
Conversation
core/trino-main/src/main/java/io/trino/sql/planner/plan/TableWriterNode.java
Outdated
Show resolved
Hide resolved
238d587 to
296a85b
Compare
|
If the PR is supposed to fix (close) the issue, prepend the issue number with "fixes: ". Thanks |
testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/planner/optimizations/SymbolMapper.java
Outdated
Show resolved
Hide resolved
6ab803e to
9a21e25
Compare
core/trino-main/src/main/java/io/trino/sql/planner/LogicalPlanner.java
Outdated
Show resolved
Hide resolved
9a21e25 to
1d2ed09
Compare
core/trino-main/src/main/java/io/trino/sql/planner/LogicalPlanner.java
Outdated
Show resolved
Hide resolved
testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java
Outdated
Show resolved
Hide resolved
testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java
Outdated
Show resolved
Hide resolved
testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java
Outdated
Show resolved
Hide resolved
testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java
Outdated
Show resolved
Hide resolved
3e14c3e to
f5adf56
Compare
3e14c3e to
f5adf56
Compare
core/trino-main/src/main/java/io/trino/operator/TableWriterOperator.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/planner/LogicalPlanner.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/planner/LogicalPlanner.java
Outdated
Show resolved
Hide resolved
plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java
Outdated
Show resolved
Hide resolved
plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
( #13551 )
// TODO (https://github.com/trinodb/trino/issues/13551) This doesn't fail for other connectors so
// probably shouldn't fail for MariaDB either. Once fixed, remove test override.
(mind two spaces after // on the second comment line)
f5adf56 to
7a0d69b
Compare
plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java
Outdated
Show resolved
Hide resolved
This is now redundant as the checks are inserted by the planner
7a0d69b to
6321160
Compare
| assertQueryFails(format("INSERT INTO %s (nullable_col) SELECT nationkey FROM nation", table.getName()), errorMessageForInsertIntoNotNullColumn("not_null_col")); | ||
| // TODO (https://github.com/trinodb/trino/issues/13551) This doesn't fail for other connectors so | ||
| // probably shouldn't fail for MariaDB either. Once fixed, remove test override. | ||
| assertQueryFails(format("INSERT INTO %s (nullable_col) SELECT nationkey FROM nation WHERE regionkey < 0", table.getName()), ".*Field 'not_null_col' doesn't have a default value.*"); |
There was a problem hiding this comment.
reuse errorMessageForInsertIntoNotNullColumn("not_null_col")
| assertQueryFails(format("INSERT INTO %s (nullable_col) SELECT nationkey FROM nation", table.getName()), errorMessageForInsertIntoNotNullColumn("not_null_col")); | ||
| // TODO (https://github.com/trinodb/trino/issues/13551) This doesn't fail for other connectors so | ||
| // probably shouldn't fail for MariaDB either. Once fixed, remove test override. | ||
| assertQueryFails(format("INSERT INTO %s (nullable_col) SELECT nationkey FROM nation WHERE regionkey < 0", table.getName()), ".*Field 'not_null_col' doesn't have a default value.*"); |
There was a problem hiding this comment.
There seems to be a problem here caused by the current implementation
I modified the test to run like this:
public void testInsertIntoNotNullColumn()
{
try (TestTable table = new TestTable(getQueryRunner()::execute, "insert_not_null", "(nullable_col INTEGER, not_null_col INTEGER NOT NULL)")) {
assertQuerySucceeds(format("INSERT INTO %s (nullable_col) SELECT nationkey FROM nation WHERE regionkey < 0", table.getName()));
}
and I notice the following exception in the stacktrace:
java.lang.AssertionError: Expected query to succeed: INSERT INTO insert_not_null1evdhkhr9c (nullable_col) SELECT nationkey FROM nation WHERE regionkey < 0
...
Suppressed: java.lang.Exception: SQL: INSERT INTO insert_not_null1evdhkhr9c (nullable_col) SELECT nationkey FROM nation WHERE regionkey < 0
.........
Suppressed: java.lang.RuntimeException: Query: INSERT INTO `tpch`.`insert_not_null1evdhkhr9c` (`nullable_col`) SELECT `nullable_col` FROM `tpch`.`tmp_trino_2dc66901e1fa421f9cf3064225e9df13
There seems to be some side-effect of your changes.
There was a problem hiding this comment.
Sorry I don't understand your point here. This query fails because MariaDB does additional check that fails fast which is similar to what I did in LogicalPlanner here
There was a problem hiding this comment.
I get it now. The exception originates from MariaDB which complaints while copying the content from the temporary table towards the target table.
|
Test failure not related and same as here #13556 |
23da3f3 to
6321160
Compare
|
raptor failure is a know flaky #12385 |
|
Second failure is |
|
trino-hive failure seems not to be related - I opened new issue #13600 |
|
In default, suite-7-non-generic |
|
|
I think it can be. I will create a ticket for it |
|
Description
a fix
core query engine
it prevents users from inserting nulls into non nullable columns
Related issues, pull requests, and links
fixes: #13434
Documentation
(x) 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.
(x) Release notes entries required with the following suggested text: