diff --git a/plugin/trino-singlestore/src/test/java/io/trino/plugin/singlestore/TestSingleStoreConnectorTest.java b/plugin/trino-singlestore/src/test/java/io/trino/plugin/singlestore/TestSingleStoreConnectorTest.java index c25a5464ba04..68971c65ff29 100644 --- a/plugin/trino-singlestore/src/test/java/io/trino/plugin/singlestore/TestSingleStoreConnectorTest.java +++ b/plugin/trino-singlestore/src/test/java/io/trino/plugin/singlestore/TestSingleStoreConnectorTest.java @@ -223,6 +223,31 @@ public void testSingleStoreTinyint() assertUpdate("DROP TABLE mysql_test_tinyint1"); } + // Overridden because the method from BaseConnectorTest fails on one of the assertions, see TODO below + @Override + public void testInsertIntoNotNullColumn() + { + try (TestTable table = new TestTable(getQueryRunner()::execute, "insert_not_null", "(nullable_col INTEGER, not_null_col INTEGER NOT NULL)")) { + assertUpdate(format("INSERT INTO %s (not_null_col) VALUES (2)", table.getName()), 1); + assertQuery("SELECT * FROM " + table.getName(), "VALUES (NULL, 2)"); + assertQueryFails(format("INSERT INTO %s (nullable_col) VALUES (1)", table.getName()), errorMessageForInsertIntoNotNullColumn("not_null_col")); + assertQueryFails(format("INSERT INTO %s (not_null_col, nullable_col) VALUES (NULL, 3)", table.getName()), "NULL value not allowed for NOT NULL column: not_null_col"); + assertQueryFails(format("INSERT INTO %s (not_null_col, nullable_col) VALUES (TRY(5/0), 4)", table.getName()), "NULL value not allowed for NOT NULL column: not_null_col"); + assertQueryFails(format("INSERT INTO %s (not_null_col) VALUES (TRY(6/0))", table.getName()), "NULL value not allowed for NOT NULL column: 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 SingleStore 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.*"); + } + + try (TestTable table = new TestTable(getQueryRunner()::execute, "commuted_not_null", "(nullable_col BIGINT, not_null_col BIGINT NOT NULL)")) { + assertUpdate(format("INSERT INTO %s (not_null_col) VALUES (2)", table.getName()), 1); + assertQuery("SELECT * FROM " + table.getName(), "VALUES (NULL, 2)"); + // This is enforced by the engine and not the connector + assertQueryFails(format("INSERT INTO %s (not_null_col, nullable_col) VALUES (NULL, 3)", table.getName()), "NULL value not allowed for NOT NULL column: not_null_col"); + } + } + @Override protected String errorMessageForInsertIntoNotNullColumn(String columnName) {