@ScalarOperator(ADD) @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long timestampWithTimeZonePlusIntervalDayToSecond(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long left, @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long right) { return updateMillisUtc(unpackMillisUtc(left) + right, left); }
private static long timeAtTimeZone(ConnectorSession session, long timeWithTimeZone, TimeZoneKey timeZoneKey) { DateTimeZone sourceTimeZone = getDateTimeZone(unpackZoneKey(timeWithTimeZone)); DateTimeZone targetTimeZone = getDateTimeZone(timeZoneKey); long millis = unpackMillisUtc(timeWithTimeZone); // STEP 1. Calculate source UTC millis in session start millis += valueToSessionTimeZoneOffsetDiff(session.getStartTime(), sourceTimeZone); // STEP 2. Calculate target UTC millis in 1970 millis -= valueToSessionTimeZoneOffsetDiff(session.getStartTime(), targetTimeZone); // STEP 3. Make sure that value + offset is in 0 - 23:59:59.999 long localMillis = millis + targetTimeZone.getOffset(0); // Loops up to 2 times in total while (localMillis > TimeUnit.DAYS.toMillis(1)) { millis -= TimeUnit.DAYS.toMillis(1); localMillis -= TimeUnit.DAYS.toMillis(1); } while (localMillis < 0) { millis += TimeUnit.DAYS.toMillis(1); localMillis += TimeUnit.DAYS.toMillis(1); } return packDateTimeWithZone(millis, timeZoneKey); }
public static long updateMillisUtc(long newMillsUtc, long dateTimeWithTimeZone) { return pack(newMillsUtc, (short) (dateTimeWithTimeZone & TIME_ZONE_MASK)); } }
public SqlTimeWithTimeZone(long timeWithTimeZone) { millisUtc = unpackMillisUtc(timeWithTimeZone); timeZoneKey = unpackZoneKey(timeWithTimeZone); }
@Override protected Object getGreaterValue(Object value) { // time zone doesn't matter for ordering return packDateTimeWithZone(unpackMillisUtc((Long) value) + 10, getTimeZoneKeyForOffset(33)); } }
@ScalarOperator(LESS_THAN) @SqlType(StandardTypes.BOOLEAN) public static boolean lessThan(@SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long left, @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long right) { return unpackMillisUtc(left) < unpackMillisUtc(right); }
public static long packDateTimeWithZone(long millisUtc, String zoneId) { return packDateTimeWithZone(millisUtc, getTimeZoneKey(zoneId)); }
public static ISOChronology unpackChronology(long timestampWithTimeZone) { return getChronology(unpackZoneKey(timestampWithTimeZone)); }
@ScalarOperator(GREATER_THAN) @SqlType(StandardTypes.BOOLEAN) public static boolean greaterThan(@SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long left, @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long right) { return unpackMillisUtc(left) > unpackMillisUtc(right); }
@Override protected Object getGreaterValue(Object value) { // time zone doesn't matter for ordering return packDateTimeWithZone(unpackMillisUtc((Long) value) + 10, getTimeZoneKeyForOffset(33)); } }
public SqlTimestampWithTimeZone(long timestampWithTimeZone) { millisUtc = unpackMillisUtc(timestampWithTimeZone); timeZoneKey = unpackZoneKey(timestampWithTimeZone); }
public static long packDateTimeWithZone(long millisUtc, int offsetMinutes) { return packDateTimeWithZone(millisUtc, getTimeZoneKeyForOffset(offsetMinutes)); }
public static ISOChronology unpackChronology(long timestampWithTimeZone) { return getChronology(unpackZoneKey(timestampWithTimeZone)); }
@ScalarOperator(SUBTRACT) @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long timestampWithTimeZoneMinusIntervalDayToSecond(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long left, @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long right) { return updateMillisUtc(unpackMillisUtc(left) - right, left); }
@ScalarOperator(LESS_THAN_OR_EQUAL) @SqlType(StandardTypes.BOOLEAN) public static boolean lessThanOrEqual(@SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long left, @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long right) { return unpackMillisUtc(left) <= unpackMillisUtc(right); }
private static long timeAtTimeZone(ConnectorSession session, long timeWithTimeZone, TimeZoneKey timeZoneKey) { DateTimeZone sourceTimeZone = getDateTimeZone(unpackZoneKey(timeWithTimeZone)); DateTimeZone targetTimeZone = getDateTimeZone(timeZoneKey); long millis = unpackMillisUtc(timeWithTimeZone); // STEP 1. Calculate source UTC millis in session start millis += valueToSessionTimeZoneOffsetDiff(session.getStartTime(), sourceTimeZone); // STEP 2. Calculate target UTC millis in 1970 millis -= valueToSessionTimeZoneOffsetDiff(session.getStartTime(), targetTimeZone); // STEP 3. Make sure that value + offset is in 0 - 23:59:59.999 long localMillis = millis + targetTimeZone.getOffset(0); // Loops up to 2 times in total while (localMillis > TimeUnit.DAYS.toMillis(1)) { millis -= TimeUnit.DAYS.toMillis(1); localMillis -= TimeUnit.DAYS.toMillis(1); } while (localMillis < 0) { millis += TimeUnit.DAYS.toMillis(1); localMillis += TimeUnit.DAYS.toMillis(1); } return packDateTimeWithZone(millis, timeZoneKey); }
@Override protected Object getGreaterValue(Object value) { // time zone doesn't matter for ordering return packDateTimeWithZone(unpackMillisUtc((Long) value) + 10, getTimeZoneKeyForOffset(33)); } }
@ScalarOperator(CAST) @SqlType(StandardTypes.TIMESTAMP) public static long castToTimestamp(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long value) { if (session.isLegacyTimestamp()) { return unpackMillisUtc(value); } else { ISOChronology chronology = getChronology(unpackZoneKey(value)); return chronology.getZone().convertUTCToLocal(unpackMillisUtc(value)); } }
public static long packDateTimeWithZone(DateTime dateTime) { return DateTimeEncoding.packDateTimeWithZone(dateTime.getMillis(), dateTime.getZone().getID()); }
public static DateTimeZone unpackDateTimeZone(long dateTimeWithTimeZone) { return getDateTimeZone(unpackZoneKey(dateTimeWithTimeZone)); }