Refine search
@ScalarOperator(ADD) @SqlType(StandardTypes.TIME) public static long intervalDayToSecondPlusTime(ConnectorSession session, @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long left, @SqlType(StandardTypes.TIME) long right) { return modulo24Hour(getChronology(session.getTimeZoneKey()), left + right); }
@ScalarFunction("to_iso8601") @SqlType("varchar(35)") // YYYY-MM-DDTHH:MM:SS.mmm+HH:MM is a standard notation, and it requires 29 characters. // However extended notation with format ±(Y)+-MM-DDTHH:MM:SS.mmm+HH:MM is also acceptable and as // the maximum year represented by 64bits timestamp is ~584944387 it may require up to 35 characters. public static Slice toISO8601FromTimestampWithTimeZone(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone) { long millisUtc = unpackMillisUtc(timestampWithTimeZone); DateTimeFormatter formatter = ISODateTimeFormat.dateTime() .withChronology(getChronology(unpackZoneKey(timestampWithTimeZone))); return utf8Slice(formatter.print(millisUtc)); }
@ScalarFunction("to_iso8601") @SqlType(StandardTypes.VARCHAR) public static Slice toISO8601FromTimestamp(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP) long timestamp) { DateTimeFormatter formatter = ISODateTimeFormat.dateTime() .withChronology(getChronology(session.getTimeZoneKey())); return utf8Slice(formatter.print(timestamp)); }
@ScalarOperator(ADD) @SqlType(StandardTypes.TIME) public static long timePlusIntervalDayToSecond(ConnectorSession session, @SqlType(StandardTypes.TIME) long left, @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long right) { return modulo24Hour(getChronology(session.getTimeZoneKey()), left + right); }
@ScalarOperator(CAST) @SqlType(StandardTypes.TIME) public static long castToTime(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP) long value) { return modulo24Hour(getChronology(session.getTimeZoneKey()), value); }
@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)); } }
@ScalarOperator(SUBTRACT) @SqlType(StandardTypes.TIME) public static long timeMinusIntervalDayToSecond(ConnectorSession session, @SqlType(StandardTypes.TIME) long left, @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long right) { return modulo24Hour(getChronology(session.getTimeZoneKey()), left - right); }
@ScalarOperator(CAST) @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) public static long castToTimeWithTimeZone(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP) long value) { int timeMillis = modulo24Hour(getChronology(session.getTimeZoneKey()), value); return packDateTimeWithZone(timeMillis, session.getTimeZoneKey()); }
@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_WITH_TIME_ZONE) public static long castToTimestampWithTimeZone(ConnectorSession session, @SqlType(StandardTypes.DATE) long value) { long utcMillis = TimeUnit.DAYS.toMillis(value); // date is encoded as milliseconds at midnight in UTC // convert to midnight in the session timezone ISOChronology chronology = getChronology(session.getTimeZoneKey()); long millis = utcMillis - chronology.getZone().getOffset(utcMillis); return packDateTimeWithZone(millis, session.getTimeZoneKey()); }
@ScalarOperator(CAST) @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long castToTimestampWithTimeZone(ConnectorSession session, @SqlType(StandardTypes.DATE) long value) { long utcMillis = TimeUnit.DAYS.toMillis(value); // date is encoded as milliseconds at midnight in UTC // convert to midnight if the session timezone ISOChronology chronology = getChronology(session.getTimeZoneKey()); long millis = utcMillis - chronology.getZone().getOffset(utcMillis); return packDateTimeWithZone(millis, session.getTimeZoneKey()); }
@ScalarOperator(CAST) @SqlType(StandardTypes.TIMESTAMP) public static long castToTimestamp(ConnectorSession session, @SqlType(StandardTypes.DATE) long value) { if (session.isLegacyTimestamp()) { long utcMillis = TimeUnit.DAYS.toMillis(value); // date is encoded as milliseconds at midnight in UTC // convert to midnight in the session timezone ISOChronology chronology = getChronology(session.getTimeZoneKey()); return utcMillis - chronology.getZone().getOffset(utcMillis); } else { return TimeUnit.DAYS.toMillis(value); } }
@ScalarOperator(CAST) @SqlType(StandardTypes.TIMESTAMP) public static long castToTimestamp(ConnectorSession session, @SqlType(StandardTypes.DATE) long value) { long utcMillis = TimeUnit.DAYS.toMillis(value); // date is encoded as milliseconds at midnight in UTC // convert to midnight if the session timezone ISOChronology chronology = getChronology(session.getTimeZoneKey()); return utcMillis - chronology.getZone().getOffset(utcMillis); }
@ScalarOperator(CAST) @SqlType(StandardTypes.TIME) public static long castToTime(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP) long value) { if (session.isLegacyTimestamp()) { return modulo24Hour(getChronology(session.getTimeZoneKey()), value); } else { return modulo24Hour(value); } }
@ScalarOperator(ADD) @SqlType(StandardTypes.TIME) public static long timePlusIntervalDayToSecond(ConnectorSession session, @SqlType(StandardTypes.TIME) long left, @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long right) { return modulo24Hour(getChronology(session.getTimeZoneKey()), left + right); }
@ScalarOperator(ADD) @SqlType(StandardTypes.TIMESTAMP) public static long intervalYearToMonthPlusTimestamp(ConnectorSession session, @SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long left, @SqlType(StandardTypes.TIMESTAMP) long right) { if (session.isLegacyTimestamp()) { return getChronology(session.getTimeZoneKey()).monthOfYear().add(right, left); } else { return MONTH_OF_YEAR_UTC.add(right, left); } }
@ScalarOperator(ADD) @SqlType(StandardTypes.TIME) public static long intervalDayToSecondPlusTime(ConnectorSession session, @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long left, @SqlType(StandardTypes.TIME) long right) { return modulo24Hour(getChronology(session.getTimeZoneKey()), left + right); }
@ScalarOperator(SUBTRACT) @SqlType(StandardTypes.TIMESTAMP) public static long timestampMinusIntervalYearToMonth(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP) long left, @SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long right) { if (session.isLegacyTimestamp()) { return getChronology(session.getTimeZoneKey()).monthOfYear().add(left, -right); } else { return MONTH_OF_YEAR_UTC.add(left, -right); } }
@ScalarOperator(SUBTRACT) @SqlType(StandardTypes.TIME) public static long timeMinusIntervalDayToSecond(ConnectorSession session, @SqlType(StandardTypes.TIME) long left, @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long right) { return modulo24Hour(getChronology(session.getTimeZoneKey()), left - right); }
@ScalarOperator(ADD) @SqlType(StandardTypes.TIMESTAMP) public static long timestampPlusIntervalYearToMonth(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP) long left, @SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long right) { if (session.isLegacyTimestamp()) { return getChronology(session.getTimeZoneKey()).monthOfYear().add(left, right); } else { return MONTH_OF_YEAR_UTC.add(left, right); } }