@ScalarOperator(CAST) @SqlType(StandardTypes.TIMESTAMP) public static long castToTimestamp(ConnectorSession session, @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long value) { if (session.isLegacyTimestamp()) { return unpackMillisUtc(value); } else { // This is hack that we need to use as the timezone interpretation depends on date (not only on time) // TODO remove REFERENCE_TIMESTAMP_UTC when removing support for political time zones in TIME WIT TIME ZONE long currentMillisOfDay = ChronoField.MILLI_OF_DAY.getFrom(Instant.ofEpochMilli(REFERENCE_TIMESTAMP_UTC).atZone(ZoneOffset.UTC)); long timeMillisUtcInCurrentDay = REFERENCE_TIMESTAMP_UTC - currentMillisOfDay + unpackMillisUtc(value); ISOChronology chronology = getChronology(unpackZoneKey(value)); return unpackMillisUtc(value) + chronology.getZone().getOffset(timeMillisUtcInCurrentDay); } }
private static TemporalQuery<Consumer<FieldResult>> temporalQuery(final ChronoField field) { return temporal -> result -> { if (field.isSupportedBy(temporal)) { String key = field.getBaseUnit().toString().toLowerCase(); long value = field.getFrom(temporal); switch (field) { case YEAR: result.years = value;break; case MONTH_OF_YEAR: result.months = value;break; case DAY_OF_WEEK: result.weekdays = value; key = "weekdays"; break; case DAY_OF_MONTH: result.days = value;break; case HOUR_OF_DAY: result.hours = value;break; case MINUTE_OF_HOUR: result.minutes = value;break; case SECOND_OF_MINUTE: result.seconds = value;break; } result.value.put(key, value); } }; } }
@ScalarOperator(CAST) @SqlType(StandardTypes.TIMESTAMP) public static long castToTimestamp(ConnectorSession session, @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long value) { if (session.isLegacyTimestamp()) { return unpackMillisUtc(value); } else { // This is hack that we need to use as the timezone interpretation depends on date (not only on time) // TODO remove REFERENCE_TIMESTAMP_UTC when removing support for political time zones in TIME WIT TIME ZONE long currentMillisOfDay = ChronoField.MILLI_OF_DAY.getFrom(Instant.ofEpochMilli(REFERENCE_TIMESTAMP_UTC).atZone(ZoneOffset.UTC)); long timeMillisUtcInCurrentDay = REFERENCE_TIMESTAMP_UTC - currentMillisOfDay + unpackMillisUtc(value); ISOChronology chronology = getChronology(unpackZoneKey(value)); return unpackMillisUtc(value) + chronology.getZone().getOffset(timeMillisUtcInCurrentDay); } }
@ScalarOperator(CAST) @SqlType(StandardTypes.TIMESTAMP) public static long castToTimestamp(ConnectorSession session, @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long value) { if (session.isLegacyTimestamp()) { return unpackMillisUtc(value); } else { // This is hack that we need to use as the timezone interpretation depends on date (not only on time) // TODO remove REFERENCE_TIMESTAMP_UTC when removing support for political time zones in TIME WIT TIME ZONE long currentMillisOfDay = ChronoField.MILLI_OF_DAY.getFrom(Instant.ofEpochMilli(REFERENCE_TIMESTAMP_UTC).atZone(ZoneOffset.UTC)); long timeMillisUtcInCurrentDay = REFERENCE_TIMESTAMP_UTC - currentMillisOfDay + unpackMillisUtc(value); ISOChronology chronology = getChronology(unpackZoneKey(value)); return unpackMillisUtc(value) + chronology.getZone().getOffset(timeMillisUtcInCurrentDay); } }