Search in sources :

Example 11 with TestTable

use of io.trino.testing.sql.TestTable in project trino by trinodb.

the class TestJdbcConnectorTest method testUnknownTypeAsIgnored.

@Test
public void testUnknownTypeAsIgnored() {
    try (TestTable table = new TestTable(onRemoteDatabase(), "tpch.test_failure_on_unknown_type_as_ignored", "(int_column int, geometry_column GEOMETRY)", ImmutableList.of("1, NULL", "2, 'POINT(7 52)'"))) {
        Session ignoreUnsupportedType = unsupportedTypeHandling(IGNORE);
        assertQuery(ignoreUnsupportedType, "SELECT int_column FROM " + table.getName(), "VALUES 1, 2");
        assertQuery(ignoreUnsupportedType, "SELECT * FROM " + table.getName(), "VALUES 1, 2");
        assertQuery(ignoreUnsupportedType, "SELECT column_name, data_type FROM information_schema.columns WHERE table_name LIKE 'test_failure_on_unknown_type_as_ignored%'", "VALUES ('int_column', 'integer')");
        assertQuery(ignoreUnsupportedType, "DESCRIBE " + table.getName(), "VALUES ('int_column', 'integer', '', '')");
        assertUpdate(ignoreUnsupportedType, format("INSERT INTO %s (int_column) VALUES (3)", table.getName()), 1);
        assertQuery(ignoreUnsupportedType, "SELECT * FROM " + table.getName(), "VALUES 1, 2, 3");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 12 with TestTable

use of io.trino.testing.sql.TestTable in project trino by trinodb.

the class TestBigQueryConnectorTest method testColumnPositionMismatch.

/**
 * https://github.com/trinodb/trino/issues/8183
 */
@Test
public void testColumnPositionMismatch() {
    try (TestTable table = new TestTable(getQueryRunner()::execute, "test.test_column_position_mismatch", "(c_varchar VARCHAR, c_int INT, c_date DATE)")) {
        onBigQuery("INSERT INTO " + table.getName() + " VALUES ('a', 1, '2021-01-01')");
        // Adding a CAST makes BigQuery return columns in a different order
        assertQuery("SELECT c_varchar, CAST(c_int AS SMALLINT), c_date FROM " + table.getName(), "VALUES ('a', 1, '2021-01-01')");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 13 with TestTable

use of io.trino.testing.sql.TestTable in project trino by trinodb.

the class TestClickHouseTypeMapping method testUnsupportedTimestamp.

@Test
public void testUnsupportedTimestamp() {
    try (TestTable table = new TestTable(getQueryRunner()::execute, "test_unsupported_timestamp", "(dt timestamp(0))")) {
        assertQueryFails(format("INSERT INTO %s VALUES (TIMESTAMP '-9999-12-31 23:59:59')", table.getName()), "Timestamp must be between 1970-01-01 00:00:00 and 2105-12-31 23:59:59 in ClickHouse: -9999-12-31 23:59:59");
        assertQueryFails(format("INSERT INTO %s VALUES (TIMESTAMP '1969-12-31 23:59:59')", table.getName()), "Timestamp must be between 1970-01-01 00:00:00 and 2105-12-31 23:59:59 in ClickHouse: 1969-12-31 23:59:59");
        assertQueryFails(format("INSERT INTO %s VALUES (TIMESTAMP '2106-01-01 00:00:00')", table.getName()), "Timestamp must be between 1970-01-01 00:00:00 and 2105-12-31 23:59:59 in ClickHouse: 2106-01-01 00:00:00");
        assertQueryFails(format("INSERT INTO %s VALUES (TIMESTAMP '9999-12-31 23:59:59')", table.getName()), "Timestamp must be between 1970-01-01 00:00:00 and 2105-12-31 23:59:59 in ClickHouse: 9999-12-31 23:59:59");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 14 with TestTable

use of io.trino.testing.sql.TestTable in project trino by trinodb.

the class TestClickHouseTypeMapping method testUnsupportedUint32.

@Test
public void testUnsupportedUint32() {
    // ClickHouse stores incorrect results when the values are out of supported range. This test should be fixed when ClickHouse changes the behavior.
    SqlDataTypeTest.create().addRoundTrip("UInt32", "-1", BIGINT, "BIGINT '4294967295'").addRoundTrip("UInt32", "4294967296", BIGINT, "BIGINT '0'").execute(getQueryRunner(), clickhouseCreateAndInsert("tpch.test_unsupported_uint32"));
    // Prevent writing incorrect results in the connector
    try (TestTable table = new TestTable(clickhouseServer::execute, "tpch.test_unsupported_uint32", "(value UInt32) ENGINE=Log")) {
        assertQueryFails(format("INSERT INTO %s VALUES (CAST('-1' AS BIGINT))", table.getName()), "Value must be between 0 and 4294967295 in ClickHouse: -1");
        assertQueryFails(format("INSERT INTO %s VALUES (CAST('4294967296' AS BIGINT))", table.getName()), "Value must be between 0 and 4294967295 in ClickHouse: 4294967296");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 15 with TestTable

use of io.trino.testing.sql.TestTable in project trino by trinodb.

the class TestClickHouseTypeMapping method testUnsupportedUint64.

@Test
public void testUnsupportedUint64() {
    // ClickHouse stores incorrect results when the values are out of supported range. This test should be fixed when ClickHouse changes the behavior.
    SqlDataTypeTest.create().addRoundTrip("UInt64", "-1", createDecimalType(20), "CAST('18446744073709551615' AS decimal(20, 0))").addRoundTrip("UInt64", "18446744073709551616", createDecimalType(20), "CAST('0' AS decimal(20, 0))").execute(getQueryRunner(), clickhouseCreateAndInsert("tpch.test_unsupported_uint64"));
    // Prevent writing incorrect results in the connector
    try (TestTable table = new TestTable(clickhouseServer::execute, "tpch.test_unsupported_uint64", "(value UInt64) ENGINE=Log")) {
        assertQueryFails(format("INSERT INTO %s VALUES (CAST('-1' AS decimal(20, 0)))", table.getName()), "Value must be between 0 and 18446744073709551615 in ClickHouse: -1");
        assertQueryFails(format("INSERT INTO %s VALUES (CAST('18446744073709551616' AS decimal(20, 0)))", table.getName()), "Value must be between 0 and 18446744073709551615 in ClickHouse: 18446744073709551616");
    }
}
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