use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class TestClickHouseConnectorTest method testInsertIntoNotNullColumn.
@Test
@Override
public void testInsertIntoNotNullColumn() {
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_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)");
// ClickHouse inserts default values (e.g. 0 for integer column) even if we don't specify default clause in CREATE TABLE statement
assertUpdate(format("INSERT INTO %s (nullable_col) VALUES (1)", table.getName()), 1);
assertQuery("SELECT * FROM " + table.getName(), "VALUES (NULL, 2), (1, 0)");
}
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_commuted_not_null_table", "(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)");
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");
}
}
use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class TestKuduIntegrationDecimalColumns method testDeleteByPrimaryKeyDecimalColumn.
@Test
public void testDeleteByPrimaryKeyDecimalColumn() {
try (TestTable testTable = new TestTable(new TrinoSqlExecutor(getQueryRunner()), "test_decimal", "(decimal_id decimal(18, 3) WITH (primary_key=true), col_decimal decimal(18, 3)) " + "WITH (partition_by_hash_columns = ARRAY['decimal_id'], partition_by_hash_buckets = 2)")) {
assertUpdate(format("INSERT INTO %s VALUES (1.1, 1.1), (2.2, 2.2)", testTable.getName()), 2);
assertUpdate(format("DELETE FROM %s WHERE decimal_id = 2.2", testTable.getName()), 1);
assertQuery(format("SELECT * FROM %s", testTable.getName()), "VALUES (1.1, 1.1)");
}
}
use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class TestMySqlTypeMapping method testUnsupportedInteger.
@Test
public void testUnsupportedInteger() {
try (TestTable table = new TestTable(mySqlServer::execute, "tpch.test_unsupported_integer", "(data integer)")) {
assertMySqlQueryFails(// min - 1
format("INSERT INTO %s VALUES (-2147483649)", table.getName()), "Data truncation: Out of range value for column 'data' at row 1");
assertMySqlQueryFails(// max + 1
format("INSERT INTO %s VALUES (2147483648)", table.getName()), "Data truncation: Out of range value for column 'data' at row 1");
}
}
use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class TestMySqlTypeMapping method testUnsupportedBigint.
@Test
public void testUnsupportedBigint() {
try (TestTable table = new TestTable(mySqlServer::execute, "tpch.test_unsupported_bigint", "(data bigint)")) {
assertMySqlQueryFails(// min - 1
format("INSERT INTO %s VALUES (-9223372036854775809)", table.getName()), "Data truncation: Out of range value for column 'data' at row 1");
assertMySqlQueryFails(// max + 1
format("INSERT INTO %s VALUES (9223372036854775808)", table.getName()), "Data truncation: Out of range value for column 'data' at row 1");
}
}
use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class TestMySqlTypeMapping method testDecimalExceedingPrecisionMaxWithNonExceedingIntegerValues.
@Test
public void testDecimalExceedingPrecisionMaxWithNonExceedingIntegerValues() {
try (TestTable testTable = new TestTable(mySqlServer::execute, "tpch.test_exceeding_max_decimal", "(d_col decimal(60,20))", asList("123456789012345678901234567890.123456789012345", "-123456789012345678901234567890.123456789012345"))) {
assertQuery(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 0), format("SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'tpch' AND table_schema||'.'||table_name = '%s'", testTable.getName()), "VALUES ('d_col', 'decimal(38,0)')");
assertQueryFails(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 0), "SELECT d_col FROM " + testTable.getName(), "Rounding necessary");
assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 0), "SELECT d_col FROM " + testTable.getName(), "VALUES (123456789012345678901234567890), (-123456789012345678901234567890)");
assertQuery(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 8), format("SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'tpch' AND table_schema||'.'||table_name = '%s'", testTable.getName()), "VALUES ('d_col', 'decimal(38,8)')");
assertQueryFails(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 8), "SELECT d_col FROM " + testTable.getName(), "Rounding necessary");
assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 8), "SELECT d_col FROM " + testTable.getName(), "VALUES (123456789012345678901234567890.12345679), (-123456789012345678901234567890.12345679)");
assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 22), format("SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'tpch' AND table_schema||'.'||table_name = '%s'", testTable.getName()), "VALUES ('d_col', 'decimal(38,20)')");
assertQueryFails(sessionWithDecimalMappingAllowOverflow(HALF_UP, 20), "SELECT d_col FROM " + testTable.getName(), "Decimal overflow");
assertQueryFails(sessionWithDecimalMappingAllowOverflow(HALF_UP, 9), "SELECT d_col FROM " + testTable.getName(), "Decimal overflow");
assertQuery(sessionWithDecimalMappingStrict(CONVERT_TO_VARCHAR), format("SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'tpch' AND table_schema||'.'||table_name = '%s'", testTable.getName()), "VALUES ('d_col', 'varchar')");
assertQuery(sessionWithDecimalMappingStrict(CONVERT_TO_VARCHAR), "SELECT d_col FROM " + testTable.getName(), "VALUES ('123456789012345678901234567890.12345678901234500000'), ('-123456789012345678901234567890.12345678901234500000')");
}
}
Aggregations