Search in sources :

Example 1 with SqlDataTypeTest

use of io.trino.testing.datatype.SqlDataTypeTest in project trino by trinodb.

the class TestPhoenixTypeMapping method testArrayNulls.

@Test
public void testArrayNulls() {
    // Verify only SELECT instead of using SqlDataTypeTest because array comparison not supported for arrays with null elements
    try (TestTable table = new TestTable(getQueryRunner()::execute, "test_array_nulls", "(c1 ARRAY(boolean), c2 ARRAY(varchar), c3 ARRAY(varchar))", ImmutableList.of("(NULL, ARRAY[NULL], ARRAY['foo', NULL, 'bar', NULL])"))) {
        assertThat(query("SELECT c1 FROM " + table.getName())).matches("VALUES CAST(NULL AS ARRAY(boolean))");
        assertThat(query("SELECT c2 FROM " + table.getName())).matches("VALUES CAST(ARRAY[NULL] AS ARRAY(varchar))");
        assertThat(query("SELECT c3 FROM " + table.getName())).matches("VALUES CAST(ARRAY['foo', NULL, 'bar', NULL] AS ARRAY(varchar))");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 2 with SqlDataTypeTest

use of io.trino.testing.datatype.SqlDataTypeTest in project trino by trinodb.

the class TestPhoenixTypeMapping method testArrayNulls.

@Test
public void testArrayNulls() {
    // Verify only SELECT instead of using SqlDataTypeTest because array comparison not supported for arrays with null elements
    try (TestTable table = new TestTable(getQueryRunner()::execute, "test_array_nulls", "(c1 ARRAY(boolean), c2 ARRAY(varchar), c3 ARRAY(varchar))", ImmutableList.of("(NULL, ARRAY[NULL], ARRAY['foo', NULL, 'bar', NULL])"))) {
        assertThat(query("SELECT c1 FROM " + table.getName())).matches("VALUES CAST(NULL AS ARRAY(boolean))");
        assertThat(query("SELECT c2 FROM " + table.getName())).matches("VALUES CAST(ARRAY[NULL] AS ARRAY(varchar))");
        assertThat(query("SELECT c3 FROM " + table.getName())).matches("VALUES CAST(ARRAY['foo', NULL, 'bar', NULL] AS ARRAY(varchar))");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 3 with SqlDataTypeTest

use of io.trino.testing.datatype.SqlDataTypeTest in project trino by trinodb.

the class TestPostgreSqlTypeMapping method testArrayEmptyOrNulls.

@Test
public void testArrayEmptyOrNulls() {
    SqlDataTypeTest.create().addRoundTrip("ARRAY(bigint)", "ARRAY[]", new ArrayType(BIGINT), "CAST(ARRAY[] AS ARRAY(BIGINT))").addRoundTrip("ARRAY(boolean)", "NULL", new ArrayType(BOOLEAN), "CAST(NULL AS ARRAY(BOOLEAN))").addRoundTrip("ARRAY(integer)", "ARRAY[1, 2, 3, 4]", new ArrayType(INTEGER), "ARRAY[1, 2, 3, 4]").addRoundTrip("ARRAY(timestamp(3))", "ARRAY[]", new ArrayType(createTimestampType(3)), "CAST(ARRAY[] AS ARRAY(TIMESTAMP(3)))").addRoundTrip("ARRAY(timestamp(3) with time zone)", "ARRAY[]", new ArrayType(createTimestampWithTimeZoneType(3)), "CAST(ARRAY[] AS ARRAY(TIMESTAMP(3) WITH TIME ZONE))").execute(getQueryRunner(), sessionWithArrayAsArray(), trinoCreateAsSelect(sessionWithArrayAsArray(), "test_array_empty_or_nulls")).execute(getQueryRunner(), sessionWithArrayAsArray(), trinoCreateAndInsert(sessionWithArrayAsArray(), "test_array_empty_or_nulls"));
    // TODO: Migrate from DataTypeTest. SqlDataTypeTest fails when verifying predicates since we don't support comparing arrays containing NULLs, see https://github.com/trinodb/trino/issues/11397.
    DataTypeTest.create().addRoundTrip(arrayDataType(realDataType()), singletonList(null)).addRoundTrip(arrayDataType(integerDataType()), asList(1, null, 3, null)).addRoundTrip(arrayDataType(timestampDataType(3)), singletonList(null)).addRoundTrip(arrayDataType(trinoTimestampWithTimeZoneDataType(3)), singletonList(null)).execute(getQueryRunner(), sessionWithArrayAsArray(), trinoCreateAsSelect(sessionWithArrayAsArray(), "test_array_empty_or_nulls")).execute(getQueryRunner(), sessionWithArrayAsArray(), trinoCreateAndInsert(sessionWithArrayAsArray(), "test_array_empty_or_nulls"));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) Test(org.testng.annotations.Test) DataTypeTest(io.trino.testing.datatype.DataTypeTest) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 4 with SqlDataTypeTest

use of io.trino.testing.datatype.SqlDataTypeTest in project trino by trinodb.

the class BaseSqlServerTypeMapping method testTimestamp.

@Test(dataProvider = "sessionZonesDataProvider")
public void testTimestamp(ZoneId sessionZone) {
    SqlDataTypeTest tests = SqlDataTypeTest.create().addRoundTrip("TIMESTAMP '1958-01-01 13:18:03.123'", "TIMESTAMP '1958-01-01 13:18:03.123'").addRoundTrip("TIMESTAMP '2019-03-18 10:01:17.987'", "TIMESTAMP '2019-03-18 10:01:17.987'").addRoundTrip("TIMESTAMP '2018-10-28 01:33:17.456'", "TIMESTAMP '2018-10-28 01:33:17.456'").addRoundTrip("TIMESTAMP '2018-10-28 03:33:33.333'", "TIMESTAMP '2018-10-28 03:33:33.333'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.000'", "TIMESTAMP '1970-01-01 00:00:00.000'").addRoundTrip("TIMESTAMP '1970-01-01 00:13:42.000'", "TIMESTAMP '1970-01-01 00:13:42.000'").addRoundTrip("TIMESTAMP '2018-04-01 02:13:55.123'", "TIMESTAMP '2018-04-01 02:13:55.123'").addRoundTrip("TIMESTAMP '2018-03-25 03:17:17.000'", "TIMESTAMP '2018-03-25 03:17:17.000'").addRoundTrip("TIMESTAMP '1986-01-01 00:13:07.000'", "TIMESTAMP '1986-01-01 00:13:07.000'").addRoundTrip("TIMESTAMP '1958-01-01 13:18:03.1230000'", "TIMESTAMP '1958-01-01 13:18:03.1230000'").addRoundTrip("TIMESTAMP '2019-03-18 10:01:17.9870000'", "TIMESTAMP '2019-03-18 10:01:17.9870000'").addRoundTrip("TIMESTAMP '2018-10-28 01:33:17.4560000'", "TIMESTAMP '2018-10-28 01:33:17.4560000'").addRoundTrip("TIMESTAMP '2018-10-28 03:33:33.3330000'", "TIMESTAMP '2018-10-28 03:33:33.3330000'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.0000000'", "TIMESTAMP '1970-01-01 00:00:00.0000000'").addRoundTrip("TIMESTAMP '1970-01-01 00:13:42.0000000'", "TIMESTAMP '1970-01-01 00:13:42.0000000'").addRoundTrip("TIMESTAMP '2018-04-01 02:13:55.1230000'", "TIMESTAMP '2018-04-01 02:13:55.1230000'").addRoundTrip("TIMESTAMP '2018-03-25 03:17:17.0000000'", "TIMESTAMP '2018-03-25 03:17:17.0000000'").addRoundTrip("TIMESTAMP '1986-01-01 00:13:07.0000000'", "TIMESTAMP '1986-01-01 00:13:07.0000000'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00'", "TIMESTAMP '1970-01-01 00:00:00'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.1'", "TIMESTAMP '1970-01-01 00:00:00.1'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.12'", "TIMESTAMP '1970-01-01 00:00:00.12'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.123'", "TIMESTAMP '1970-01-01 00:00:00.123'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.1234'", "TIMESTAMP '1970-01-01 00:00:00.1234'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.12345'", "TIMESTAMP '1970-01-01 00:00:00.12345'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.123456'", "TIMESTAMP '1970-01-01 00:00:00.123456'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.1234567'", "TIMESTAMP '1970-01-01 00:00:00.1234567'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.12345670'", "TIMESTAMP '1970-01-01 00:00:00.1234567'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.123456749999'", "TIMESTAMP '1970-01-01 00:00:00.1234567'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.12345675'", "TIMESTAMP '1970-01-01 00:00:00.1234568'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.12345679'", "TIMESTAMP '1970-01-01 00:00:00.1234568'").addRoundTrip("TIMESTAMP '1969-12-31 23:59:59.1230000'", "TIMESTAMP '1969-12-31 23:59:59.1230000'").addRoundTrip("TIMESTAMP '1969-12-31 23:59:59.1234567'", "TIMESTAMP '1969-12-31 23:59:59.1234567'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00'", "TIMESTAMP '1970-01-01 00:00:00'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.1'", "TIMESTAMP '1970-01-01 00:00:00.1'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.9'", "TIMESTAMP '1970-01-01 00:00:00.9'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.123'", "TIMESTAMP '1970-01-01 00:00:00.123'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.123000'", "TIMESTAMP '1970-01-01 00:00:00.123000'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.999'", "TIMESTAMP '1970-01-01 00:00:00.999'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.1234567'", "TIMESTAMP '1970-01-01 00:00:00.1234567'").addRoundTrip("TIMESTAMP '2020-09-27 12:34:56.1'", "TIMESTAMP '2020-09-27 12:34:56.1'").addRoundTrip("TIMESTAMP '2020-09-27 12:34:56.9'", "TIMESTAMP '2020-09-27 12:34:56.9'").addRoundTrip("TIMESTAMP '2020-09-27 12:34:56.123'", "TIMESTAMP '2020-09-27 12:34:56.123'").addRoundTrip("TIMESTAMP '2020-09-27 12:34:56.123000'", "TIMESTAMP '2020-09-27 12:34:56.123000'").addRoundTrip("TIMESTAMP '2020-09-27 12:34:56.999'", "TIMESTAMP '2020-09-27 12:34:56.999'").addRoundTrip("TIMESTAMP '2020-09-27 12:34:56.1234567'", "TIMESTAMP '2020-09-27 12:34:56.1234567'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.12345671'", "TIMESTAMP '1970-01-01 00:00:00.1234567'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.1234567499'", "TIMESTAMP '1970-01-01 00:00:00.1234567'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.123456749999'", "TIMESTAMP '1970-01-01 00:00:00.1234567'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.12345675'", "TIMESTAMP '1970-01-01 00:00:00.1234568'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.111222333444'", "TIMESTAMP '1970-01-01 00:00:00.1112223'").addRoundTrip("TIMESTAMP '1970-01-01 00:00:00.99999995'", "TIMESTAMP '1970-01-01 00:00:01.0000000'").addRoundTrip("TIMESTAMP '1970-01-01 23:59:59.99999995'", "TIMESTAMP '1970-01-02 00:00:00.0000000'").addRoundTrip("TIMESTAMP '1969-12-31 23:59:59.99999995'", "TIMESTAMP '1970-01-01 00:00:00.0000000'").addRoundTrip("TIMESTAMP '1969-12-31 23:59:59.999999949999'", "TIMESTAMP '1969-12-31 23:59:59.9999999'").addRoundTrip("TIMESTAMP '1969-12-31 23:59:59.99999994'", "TIMESTAMP '1969-12-31 23:59:59.9999999'");
    Session session = Session.builder(getSession()).setTimeZoneKey(TimeZoneKey.getTimeZoneKey(sessionZone.getId())).build();
    tests.execute(getQueryRunner(), session, trinoCreateAsSelect(session, "test_timestamp"));
    tests.execute(getQueryRunner(), session, trinoCreateAsSelect("test_timestamp"));
    tests.execute(getQueryRunner(), session, trinoCreateAndInsert(session, "test_timestamp"));
}
Also used : SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest) TestingSession(io.trino.testing.TestingSession) Session(io.trino.Session) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 5 with SqlDataTypeTest

use of io.trino.testing.datatype.SqlDataTypeTest in project trino by trinodb.

the class BaseSqlServerTypeMapping method testDate.

@Test
public void testDate() {
    ZoneId jvmZone = ZoneId.systemDefault();
    checkState(jvmZone.getId().equals("America/Bahia_Banderas"), "This test assumes certain JVM time zone");
    LocalDate dateOfLocalTimeChangeForwardAtMidnightInJvmZone = LocalDate.of(1970, 1, 1);
    checkIsGap(jvmZone, dateOfLocalTimeChangeForwardAtMidnightInJvmZone.atStartOfDay());
    ZoneId someZone = ZoneId.of("Europe/Vilnius");
    LocalDate dateOfLocalTimeChangeForwardAtMidnightInSomeZone = LocalDate.of(1983, 4, 1);
    checkIsGap(someZone, dateOfLocalTimeChangeForwardAtMidnightInSomeZone.atStartOfDay());
    LocalDate dateOfLocalTimeChangeBackwardAtMidnightInSomeZone = LocalDate.of(1983, 10, 1);
    checkIsDoubled(someZone, dateOfLocalTimeChangeBackwardAtMidnightInSomeZone.atStartOfDay().minusMinutes(1));
    // BC dates not supported by SQL Server
    SqlDataTypeTest testsSqlServer = SqlDataTypeTest.create().addRoundTrip("date", "NULL", DATE, "CAST(NULL AS DATE)").addRoundTrip("date", "'0001-01-01'", DATE, "DATE '0001-01-01'").addRoundTrip("date", "'0012-12-12'", DATE, "DATE '0012-12-12'").addRoundTrip("date", "'1500-01-01'", DATE, "DATE '1500-01-01'").addRoundTrip("date", "'1952-04-03'", DATE, "DATE '1952-04-03'").addRoundTrip("date", "'1970-01-01'", DATE, "DATE '1970-01-01'").addRoundTrip("date", "'1970-02-03'", DATE, "DATE '1970-02-03'").addRoundTrip("date", "'2017-07-01'", DATE, "DATE '2017-07-01'").addRoundTrip("date", "'2017-01-01'", DATE, "DATE '2017-01-01'").addRoundTrip("date", "'1970-01-01'", DATE, "DATE '1970-01-01'").addRoundTrip("date", "'1983-04-01'", DATE, "DATE '1983-04-01'").addRoundTrip("date", "'1983-10-01'", DATE, "DATE '1983-10-01'");
    SqlDataTypeTest testsTrino = SqlDataTypeTest.create().addRoundTrip("date", "NULL", DATE, "CAST(NULL AS DATE)").addRoundTrip("date", "DATE '0001-01-01'", DATE, "DATE '0001-01-01'").addRoundTrip("date", "DATE '0012-12-12'", DATE, "DATE '0012-12-12'").addRoundTrip("date", "DATE '1500-01-01'", DATE, "DATE '1500-01-01'").addRoundTrip("date", "DATE '1952-04-03'", DATE, "DATE '1952-04-03'").addRoundTrip("date", "DATE '1970-01-01'", DATE, "DATE '1970-01-01'").addRoundTrip("date", "DATE '1970-02-03'", DATE, "DATE '1970-02-03'").addRoundTrip("date", "DATE '2017-07-01'", DATE, "DATE '2017-07-01'").addRoundTrip("date", "DATE '2017-01-01'", DATE, "DATE '2017-01-01'").addRoundTrip("date", "DATE '1970-01-01'", DATE, "DATE '1970-01-01'").addRoundTrip("date", "DATE '1983-04-01'", DATE, "DATE '1983-04-01'").addRoundTrip("date", "DATE '1983-10-01'", DATE, "DATE '1983-10-01'");
    for (String timeZoneId : ImmutableList.of(UTC_KEY.getId(), jvmZone.getId(), someZone.getId())) {
        Session session = Session.builder(getSession()).setTimeZoneKey(TimeZoneKey.getTimeZoneKey(timeZoneId)).build();
        testsSqlServer.execute(getQueryRunner(), session, sqlServerCreateAndInsert("test_date"));
        testsTrino.execute(getQueryRunner(), session, trinoCreateAsSelect(session, "test_date"));
        testsTrino.execute(getQueryRunner(), session, trinoCreateAndInsert(session, "test_date"));
    }
}
Also used : SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest) ZoneId(java.time.ZoneId) LocalDate(java.time.LocalDate) TestingSession(io.trino.testing.TestingSession) Session(io.trino.Session) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Aggregations

SqlDataTypeTest (io.trino.testing.datatype.SqlDataTypeTest)8 Test (org.testng.annotations.Test)8 Session (io.trino.Session)4 TestingSession (io.trino.testing.TestingSession)4 DataTypeTest (io.trino.testing.datatype.DataTypeTest)4 TestTable (io.trino.testing.sql.TestTable)2 LocalDate (java.time.LocalDate)2 ZoneId (java.time.ZoneId)2 ArrayType (io.trino.spi.type.ArrayType)1 BigDecimal (java.math.BigDecimal)1