use of com.facebook.presto.tests.datatype.DataTypeTest in project presto by prestodb.
the class TestMySqlTypeMapping method testDate.
@Test
public void testDate() {
// Note: there is identical test for PostgreSQL
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);
verify(jvmZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInJvmZone.atStartOfDay()).isEmpty());
ZoneId someZone = ZoneId.of("Europe/Vilnius");
LocalDate dateOfLocalTimeChangeForwardAtMidnightInSomeZone = LocalDate.of(1983, 4, 1);
verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInSomeZone.atStartOfDay()).isEmpty());
LocalDate dateOfLocalTimeChangeBackwardAtMidnightInSomeZone = LocalDate.of(1983, 10, 1);
verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeBackwardAtMidnightInSomeZone.atStartOfDay().minusMinutes(1)).size() == 2);
DataTypeTest testCases = DataTypeTest.create().addRoundTrip(dateDataType(), // before epoch
LocalDate.of(1952, 4, 3)).addRoundTrip(dateDataType(), LocalDate.of(1970, 1, 1)).addRoundTrip(dateDataType(), LocalDate.of(1970, 2, 3)).addRoundTrip(dateDataType(), // summer on northern hemisphere (possible DST)
LocalDate.of(2017, 7, 1)).addRoundTrip(dateDataType(), // winter on northern hemisphere (possible DST on southern hemisphere)
LocalDate.of(2017, 1, 1)).addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInJvmZone).addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInSomeZone).addRoundTrip(dateDataType(), dateOfLocalTimeChangeBackwardAtMidnightInSomeZone);
for (String timeZoneId : ImmutableList.of(UTC_KEY.getId(), jvmZone.getId(), someZone.getId())) {
Session session = Session.builder(getQueryRunner().getDefaultSession()).setTimeZoneKey(TimeZoneKey.getTimeZoneKey(timeZoneId)).build();
testCases.execute(getQueryRunner(), session, mysqlCreateAndInsert("tpch.test_date"));
testCases.execute(getQueryRunner(), session, prestoCreateAsSelect("test_date"));
}
}
use of com.facebook.presto.tests.datatype.DataTypeTest in project presto by prestodb.
the class TestPostgreSqlTypeMapping method testDate.
@Test
public void testDate() {
// Note: there is identical test for MySQL
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);
verify(jvmZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInJvmZone.atStartOfDay()).isEmpty());
ZoneId someZone = ZoneId.of("Europe/Vilnius");
LocalDate dateOfLocalTimeChangeForwardAtMidnightInSomeZone = LocalDate.of(1983, 4, 1);
verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInSomeZone.atStartOfDay()).isEmpty());
LocalDate dateOfLocalTimeChangeBackwardAtMidnightInSomeZone = LocalDate.of(1983, 10, 1);
verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeBackwardAtMidnightInSomeZone.atStartOfDay().minusMinutes(1)).size() == 2);
DataTypeTest testCases = DataTypeTest.create().addRoundTrip(dateDataType(), // before epoch
LocalDate.of(1952, 4, 3)).addRoundTrip(dateDataType(), LocalDate.of(1970, 1, 1)).addRoundTrip(dateDataType(), LocalDate.of(1970, 2, 3)).addRoundTrip(dateDataType(), // summer on northern hemisphere (possible DST)
LocalDate.of(2017, 7, 1)).addRoundTrip(dateDataType(), // winter on northern hemisphere (possible DST on southern hemisphere)
LocalDate.of(2017, 1, 1)).addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInJvmZone).addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInSomeZone).addRoundTrip(dateDataType(), dateOfLocalTimeChangeBackwardAtMidnightInSomeZone);
for (String timeZoneId : ImmutableList.of(UTC_KEY.getId(), jvmZone.getId(), someZone.getId())) {
Session session = Session.builder(getQueryRunner().getDefaultSession()).setTimeZoneKey(TimeZoneKey.getTimeZoneKey(timeZoneId)).build();
testCases.execute(getQueryRunner(), session, postgresCreateAndInsert("tpch.test_date"));
testCases.execute(getQueryRunner(), session, prestoCreateAsSelect("test_date"));
}
}
Aggregations