Search in sources :

Example 1 with DataTypeTest

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

the class TestPostgreSqlTypeMapping method testArrayTimestampWithTimeZone.

@Test(dataProvider = "trueFalse", dataProviderClass = DataProviders.class)
public void testArrayTimestampWithTimeZone(boolean insertWithTrino) {
    DataTypeTest tests = DataTypeTest.create();
    for (int precision : List.of(3, 6)) {
        // test all standard cases with precision 3 and 6 to make sure the long and short TIMESTAMP WITH TIME ZONE
        // is gap friendly.
        DataType<List<ZonedDateTime>> dataType = arrayOfTimestampWithTimeZoneDataType(precision, insertWithTrino);
        tests.addRoundTrip(dataType, asList(epoch.atZone(UTC), epoch.atZone(kathmandu)));
        tests.addRoundTrip(dataType, asList(beforeEpoch.atZone(kathmandu), beforeEpoch.atZone(UTC)));
        tests.addRoundTrip(dataType, asList(afterEpoch.atZone(UTC), afterEpoch.atZone(kathmandu)));
        tests.addRoundTrip(dataType, asList(timeDoubledInJvmZone.atZone(UTC)));
        tests.addRoundTrip(dataType, asList(timeDoubledInJvmZone.atZone(kathmandu)));
        tests.addRoundTrip(dataType, asList(timeDoubledInVilnius.atZone(UTC), timeDoubledInVilnius.atZone(vilnius), timeDoubledInVilnius.atZone(kathmandu)));
        tests.addRoundTrip(dataType, asList(timeGapInJvmZone1.atZone(UTC), timeGapInJvmZone1.atZone(kathmandu)));
        tests.addRoundTrip(dataType, asList(timeGapInJvmZone2.atZone(UTC), timeGapInJvmZone2.atZone(kathmandu)));
        tests.addRoundTrip(dataType, asList(timeGapInVilnius.atZone(kathmandu)));
        tests.addRoundTrip(dataType, asList(timeGapInKathmandu.atZone(vilnius)));
        if (!insertWithTrino) {
            // Postgres results with non-DST time (winter time) for timeDoubledInJvmZone.atZone(jvmZone) while Java results with DST time
            // When writing timestamptz arrays, Postgres JDBC driver converts java.sql.Timestamp to string representing date-time in JVM zone
            // TODO upgrade driver or find a different way to write timestamptz array elements as a point in time values with org.postgresql.jdbc.PgArray (https://github.com/pgjdbc/pgjdbc/issues/1225#issuecomment-516312324)
            tests.addRoundTrip(dataType, asList(timeDoubledInJvmZone.atZone(jvmZone)));
        }
    }
    // test arbitrary time for all supported precisions
    tests.addRoundTrip(arrayOfTimestampWithTimeZoneDataType(1, insertWithTrino), asList(ZonedDateTime.of(2012, 1, 2, 3, 4, 5, 100_000_000, kathmandu)));
    tests.addRoundTrip(arrayOfTimestampWithTimeZoneDataType(2, insertWithTrino), asList(ZonedDateTime.of(2012, 1, 2, 3, 4, 5, 120_000_000, kathmandu)));
    tests.addRoundTrip(arrayOfTimestampWithTimeZoneDataType(3, insertWithTrino), asList(ZonedDateTime.of(2012, 1, 2, 3, 4, 5, 123_000_000, kathmandu)));
    tests.addRoundTrip(arrayOfTimestampWithTimeZoneDataType(4, insertWithTrino), asList(ZonedDateTime.of(2012, 1, 2, 3, 4, 5, 123_400_000, kathmandu)));
    tests.addRoundTrip(arrayOfTimestampWithTimeZoneDataType(5, insertWithTrino), asList(ZonedDateTime.of(2012, 1, 2, 3, 4, 5, 123_450_000, kathmandu)));
    tests.addRoundTrip(arrayOfTimestampWithTimeZoneDataType(6, insertWithTrino), asList(ZonedDateTime.of(2012, 1, 2, 3, 4, 5, 123_456_000, kathmandu)));
    if (insertWithTrino) {
        tests.execute(getQueryRunner(), sessionWithArrayAsArray(), trinoCreateAsSelect(sessionWithArrayAsArray(), "test_array_timestamp_with_time_zone"));
        tests.execute(getQueryRunner(), sessionWithArrayAsArray(), trinoCreateAndInsert(sessionWithArrayAsArray(), "test_array_timestamp_with_time_zone"));
    } else {
        tests.execute(getQueryRunner(), sessionWithArrayAsArray(), postgresCreateAndInsert("test_array_timestamp_with_time_zone"));
    }
}
Also used : DataTypeTest(io.trino.testing.datatype.DataTypeTest) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) Test(org.testng.annotations.Test) DataTypeTest(io.trino.testing.datatype.DataTypeTest) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 2 with DataTypeTest

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

