Search in sources :

Example 16 with TestTable

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");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) BaseJdbcConnectorTest(io.trino.plugin.jdbc.BaseJdbcConnectorTest)

Example 17 with TestTable

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)");
    }
}
Also used : TrinoSqlExecutor(io.trino.testing.sql.TrinoSqlExecutor) TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test)

Example 18 with TestTable

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");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 19 with TestTable

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");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 20 with TestTable

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')");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Aggregations

TestTable (io.trino.testing.sql.TestTable)145 Test (org.testng.annotations.Test)132 SqlDataTypeTest (io.trino.testing.datatype.SqlDataTypeTest)50 BaseConnectorTest (io.trino.testing.BaseConnectorTest)26 Session (io.trino.Session)18 BaseJdbcConnectorTest (io.trino.plugin.jdbc.BaseJdbcConnectorTest)17 DataTypeTest (io.trino.testing.datatype.DataTypeTest)15 SkipException (org.testng.SkipException)14 List (java.util.List)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)8 String.format (java.lang.String.format)8 Stream (java.util.stream.Stream)8 ImmutableList (com.google.common.collect.ImmutableList)7 TestingConnectorBehavior (io.trino.testing.TestingConnectorBehavior)7 JdbcSqlExecutor (io.trino.testing.sql.JdbcSqlExecutor)7 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)7 PlanMatchPattern (io.trino.sql.planner.assertions.PlanMatchPattern)6 ExchangeNode (io.trino.sql.planner.plan.ExchangeNode)6 TableScanNode (io.trino.sql.planner.plan.TableScanNode)6