@Override ZoneId getZoneId( Supplier<ZoneId> defaultZone ) { return value.getZone(); }
@Override ZoneId getZoneId() { return value.getZone(); }
@JsonProperty public ZoneId getTimeZone() { return date.getZone(); }
private ZonedDateTime sameInstantInActualTimeZone(ZonedDateTime zonedDateTime) { if (zonedDateTime == null) return null; // nothing to convert in actual's TZ if (actual == null) return zonedDateTime; // no actual => let's keep zonedDateTime as it is. return zonedDateTime.withZoneSameInstant(actual.getZone()); }
@Override public Atop create(AtopTable table, ZonedDateTime date) { checkArgument(date.getZone().getRules().equals(timeZone.getRules()), "Split date (%s) is not in the local timezone (%s)", date.getZone(), timeZone); ProcessBuilder processBuilder = new ProcessBuilder(executablePath); processBuilder.command().add("-P"); processBuilder.command().add(table.getAtopLabel()); processBuilder.command().add("-r"); processBuilder.command().add(DATE_FORMATTER.format(date)); Process process; try { process = processBuilder.start(); } catch (IOException e) { throw new PrestoException(ATOP_CANNOT_START_PROCESS_ERROR, format("Cannot start %s", processBuilder.command()), e); } return new AtopProcess(process, readTimeout, executor); }
@Override protected DateTime evaluate(FunctionArgs args, EvaluationContext context, DateTimeZone timezone) { final Object datish = value.required(args, context); if (datish instanceof DateTime) { return (DateTime) datish; } if (datish instanceof Date) { return new DateTime(datish); } if (datish instanceof ZonedDateTime) { final ZonedDateTime zonedDateTime = (ZonedDateTime) datish; final DateTimeZone timeZone = DateTimeZone.forID(zonedDateTime.getZone().getId()); return new DateTime(zonedDateTime.toInstant().toEpochMilli(), timeZone); } return null; }
public void set(TimestampTZ tstz) { if (tstz == null) { timestampTZ.setZonedDateTime(null); return; } timestampTZ = tstz; timeZone = timestampTZ.getZonedDateTime().getZone(); bytesEmpty = true; timestampTZEmpty = false; }
public Clock at( ZonedDateTime datetime ) { return fixed( datetime.toInstant(), datetime.getZone() ); }
private DateTimeValue( ZonedDateTime value ) { ZoneId zone = value.getZone(); if ( zone instanceof ZoneOffset ) { this.value = value; } else { // Do a 2-way lookup of the zone to make sure we only use the new name of renamed zones ZoneId mappedZone = ZoneId.of( TimeZones.map( TimeZones.map( zone.getId() ) ) ); this.value = value.withZoneSameInstant( mappedZone ); } this.epochSeconds = this.value.toEpochSecond(); }
private static ZoneId timezone( TemporalValue<?,?> temporal ) { if ( temporal instanceof DateTimeValue ) { return ((DateTimeValue) temporal).temporal().getZone(); } if ( temporal instanceof TimeValue ) { return ((TimeValue) temporal).temporal().getOffset(); } return null; }
@Override public final void writeDateTime( ZonedDateTime zonedDateTime ) throws E { long epochSecondUTC = zonedDateTime.toEpochSecond(); int nano = zonedDateTime.getNano(); ZoneId zone = zonedDateTime.getZone(); if ( zone instanceof ZoneOffset ) { int offsetSeconds = ((ZoneOffset) zone).getTotalSeconds(); writeDateTime( epochSecondUTC, nano, offsetSeconds ); } else { String zoneId = zone.getId(); writeDateTime( epochSecondUTC, nano, zoneId ); } }
@Override public TimestampLocalTZWritable getPrimitiveWritableObject(Object o) { if (o == null) { return null; } TimestampLocalTZWritable t = (TimestampLocalTZWritable) o; TimestampLocalTZTypeInfo timestampTZTypeInfo = (TimestampLocalTZTypeInfo) typeInfo; if (!t.getTimestampTZ().getZonedDateTime().getZone().equals(timestampTZTypeInfo.timeZone())) { t.setTimeZone(timestampTZTypeInfo.timeZone()); } return t; }
@Override public void write(Kryo kryo, Output output, TimestampTZ object) { output.writeLong(object.getEpochSecond()); output.writeInt(object.getNanos()); output.writeString(object.getZonedDateTime().getZone().getId()); }
@Override public TimestampTZ getPrimitiveJavaObject(Object o) { if (o == null) { return null; } TimestampLocalTZWritable t = (TimestampLocalTZWritable) o; TimestampLocalTZTypeInfo timestampTZTypeInfo = (TimestampLocalTZTypeInfo) typeInfo; if (!t.getTimestampTZ().getZonedDateTime().getZone().equals(timestampTZTypeInfo.timeZone())) { t.setTimeZone(timestampTZTypeInfo.timeZone()); } return t.getTimestampTZ(); }
@Test public void testSerialization() { JsonCodec<AtopSplit> codec = JsonCodec.jsonCodec(AtopSplit.class); ZonedDateTime now = ZonedDateTime.now(ZoneId.of("+01:23")); AtopSplit split = new AtopSplit(AtopTable.DISKS, HostAddress.fromParts("localhost", 123), now.toEpochSecond(), now.getZone()); AtopSplit decoded = codec.fromJson(codec.toJson(split)); assertEquals(decoded.getTable(), split.getTable()); assertEquals(decoded.getHost(), split.getHost()); assertEquals(decoded.getDate(), split.getDate()); assertEquals(decoded.getEpochSeconds(), split.getEpochSeconds()); assertEquals(decoded.getTimeZone(), split.getTimeZone()); } }
@Override public Object set(Object o, TimestampTZ t) { if (t == null) { return null; } TimestampLocalTZTypeInfo timestampTZTypeInfo = (TimestampLocalTZTypeInfo) typeInfo; if (!t.getZonedDateTime().getZone().equals(timestampTZTypeInfo.timeZone())) { t.setZonedDateTime(t.getZonedDateTime().withZoneSameInstant(timestampTZTypeInfo.timeZone())); } ((TimestampLocalTZWritable) o).set(t); return o; }
@Override public TimestampLocalTZWritable getPrimitiveWritableObject(Object o) { if (o == null) { return null; } TimestampTZ t = (TimestampTZ) o; TimestampLocalTZTypeInfo timestampTZTypeInfo = (TimestampLocalTZTypeInfo) typeInfo; if (!t.getZonedDateTime().getZone().equals(timestampTZTypeInfo.timeZone())) { t.setZonedDateTime( t.getZonedDateTime().withZoneSameInstant(timestampTZTypeInfo.timeZone())); } return new TimestampLocalTZWritable(t); }
@Override public TimestampTZ getPrimitiveJavaObject(Object o) { if (o == null) { return null; } TimestampTZ t = ((LazyTimestampLocalTZ) o).getWritableObject().getTimestampTZ(); TimestampLocalTZTypeInfo timestampTZTypeInfo = (TimestampLocalTZTypeInfo) typeInfo; if (!t.getZonedDateTime().getZone().equals(timestampTZTypeInfo.timeZone())) { t.setZonedDateTime(t.getZonedDateTime().withZoneSameInstant(timestampTZTypeInfo.timeZone())); } return t; }
@Override public Object set(Object o, TimestampLocalTZWritable t) { if (t == null) { return null; } TimestampLocalTZTypeInfo timestampTZTypeInfo = (TimestampLocalTZTypeInfo) typeInfo; if (!t.getTimestampTZ().getZonedDateTime().getZone().equals(timestampTZTypeInfo.timeZone())) { t.getTimestampTZ().setZonedDateTime( t.getTimestampTZ().getZonedDateTime().withZoneSameInstant(timestampTZTypeInfo.timeZone())); } ((TimestampLocalTZWritable) o).set(t); return o; }
@Override public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layoutHandle, SplitSchedulingStrategy splitSchedulingStrategy) { AtopTableLayoutHandle handle = (AtopTableLayoutHandle) layoutHandle; AtopTableHandle table = handle.getTableHandle(); List<ConnectorSplit> splits = new ArrayList<>(); ZonedDateTime end = ZonedDateTime.now(timeZone); for (Node node : nodeManager.getWorkerNodes()) { ZonedDateTime start = end.minusDays(maxHistoryDays - 1).withHour(0).withMinute(0).withSecond(0).withNano(0); while (start.isBefore(end)) { ZonedDateTime splitEnd = start.withHour(23).withMinute(59).withSecond(59).withNano(0); Domain splitDomain = Domain.create(ValueSet.ofRanges(Range.range(TIMESTAMP_WITH_TIME_ZONE, 1000 * start.toEpochSecond(), true, 1000 * splitEnd.toEpochSecond(), true)), false); if (handle.getStartTimeConstraint().overlaps(splitDomain) && handle.getEndTimeConstraint().overlaps(splitDomain)) { splits.add(new AtopSplit(table.getTable(), node.getHostAndPort(), start.toEpochSecond(), start.getZone())); } start = start.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0); } } return new FixedSplitSource(splits); } }