the class TestPostgreSqlTypeMapping method testTimestampWithTimeZone.

/**
 * @see #testTimestampWithTimeZoneCoercion
 */
@Test(dataProvider = "trueFalse", dataProviderClass = DataProviders.class)
public void testTimestampWithTimeZone(boolean insertWithTrino) {
    DataTypeTest tests = DataTypeTest.create(true);
    for (int precision : List.of(3, 6)) {
        // test all standard cases with precision 3 and 6 to make sure the long and short TIMESTAMP WITH TIME ZONE
        // is gap friendly.
        DataType<ZonedDateTime> dataType = timestampWithTimeZoneDataType(precision, insertWithTrino);
        tests.addRoundTrip(dataType, epoch.atZone(UTC));
        tests.addRoundTrip(dataType, epoch.atZone(kathmandu));
        tests.addRoundTrip(dataType, epoch.atZone(fixedOffsetEast));
        tests.addRoundTrip(dataType, epoch.atZone(fixedOffsetWest));
        tests.addRoundTrip(dataType, beforeEpoch.atZone(UTC));
        tests.addRoundTrip(dataType, beforeEpoch.atZone(kathmandu));
        tests.addRoundTrip(dataType, beforeEpoch.atZone(fixedOffsetEast));
        tests.addRoundTrip(dataType, beforeEpoch.atZone(fixedOffsetWest));
        tests.addRoundTrip(dataType, afterEpoch.atZone(UTC));
        tests.addRoundTrip(dataType, afterEpoch.atZone(kathmandu));
        tests.addRoundTrip(dataType, afterEpoch.atZone(fixedOffsetEast));
        tests.addRoundTrip(dataType, afterEpoch.atZone(fixedOffsetWest));
        tests.addRoundTrip(dataType, afterEpoch.atZone(ZoneId.of("GMT")));
        tests.addRoundTrip(dataType, afterEpoch.atZone(ZoneId.of("UTC")));
        tests.addRoundTrip(dataType, afterEpoch.atZone(ZoneId.of("UTC+00:00")));
        tests.addRoundTrip(dataType, timeDoubledInJvmZone.atZone(UTC));
        tests.addRoundTrip(dataType, timeDoubledInJvmZone.atZone(jvmZone));
        tests.addRoundTrip(dataType, timeDoubledInJvmZone.atZone(kathmandu));
        tests.addRoundTrip(dataType, timeDoubledInVilnius.atZone(UTC));
        tests.addRoundTrip(dataType, timeDoubledInVilnius.atZone(vilnius));
        tests.addRoundTrip(dataType, timeDoubledInVilnius.atZone(kathmandu));
        tests.addRoundTrip(dataType, timeGapInJvmZone1.atZone(UTC));
        tests.addRoundTrip(dataType, timeGapInJvmZone1.atZone(kathmandu));
        tests.addRoundTrip(dataType, timeGapInJvmZone2.atZone(UTC));
        tests.addRoundTrip(dataType, timeGapInJvmZone2.atZone(kathmandu));
        tests.addRoundTrip(dataType, timeGapInVilnius.atZone(kathmandu));
        tests.addRoundTrip(dataType, timeGapInKathmandu.atZone(vilnius));
    }
    // test arbitrary time for all supported precisions
    tests.addRoundTrip(timestampWithTimeZoneDataType(1, insertWithTrino), ZonedDateTime.of(2012, 1, 2, 3, 4, 5, 100_000_000, kathmandu));
    tests.addRoundTrip(timestampWithTimeZoneDataType(2, insertWithTrino), ZonedDateTime.of(2012, 1, 2, 3, 4, 5, 120_000_000, kathmandu));
    tests.addRoundTrip(timestampWithTimeZoneDataType(3, insertWithTrino), ZonedDateTime.of(2012, 1, 2, 3, 4, 5, 123_000_000, kathmandu));
    tests.addRoundTrip(timestampWithTimeZoneDataType(4, insertWithTrino), ZonedDateTime.of(2012, 1, 2, 3, 4, 5, 123_400_000, kathmandu));
    tests.addRoundTrip(timestampWithTimeZoneDataType(5, insertWithTrino), ZonedDateTime.of(2012, 1, 2, 3, 4, 5, 123_450_000, kathmandu));
    tests.addRoundTrip(timestampWithTimeZoneDataType(6, insertWithTrino), ZonedDateTime.of(2012, 1, 2, 3, 4, 5, 123_456_000, kathmandu));
    if (insertWithTrino) {
        tests.execute(getQueryRunner(), trinoCreateAsSelect("test_timestamp_with_time_zone"));
        tests.execute(getQueryRunner(), trinoCreateAndInsert("test_timestamp_with_time_zone"));
    } else {
        tests.execute(getQueryRunner(), postgresCreateAndInsert("test_timestamp_with_time_zone"));
    }
}
Also used : DataTypeTest(io.trino.testing.datatype.DataTypeTest) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest) ZonedDateTime(java.time.ZonedDateTime) Test(org.testng.annotations.Test) DataTypeTest(io.trino.testing.datatype.DataTypeTest) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 3 with DataTypeTest

