Search in sources :

Example 1 with JdbcSqlExecutor

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

the class TestJdbcCachingConnectorSmokeTest method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    Map<String, String> properties = ImmutableMap.<String, String>builder().putAll(TestingH2JdbcModule.createProperties()).put("metadata.cache-ttl", "10m").put("metadata.cache-missing", "true").put("case-insensitive-name-matching", "true").buildOrThrow();
    this.h2SqlExecutor = new JdbcSqlExecutor(properties.get("connection-url"), new Properties());
    return createH2QueryRunner(REQUIRED_TPCH_TABLES, properties);
}
Also used : JdbcSqlExecutor(io.trino.testing.sql.JdbcSqlExecutor) Properties(java.util.Properties)

Example 2 with JdbcSqlExecutor

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

the class TestPostgreSqlTypeMapping method setUp.

@BeforeClass
public void setUp() {
    checkState(jvmZone.getId().equals("America/Bahia_Banderas"), "This test assumes certain JVM time zone");
    checkIsGap(jvmZone, timeGapInJvmZone1);
    checkIsGap(jvmZone, timeGapInJvmZone2);
    checkIsDoubled(jvmZone, timeDoubledInJvmZone);
    LocalDate dateOfLocalTimeChangeForwardAtMidnightInSomeZone = LocalDate.of(1983, 4, 1);
    checkIsGap(vilnius, dateOfLocalTimeChangeForwardAtMidnightInSomeZone.atStartOfDay());
    LocalDate dateOfLocalTimeChangeBackwardAtMidnightInSomeZone = LocalDate.of(1983, 10, 1);
    checkIsDoubled(vilnius, dateOfLocalTimeChangeBackwardAtMidnightInSomeZone.atStartOfDay().minusMinutes(1));
    checkIsGap(vilnius, timeGapInVilnius);
    checkIsDoubled(vilnius, timeDoubledInVilnius);
    checkIsGap(kathmandu, timeGapInKathmandu);
    JdbcSqlExecutor executor = new JdbcSqlExecutor(postgreSqlServer.getJdbcUrl(), postgreSqlServer.getProperties());
    executor.execute("CREATE EXTENSION hstore WITH SCHEMA public");
}
Also used : JdbcSqlExecutor(io.trino.testing.sql.JdbcSqlExecutor) LocalDate(java.time.LocalDate) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with JdbcSqlExecutor

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

the class TestPostgreSqlTypeMapping method testEnum.

@Test
public void testEnum() {
    JdbcSqlExecutor jdbcSqlExecutor = new JdbcSqlExecutor(postgreSqlServer.getJdbcUrl(), postgreSqlServer.getProperties());
    jdbcSqlExecutor.execute("CREATE TYPE enum_t AS ENUM ('a','b','c')");
    jdbcSqlExecutor.execute("CREATE TABLE test_enum(id int, enum_column enum_t)");
    jdbcSqlExecutor.execute("INSERT INTO test_enum(id,enum_column) values (1,'a'::enum_t),(2,'b'::enum_t)");
    try {
        assertQuery("SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'tpch' AND table_name = 'test_enum'", "VALUES ('id','integer'),('enum_column','varchar')");
        assertQuery("SELECT * FROM test_enum", "VALUES (1,'a'),(2,'b')");
        assertQuery("SELECT * FROM test_enum WHERE enum_column='a'", "VALUES (1,'a')");
    } finally {
        jdbcSqlExecutor.execute("DROP TABLE test_enum");
        jdbcSqlExecutor.execute("DROP TYPE enum_t");
    }
}
Also used : JdbcSqlExecutor(io.trino.testing.sql.JdbcSqlExecutor) Test(org.testng.annotations.Test) DataTypeTest(io.trino.testing.datatype.DataTypeTest) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 4 with JdbcSqlExecutor

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

the class TestPostgreSqlTypeMapping method testDecimalExceedingPrecisionMaxWithSupportedValues.

@Test(dataProvider = "testDecimalExceedingPrecisionMaxProvider")
public void testDecimalExceedingPrecisionMaxWithSupportedValues(int typePrecision, int typeScale) {
    JdbcSqlExecutor jdbcSqlExecutor = new JdbcSqlExecutor(postgreSqlServer.getJdbcUrl(), postgreSqlServer.getProperties());
    try (TestTable testTable = new TestTable(jdbcSqlExecutor, "test_exceeding_max_decimal", format("(d_col decimal(%d,%d))", typePrecision, typeScale), asList("12.01", "-12.01", "123", "-123", "1.12345678", "-1.12345678"))) {
        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");
        assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 0), "SELECT d_col FROM " + testTable.getName(), "VALUES (12), (-12), (123), (-123), (1), (-1)");
        assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 3), 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,3)')");
        assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 3), "SELECT d_col FROM " + testTable.getName(), "VALUES (12.01), (-12.01), (123), (-123), (1.123), (-1.123)");
        assertQueryFails(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 3), "SELECT d_col FROM " + testTable.getName(), "Rounding necessary");
        assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 8), 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,8)')");
        assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 8), "SELECT d_col FROM " + testTable.getName(), "VALUES (12.01), (-12.01), (123), (-123), (1.12345678), (-1.12345678)");
        assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 9), "SELECT d_col FROM " + testTable.getName(), "VALUES (12.01), (-12.01), (123), (-123), (1.12345678), (-1.12345678)");
        assertQuery(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 8), "SELECT d_col FROM " + testTable.getName(), "VALUES (12.01), (-12.01), (123), (-123), (1.12345678), (-1.12345678)");
    }
}
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 5 with JdbcSqlExecutor

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

the class TestPostgreSqlTypeMapping method testDecimalUnspecifiedPrecisionWithSupportedValues.

@Test
public void testDecimalUnspecifiedPrecisionWithSupportedValues() {
    JdbcSqlExecutor jdbcSqlExecutor = new JdbcSqlExecutor(postgreSqlServer.getJdbcUrl(), postgreSqlServer.getProperties());
    try (TestTable testTable = new TestTable(jdbcSqlExecutor, "test_var_decimal", "(d_col decimal)", asList("1.12", "123456.789", "-1.12", "-123456.789"))) {
        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");
        assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 0), "SELECT d_col FROM " + testTable.getName(), "VALUES (1), (123457), (-1), (-123457)");
        assertQueryFails(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 1), "SELECT d_col FROM " + testTable.getName(), "Rounding necessary");
        assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 1), 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,1)')");
        assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 1), "SELECT d_col FROM " + testTable.getName(), "VALUES (1.1), (123456.8), (-1.1), (-123456.8)");
        assertQueryFails(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 2), "SELECT d_col FROM " + testTable.getName(), "Rounding necessary");
        assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 2), "SELECT d_col FROM " + testTable.getName(), "VALUES (1.12), (123456.79), (-1.12), (-123456.79)");
        assertQuery(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 3), 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,3)')");
        assertQuery(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 3), "SELECT d_col FROM " + testTable.getName(), "VALUES (1.12), (123456.789), (-1.12), (-123456.789)");
    }
}
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