use of com.facebook.presto.common.type.SqlTimeWithTimeZone in project presto by prestodb.
the class TestTimestampWithTimeZoneBase method testCastToTimeWithTimeZone.
@Test
public void testCastToTimeWithTimeZone() {
assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as time with time zone)", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
functionAssertions.assertFunctionString("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as time with time zone)", TIME_WITH_TIME_ZONE, "03:04:05.321 +07:09");
}
use of com.facebook.presto.common.type.SqlTimeWithTimeZone in project presto by prestodb.
the class MaterializedResult method convertToTestTypes.
private static MaterializedRow convertToTestTypes(MaterializedRow prestoRow) {
List<Object> convertedValues = new ArrayList<>();
for (int field = 0; field < prestoRow.getFieldCount(); field++) {
Object prestoValue = prestoRow.getField(field);
Object convertedValue;
if (prestoValue instanceof SqlDate) {
convertedValue = LocalDate.ofEpochDay(((SqlDate) prestoValue).getDays());
} else if (prestoValue instanceof SqlTime) {
convertedValue = DateTimeFormatter.ISO_LOCAL_TIME.parse(prestoValue.toString(), LocalTime::from);
} else if (prestoValue instanceof SqlTimeWithTimeZone) {
// Political timezone cannot be represented in OffsetTime and there isn't any better representation.
long millisUtc = ((SqlTimeWithTimeZone) prestoValue).getMillisUtc();
ZoneOffset zone = toZoneOffset(((SqlTimeWithTimeZone) prestoValue).getTimeZoneKey());
convertedValue = OffsetTime.of(LocalTime.ofNanoOfDay(MILLISECONDS.toNanos(millisUtc) + SECONDS.toNanos(zone.getTotalSeconds())), zone);
} else if (prestoValue instanceof SqlTimestamp) {
convertedValue = SqlTimestamp.JSON_FORMATTER.parse(prestoValue.toString(), LocalDateTime::from);
} else if (prestoValue instanceof SqlTimestampWithTimeZone) {
convertedValue = Instant.ofEpochMilli(((SqlTimestampWithTimeZone) prestoValue).getMillisUtc()).atZone(ZoneId.of(((SqlTimestampWithTimeZone) prestoValue).getTimeZoneKey().getId()));
} else if (prestoValue instanceof SqlDecimal) {
convertedValue = ((SqlDecimal) prestoValue).toBigDecimal();
} else {
convertedValue = prestoValue;
}
convertedValues.add(convertedValue);
}
return new MaterializedRow(prestoRow.getPrecision(), convertedValues);
}
use of com.facebook.presto.common.type.SqlTimeWithTimeZone in project presto by prestodb.
the class TestTimeBase method testCastToTimeWithTimeZoneWithTZWithRulesChanged.
@Test
public void testCastToTimeWithTimeZoneWithTZWithRulesChanged() {
TimeZoneKey timeZoneThatChangedSince1970 = getTimeZoneKey("Asia/Kathmandu");
DateTimeZone dateTimeZoneThatChangedSince1970 = getDateTimeZone(timeZoneThatChangedSince1970);
Session session = Session.builder(this.session).setTimeZoneKey(timeZoneThatChangedSince1970).build();
try (FunctionAssertions localAssertions = new FunctionAssertions(session)) {
localAssertions.assertFunction("cast(TIME '03:04:05.321' as time with time zone)", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, dateTimeZoneThatChangedSince1970).getMillis(), TimeZone.getTimeZone(ZoneId.of(dateTimeZoneThatChangedSince1970.getID()))));
}
}
use of com.facebook.presto.common.type.SqlTimeWithTimeZone in project presto by prestodb.
the class TestDateTimeOperatorsLegacy method testTimeWithTimeZoneRepresentation.
@Test
public void testTimeWithTimeZoneRepresentation() {
// PST -> PDT date
testTimeRepresentationOnDate(new DateTime(2017, 3, 12, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '02:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(37800000, getTimeZoneKey("America/Los_Angeles")));
testTimeRepresentationOnDate(new DateTime(2017, 3, 12, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '03:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(41400000, getTimeZoneKey("America/Los_Angeles")));
// PDT -> PST date
testTimeRepresentationOnDate(new DateTime(2017, 10, 4, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '02:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(37800000, getTimeZoneKey("America/Los_Angeles")));
testTimeRepresentationOnDate(new DateTime(2017, 10, 4, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '03:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(41400000, getTimeZoneKey("America/Los_Angeles")));
// PDT date
testTimeRepresentationOnDate(new DateTime(2017, 6, 6, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '02:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(37800000, getTimeZoneKey("America/Los_Angeles")));
testTimeRepresentationOnDate(new DateTime(2017, 6, 6, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '03:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(41400000, getTimeZoneKey("America/Los_Angeles")));
// PST date
testTimeRepresentationOnDate(new DateTime(2017, 11, 1, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '02:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(37800000, getTimeZoneKey("America/Los_Angeles")));
testTimeRepresentationOnDate(new DateTime(2017, 11, 1, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '03:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(41400000, getTimeZoneKey("America/Los_Angeles")));
}
use of com.facebook.presto.common.type.SqlTimeWithTimeZone in project presto by prestodb.
the class TestDateTimeOperatorsBase method testTimeMinusInterval.
@Test
public void testTimeMinusInterval() {
assertFunction("TIME '03:04:05.321' - INTERVAL '3' hour", TIME, sqlTimeOf(0, 4, 5, 321, session));
assertFunction("TIME '03:04:05.321' - INTERVAL '3' day", TIME, sqlTimeOf(3, 4, 5, 321, session));
assertFunction("TIME '03:04:05.321' - INTERVAL '3' month", TIME, sqlTimeOf(3, 4, 5, 321, session));
assertFunction("TIME '03:04:05.321' - INTERVAL '3' year", TIME, sqlTimeOf(3, 4, 5, 321, session));
assertFunction("TIME '03:04:05.321' - INTERVAL '6' hour", TIME, sqlTimeOf(21, 4, 5, 321, session));
assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '3' hour", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 0, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '3' day", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '3' month", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '3' year", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '6' hour", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 21, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
}
Aggregations