/** * Parse a string containing a zone as a value of TIME WITH TIME ZONE type. * <p> * For example: {@code "01:23:00 +01:23"} is parsed to TIME WITH TIME ZONE * {@code 01:23:00+01:23} and {@code "01:23:00"} is rejected. * * @return stack representation of TIME WITH TIME ZONE type */ public static long parseTimeWithTimeZone(String timeWithTimeZone) { DateTime dateTime = TIME_WITH_TIME_ZONE_FORMATTER.parseDateTime(timeWithTimeZone); return packDateTimeWithZone(dateTime); }
/** * Parse a string (optionally containing a zone) as a value of either TIMESTAMP or TIMESTAMP WITH TIME ZONE type. * <p> * For example: {@code "2000-01-01 01:23:00"} is parsed to TIMESTAMP {@code 2000-01-01T01:23:00} * and {@code "2000-01-01 01:23:00 +01:23"} is parsed to TIMESTAMP WITH TIME ZONE * {@code 2000-01-01T01:23:00.000+01:23}. * * @return stack representation of TIMESTAMP or TIMESTAMP WITH TIME ZONE type, depending on input */ public static long parseTimestampLiteral(String value) { try { DateTime dateTime = TIMESTAMP_WITH_TIME_ZONE_FORMATTER.parseDateTime(value); return packDateTimeWithZone(dateTime); } catch (Exception e) { return TIMESTAMP_WITHOUT_TIME_ZONE_FORMATTER.parseMillis(value); } }
/** * Parse a string (optionally containing a zone) as a value of either TIMESTAMP or TIMESTAMP WITH TIME ZONE type. * If the string doesn't specify a zone, it is interpreted in {@code timeZoneKey} zone. * * @return stack representation of legacy TIMESTAMP or TIMESTAMP WITH TIME ZONE type, depending on input */ @Deprecated public static long parseTimestampLiteral(TimeZoneKey timeZoneKey, String value) { try { DateTime dateTime = TIMESTAMP_WITH_TIME_ZONE_FORMATTER.parseDateTime(value); return packDateTimeWithZone(dateTime); } catch (RuntimeException e) { return LEGACY_TIMESTAMP_WITHOUT_TIME_ZONE_FORMATTER.withChronology(getChronology(timeZoneKey)).parseMillis(value); } }
/** * Parse a string (optionally containing a zone) as a value of TIMESTAMP WITH TIME ZONE type. * If the string doesn't specify a zone, it is interpreted in {@code timeZoneKey} zone. * <p> * For example: {@code "2000-01-01 01:23:00"} is parsed to TIMESTAMP WITH TIME ZONE * {@code 2000-01-01T01:23:00 <provided zone>} and {@code "2000-01-01 01:23:00 +01:23"} * is parsed to TIMESTAMP WITH TIME ZONE {@code 2000-01-01T01:23:00.000+01:23}. * * @return stack representation of TIMESTAMP WITH TIME ZONE type */ public static long parseTimestampWithTimeZone(TimeZoneKey timeZoneKey, String timestampWithTimeZone) { DateTime dateTime = TIMESTAMP_WITH_OR_WITHOUT_TIME_ZONE_FORMATTER.withChronology(getChronology(timeZoneKey)).withOffsetParsed().parseDateTime(timestampWithTimeZone); return packDateTimeWithZone(dateTime); }
public static void assertTimeZone(String zoneId, DateTimeZone dateTimeZone) { long dateTimeWithTimeZone = packDateTimeWithZone(new DateTime(42, dateTimeZone)); assertEquals(packDateTimeWithZone((long) 42, dateTimeZone.toTimeZone().getID()), dateTimeWithTimeZone); DateTimeZone unpackedZone = unpackDateTimeZone(dateTimeWithTimeZone); assertDateTimeZoneEquals(zoneId, unpackedZone); }
@ScalarFunction("from_iso8601_timestamp") @LiteralParameters("x") @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long fromISO8601Timestamp(ConnectorSession session, @SqlType("varchar(x)") Slice iso8601DateTime) { DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser() .withChronology(getChronology(session.getTimeZoneKey())) .withOffsetParsed(); return packDateTimeWithZone(parseDateTimeHelper(formatter, iso8601DateTime.toStringUtf8())); }
@Description("parses the specified date/time by the given format") @ScalarFunction @LiteralParameters({"x", "y"}) @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long parseDatetime(ConnectorSession session, @SqlType("varchar(x)") Slice datetime, @SqlType("varchar(y)") Slice formatString) { try { return packDateTimeWithZone(parseDateTimeHelper( DateTimeFormat.forPattern(formatString.toStringUtf8()) .withChronology(getChronology(session.getTimeZoneKey())) .withOffsetParsed() .withLocale(session.getLocale()), datetime.toStringUtf8())); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e); } }
public static long parseTimeWithTimeZone(String timeWithTimeZone) { DateTime dateTime = TIME_WITH_TIME_ZONE_FORMATTER.parseDateTime(timeWithTimeZone); return packDateTimeWithZone(dateTime); }
public static long parseTimestampLiteral(TimeZoneKey timeZoneKey, String value) { try { DateTime dateTime = TIMESTAMP_WITH_TIME_ZONE_FORMATTER.parseDateTime(value); return packDateTimeWithZone(dateTime); } catch (Exception e) { return TIMESTAMP_WITHOUT_TIME_ZONE_FORMATTER.withChronology(getChronology(timeZoneKey)).parseMillis(value); } }
public static long parseTimestampWithTimeZone(TimeZoneKey timeZoneKey, String timestampWithTimeZone) { DateTime dateTime = TIMESTAMP_WITH_OR_WITHOUT_TIME_ZONE_FORMATTER.withChronology(getChronology(timeZoneKey)).withOffsetParsed().parseDateTime(timestampWithTimeZone); return packDateTimeWithZone(dateTime); }
public static void assertTimeZone(String zoneId, DateTimeZone dateTimeZone) { long dateTimeWithTimeZone = packDateTimeWithZone(new DateTime(42, dateTimeZone)); assertEquals(packDateTimeWithZone((long) 42, dateTimeZone.toTimeZone().getID()), dateTimeWithTimeZone); DateTimeZone unpackedZone = unpackDateTimeZone(dateTimeWithTimeZone); assertDateTimeZoneEquals(zoneId, unpackedZone); }
@ScalarFunction("from_iso8601_timestamp") @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long fromISO8601Timestamp(ConnectorSession session, @SqlType(StandardTypes.VARCHAR) Slice iso8601DateTime) { DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser() .withChronology(getChronology(session.getTimeZoneKey())) .withOffsetParsed(); return packDateTimeWithZone(parseDateTimeHelper(formatter, iso8601DateTime.toStringUtf8())); }
@Description("parses the specified date/time by the given format") @ScalarFunction @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long parseDatetime(ConnectorSession session, @SqlType(StandardTypes.VARCHAR) Slice datetime, @SqlType(StandardTypes.VARCHAR) Slice formatString) { try { return packDateTimeWithZone(parseDateTimeHelper(DateTimeFormat.forPattern(formatString.toStringUtf8()) .withChronology(getChronology(session.getTimeZoneKey())) .withOffsetParsed() .withLocale(session.getLocale()), datetime.toStringUtf8())); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e); } }