Search in sources :

Example 11 with JdbcSqlExecutor

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

the class TestPostgreSqlTypeMapping method testTime24.

@Test
public void testTime24() {
    try (TestTable testTable = new TestTable(new JdbcSqlExecutor(postgreSqlServer.getJdbcUrl(), postgreSqlServer.getProperties()), "test_time_24", "(a time(0), b time(3), c time(6))", List.of(// "zero" row
    "TIME '00:00:00', TIME '00:00:00.000', TIME '00:00:00.000000'", // "max" row
    "TIME '23:59:59', TIME '23:59:59.999', TIME '23:59:59.999999'", // "24" row
    "TIME '24:00:00', TIME '24:00:00.000', TIME '24:00:00.000000'"))) {
        // select
        assertThat(query("SELECT a, b, c FROM " + testTable.getName())).matches("VALUES " + "(TIME '00:00:00', TIME '00:00:00.000', TIME '00:00:00.000000'), " + "(TIME '23:59:59', TIME '23:59:59.999', TIME '23:59:59.999999'), " + "(TIME '23:59:59', TIME '23:59:59.999', TIME '23:59:59.999999')");
        // select with predicate -- should not be pushed down
        assertThat(query("SELECT count(*) FROM " + testTable.getName() + " WHERE a = TIME '23:59:59'")).matches("VALUES BIGINT '2'").isNotFullyPushedDown(FilterNode.class);
        assertThat(query("SELECT count(*) FROM " + testTable.getName() + " WHERE b = TIME '23:59:59.999'")).matches("VALUES BIGINT '2'").isNotFullyPushedDown(FilterNode.class);
        assertThat(query("SELECT count(*) FROM " + testTable.getName() + " WHERE c = TIME '23:59:59.999999'")).matches("VALUES BIGINT '2'").isNotFullyPushedDown(FilterNode.class);
    // aggregation should not be pushed down, as it would incorrectly treat values
    // TODO https://github.com/trinodb/trino/issues/5339
    // assertThat(query("SELECT count(*) FROM " + testTable.getName() + " GROUP BY a"))
    // .matches("VALUES BIGINT '1', BIGINT '2'")
    // .isNotFullyPushedDown(AggregationNode.class);
    // assertThat(query("SELECT count(*) FROM " + testTable.getName() + " GROUP BY b"))
    // .matches("VALUES BIGINT '1', BIGINT '2'")
    // .isNotFullyPushedDown(AggregationNode.class);
    // assertThat(query("SELECT count(*) FROM " + testTable.getName() + " GROUP BY c"))
    // .matches("VALUES BIGINT '1', BIGINT '2'")
    // .isNotFullyPushedDown(AggregationNode.class);
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) JdbcSqlExecutor(io.trino.testing.sql.JdbcSqlExecutor) Test(org.testng.annotations.Test) DataTypeTest(io.trino.testing.datatype.DataTypeTest) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 12 with JdbcSqlExecutor

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

the class TestPostgreSqlTypeMapping method testDecimalExceedingPrecisionMaxWithExceedingIntegerValues.

@Test
public void testDecimalExceedingPrecisionMaxWithExceedingIntegerValues() {
    JdbcSqlExecutor jdbcSqlExecutor = new JdbcSqlExecutor(postgreSqlServer.getJdbcUrl(), postgreSqlServer.getProperties());
    try (TestTable testTable = new TestTable(jdbcSqlExecutor, "test_exceeding_max_decimal", "(d_col decimal(65,25))", asList("1234567890123456789012345678901234567890.123456789", "-1234567890123456789012345678901234567890.123456789"))) {
        assertQuery(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 0), format("SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'tpch' AND table_name = '%s'", testTable.getName()), "VALUES ('d_col', 'decimal(38,0)')");
        assertQueryFails(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 0), "SELECT d_col FROM " + testTable.getName(), "Rounding necessary");
        assertQueryFails(sessionWithDecimalMappingAllowOverflow(HALF_UP, 0), "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_name = '%s'", testTable.getName()), "VALUES ('d_col', 'varchar')");
        assertQuery(sessionWithDecimalMappingStrict(CONVERT_TO_VARCHAR), "SELECT d_col FROM " + testTable.getName(), "VALUES ('1234567890123456789012345678901234567890.1234567890000000000000000'), ('-1234567890123456789012345678901234567890.1234567890000000000000000')");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) JdbcSqlExecutor(io.trino.testing.sql.JdbcSqlExecutor) Test(org.testng.annotations.Test) DataTypeTest(io.trino.testing.datatype.DataTypeTest) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Aggregations

JdbcSqlExecutor (io.trino.testing.sql.JdbcSqlExecutor)12 DataTypeTest (io.trino.testing.datatype.DataTypeTest)8 SqlDataTypeTest (io.trino.testing.datatype.SqlDataTypeTest)8 TestTable (io.trino.testing.sql.TestTable)8 Test (org.testng.annotations.Test)8 Session (io.trino.Session)1 TestingSession (io.trino.testing.TestingSession)1 LocalDate (java.time.LocalDate)1 Properties (java.util.Properties)1 BeforeClass (org.testng.annotations.BeforeClass)1