use of io.trino.testing.datatype.DataTypeTest 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 DataTypeTest

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

the class TestPostgreSqlTypeMapping method testArrayMultidimensional.

@Test
public void testArrayMultidimensional() {
    // 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.
    // for multidimensional arrays, PostgreSQL requires subarrays to have the same dimensions, including nulls
    // e.g. [[1], [1, 2]] and [null, [1, 2]] are not allowed, but [[null, null], [1, 2]] is allowed
    DataTypeTest.create().addRoundTrip(arrayDataType(arrayDataType(booleanDataType())), asList(asList(null, null, null))).addRoundTrip(arrayDataType(arrayDataType(booleanDataType())), asList(asList(true, null), asList(null, null), asList(false, false))).addRoundTrip(arrayDataType(arrayDataType(integerDataType())), asList(asList(1, 2), asList(null, null), asList(3, 4))).addRoundTrip(arrayDataType(arrayDataType(decimalDataType(3, 0))), asList(asList(new BigDecimal("193")), asList(new BigDecimal("19")), asList(new BigDecimal("-193")))).execute(getQueryRunner(), sessionWithArrayAsArray(), trinoCreateAsSelect(sessionWithArrayAsArray(), "test_array_2d")).execute(getQueryRunner(), sessionWithArrayAsArray(), trinoCreateAndInsert(sessionWithArrayAsArray(), "test_array_2d"));
    DataTypeTest.create().addRoundTrip(arrayDataType(arrayDataType(arrayDataType(doubleDataType()))), asList(asList(asList(123.45d), asList(678.99d)), asList(asList(543.21d), asList(998.76d)), asList(asList(567.123d), asList(789.12d)))).addRoundTrip(arrayDataType(arrayDataType(arrayDataType(dateDataType()))), asList(asList(asList(LocalDate.of(1952, 4, 3), LocalDate.of(1970, 1, 1))), asList(asList(null, LocalDate.of(1970, 1, 1))), asList(asList(LocalDate.of(1970, 2, 3), LocalDate.of(2017, 7, 1))))).execute(getQueryRunner(), sessionWithArrayAsArray(), trinoCreateAsSelect(sessionWithArrayAsArray(), "test_array_3d")).execute(getQueryRunner(), sessionWithArrayAsArray(), trinoCreateAndInsert(sessionWithArrayAsArray(), "test_array_3d"));
}
Also used : BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test) DataTypeTest(io.trino.testing.datatype.DataTypeTest) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Aggregations

DataTypeTest (io.trino.testing.datatype.DataTypeTest)4 SqlDataTypeTest (io.trino.testing.datatype.SqlDataTypeTest)4 Test (org.testng.annotations.Test)4 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayType (io.trino.spi.type.ArrayType)1 BigDecimal (java.math.BigDecimal)1 ZonedDateTime (java.time.ZonedDateTime)1 Arrays.asList (java.util.Arrays.asList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1