private static ZoneOffset toZoneOffset(TimeZoneKey timeZoneKey) { requireNonNull(timeZoneKey, "timeZoneKey is null"); if (Objects.equals("UTC", timeZoneKey.getId())) { return ZoneOffset.UTC; } checkArgument(timeZoneKey.getId().matches("[+-]\\d\\d:\\d\\d"), "Not a zone-offset timezone: %s", timeZoneKey); return ZoneOffset.of(timeZoneKey.getId()); }
private static ZoneOffset toZoneOffset(TimeZoneKey timeZoneKey) { requireNonNull(timeZoneKey, "timeZoneKey is null"); if (Objects.equals("UTC", timeZoneKey.getId())) { return ZoneOffset.UTC; } checkArgument(timeZoneKey.getId().matches("[+-]\\d\\d:\\d\\d"), "Not a zone-offset timezone: %s", timeZoneKey); return ZoneOffset.of(timeZoneKey.getId()); }
@JsonValue @Override public String toString() { return Instant.ofEpochMilli(millisUtc).atZone(ZoneId.of(timeZoneKey.getId())).format(formatter); } }
@JsonValue @Override public String toString() { return Instant.ofEpochMilli(millisUtc).atZone(ZoneId.of(timeZoneKey.getId())).format(formatter); } }
@JsonValue @Override public String toString() { if (isLegacyTimestamp()) { return Instant.ofEpochMilli(millis).atZone(ZoneId.of(sessionTimeZoneKey.get().getId())).format(formatter); } else { return Instant.ofEpochMilli(millis).atZone(ZoneOffset.UTC).format(formatter); } }
@Override public String getTimeZoneId() { return session.getTimeZoneKey().getId(); }
public static SqlTime sqlTimeOf(LocalTime time, Session session) { if (session.toConnectorSession().isLegacyTimestamp()) { long millisUtc = LocalDate.ofEpochDay(0) .atTime(time) .atZone(UTC) .withZoneSameLocal(ZoneId.of(session.getTimeZoneKey().getId())) .toInstant() .toEpochMilli(); return new SqlTime(millisUtc, session.getTimeZoneKey()); } return new SqlTime(NANOSECONDS.toMillis(time.toNanoOfDay())); }
public static SqlTime sqlTimeOf(LocalTime time, Session session) { if (session.toConnectorSession().isLegacyTimestamp()) { long millisUtc = LocalDate.ofEpochDay(0) .atTime(time) .atZone(UTC) .withZoneSameLocal(ZoneId.of(session.getTimeZoneKey().getId())) .toInstant() .toEpochMilli(); return new SqlTime(millisUtc, session.getTimeZoneKey()); } return new SqlTime(NANOSECONDS.toMillis(time.toNanoOfDay())); }
private static long epochDaysInZone(TimeZoneKey timeZoneKey, long instant) { return LocalDate.from(Instant.ofEpochMilli(instant).atZone(ZoneId.of(timeZoneKey.getId()))).toEpochDay(); }
private static long epochDaysInZone(TimeZoneKey timeZoneKey, long instant) { return LocalDate.from(Instant.ofEpochMilli(instant).atZone(ZoneId.of(timeZoneKey.getId()))).toEpochDay(); }
@Override public FormatWriter createFileFormatWriter( ConnectorSession session, File targetFile, List<String> columnNames, List<Type> columnTypes, HiveCompressionCodec compressionCodec) throws IOException { return new PrestoDwrfFormatWriter( targetFile, columnNames, columnTypes, DateTimeZone.forID(session.getTimeZoneKey().getId()), compressionCodec); }
@Description("current time zone") @ScalarFunction("current_timezone") @SqlType(StandardTypes.VARCHAR) public static Slice currentTimeZone(ConnectorSession session) { return utf8Slice(session.getTimeZoneKey().getId()); }
@Override public FormatWriter createFileFormatWriter( ConnectorSession session, File targetFile, List<String> columnNames, List<Type> columnTypes, HiveCompressionCodec compressionCodec) throws IOException { return new PrestoDwrfFormatWriter( targetFile, columnNames, columnTypes, DateTimeZone.forID(session.getTimeZoneKey().getId()), compressionCodec); }
@Description("current time zone") @ScalarFunction("current_timezone") @SqlType(StandardTypes.VARCHAR) public static Slice currentTimeZone(ConnectorSession session) { return utf8Slice(session.getTimeZoneKey().getId()); }
@Test public void testZoneKeyLookup() { for (TimeZoneKey timeZoneKey : TimeZoneKey.getTimeZoneKeys()) { assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getKey()), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId()), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId().toUpperCase(ENGLISH)), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId().toLowerCase(ENGLISH)), timeZoneKey); } }
@Test public void testZoneKeyLookup() { for (TimeZoneKey timeZoneKey : TimeZoneKey.getTimeZoneKeys()) { assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getKey()), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId()), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId().toUpperCase(ENGLISH)), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId().toLowerCase(ENGLISH)), timeZoneKey); } }
@Override public FormatWriter createFileFormatWriter( ConnectorSession session, File targetFile, List<String> columnNames, List<Type> columnTypes, HiveCompressionCodec compressionCodec) throws IOException { return new PrestoRcFileFormatWriter( targetFile, columnTypes, new TextRcFileEncoding(DateTimeZone.forID(session.getTimeZoneKey().getId())), compressionCodec); } },
@Test public void testTimeZone() { assertFunction("hour(" + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getHourOfDay()); assertFunction("minute(" + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getMinuteOfHour()); assertFunction("hour(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getHourOfDay()); assertFunction("minute(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getMinuteOfHour()); assertFunction("current_timezone()", VARCHAR, TIME_ZONE_KEY.getId()); }
@Test public void testTimeZone() { assertFunction("hour(" + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getHourOfDay()); assertFunction("minute(" + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getMinuteOfHour()); assertFunction("hour(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getHourOfDay()); assertFunction("minute(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getMinuteOfHour()); assertFunction("current_timezone()", VARCHAR, TIME_ZONE_KEY.getId()); }