use of io.trino.spi.type.LongTimestampWithTimeZone in project trino by trinodb.
the class DateTimes method toZonedDateTime.
public static ZonedDateTime toZonedDateTime(TimestampWithTimeZoneType type, Block block, int position) {
int precision = type.getPrecision();
long epochMillis;
int picosOfMilli = 0;
ZoneId zoneId;
if (precision <= TimestampWithTimeZoneType.MAX_SHORT_PRECISION) {
long packedEpochMillis = type.getLong(block, position);
epochMillis = unpackMillisUtc(packedEpochMillis);
zoneId = unpackZoneKey(packedEpochMillis).getZoneId();
} else {
LongTimestampWithTimeZone timestamp = (LongTimestampWithTimeZone) type.getObject(block, position);
epochMillis = timestamp.getEpochMillis();
picosOfMilli = timestamp.getPicosOfMilli();
zoneId = getTimeZoneKey(timestamp.getTimeZoneKey()).getZoneId();
}
long epochSecond = scaleEpochMillisToSeconds(epochMillis);
int nanoFraction = getMillisOfSecond(epochMillis) * NANOSECONDS_PER_MILLISECOND + (int) (roundToNearest(picosOfMilli, PICOSECONDS_PER_NANOSECOND) / PICOSECONDS_PER_NANOSECOND);
return Instant.ofEpochSecond(epochSecond, nanoFraction).atZone(zoneId);
}
use of io.trino.spi.type.LongTimestampWithTimeZone in project trino by trinodb.
the class TimestampColumnWriter method writeInstantLong.
private void writeInstantLong(Block block) {
for (int i = 0; i < block.getPositionCount(); i++) {
if (!block.isNull(i)) {
LongTimestampWithTimeZone timestamp = (LongTimestampWithTimeZone) type.getObject(block, i);
long millis = timestamp.getEpochMillis();
// ORC erroneously uses normal division for seconds
long seconds = millis / MILLISECONDS_PER_SECOND;
long millisFraction = floorMod(millis, MILLISECONDS_PER_SECOND);
long nanosFraction = (millisFraction * NANOSECONDS_PER_MILLISECOND) + (timestamp.getPicosOfMilli() / PICOSECONDS_PER_NANOSECOND);
writeValues(seconds, nanosFraction);
statisticsBuilder.addValue(millis);
}
}
}
use of io.trino.spi.type.LongTimestampWithTimeZone in project trino by trinodb.
the class TestTupleDomainOrcPredicate method testInstantNanos.
@Test
public void testInstantNanos() {
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 0, null)).isEqualTo(none(TIMESTAMP_TZ_NANOS));
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 10, null)).isEqualTo(all(TIMESTAMP_TZ_NANOS));
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 0, timeStampColumnStats(null, null, null))).isEqualTo(none(TIMESTAMP_TZ_NANOS));
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 0, timeStampColumnStats(0L, null, null))).isEqualTo(none(TIMESTAMP_TZ_NANOS));
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 0, timeStampColumnStats(0L, 100L, 100L))).isEqualTo(none(TIMESTAMP_TZ_NANOS));
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 10, timeStampColumnStats(0L, null, null))).isEqualTo(onlyNull(TIMESTAMP_TZ_NANOS));
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 10, timeStampColumnStats(10L, null, null))).isEqualTo(notNull(TIMESTAMP_TZ_NANOS));
LongTimestampWithTimeZone low13 = LongTimestampWithTimeZone.fromEpochMillisAndFraction(13L, 0, UTC_KEY);
LongTimestampWithTimeZone low100 = LongTimestampWithTimeZone.fromEpochMillisAndFraction(100L, 0, UTC_KEY);
LongTimestampWithTimeZone high100 = LongTimestampWithTimeZone.fromEpochMillisAndFraction(100L, 999_999_000, UTC_KEY);
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 10, timeStampColumnStats(10L, 100L, 100L))).isEqualTo(create(ValueSet.ofRanges(range(TIMESTAMP_TZ_NANOS, low100, true, high100, true)), false));
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 10, timeStampColumnStats(10L, 13L, 100L))).isEqualTo(create(ValueSet.ofRanges(range(TIMESTAMP_TZ_NANOS, low13, true, high100, true)), false));
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 10, timeStampColumnStats(10L, null, 100L))).isEqualTo(create(ValueSet.ofRanges(lessThanOrEqual(TIMESTAMP_TZ_NANOS, high100)), false));
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 10, timeStampColumnStats(10L, 13L, null))).isEqualTo(create(ValueSet.ofRanges(greaterThanOrEqual(TIMESTAMP_TZ_NANOS, low13)), false));
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 10, timeStampColumnStats(5L, 13L, 100L))).isEqualTo(create(ValueSet.ofRanges(range(TIMESTAMP_TZ_NANOS, low13, true, high100, true)), true));
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 10, timeStampColumnStats(5L, null, 100L))).isEqualTo(create(ValueSet.ofRanges(lessThanOrEqual(TIMESTAMP_TZ_NANOS, high100)), true));
assertThat(getDomain(TIMESTAMP_TZ_NANOS, 10, timeStampColumnStats(5L, 13L, null))).isEqualTo(create(ValueSet.ofRanges(greaterThanOrEqual(TIMESTAMP_TZ_NANOS, low13)), true));
}
use of io.trino.spi.type.LongTimestampWithTimeZone in project trino by trinodb.
the class TestTupleDomainOrcPredicate method testInstantMicros.
@Test
public void testInstantMicros() {
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 0, null)).isEqualTo(none(TIMESTAMP_TZ_MICROS));
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 10, null)).isEqualTo(all(TIMESTAMP_TZ_MICROS));
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 0, timeStampColumnStats(null, null, null))).isEqualTo(none(TIMESTAMP_TZ_MICROS));
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 0, timeStampColumnStats(0L, null, null))).isEqualTo(none(TIMESTAMP_TZ_MICROS));
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 0, timeStampColumnStats(0L, 100L, 100L))).isEqualTo(none(TIMESTAMP_TZ_MICROS));
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 10, timeStampColumnStats(0L, null, null))).isEqualTo(onlyNull(TIMESTAMP_TZ_MICROS));
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 10, timeStampColumnStats(10L, null, null))).isEqualTo(notNull(TIMESTAMP_TZ_MICROS));
LongTimestampWithTimeZone low13 = LongTimestampWithTimeZone.fromEpochMillisAndFraction(13L, 0, UTC_KEY);
LongTimestampWithTimeZone low100 = LongTimestampWithTimeZone.fromEpochMillisAndFraction(100L, 0, UTC_KEY);
LongTimestampWithTimeZone high100 = LongTimestampWithTimeZone.fromEpochMillisAndFraction(100L, 999_000_000, UTC_KEY);
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 10, timeStampColumnStats(10L, 100L, 100L))).isEqualTo(create(ValueSet.ofRanges(range(TIMESTAMP_TZ_MICROS, low100, true, high100, true)), false));
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 10, timeStampColumnStats(10L, 13L, 100L))).isEqualTo(create(ValueSet.ofRanges(range(TIMESTAMP_TZ_MICROS, low13, true, high100, true)), false));
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 10, timeStampColumnStats(10L, null, 100L))).isEqualTo(create(ValueSet.ofRanges(lessThanOrEqual(TIMESTAMP_TZ_MICROS, high100)), false));
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 10, timeStampColumnStats(10L, 13L, null))).isEqualTo(create(ValueSet.ofRanges(greaterThanOrEqual(TIMESTAMP_TZ_MICROS, low13)), false));
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 10, timeStampColumnStats(5L, 13L, 100L))).isEqualTo(create(ValueSet.ofRanges(range(TIMESTAMP_TZ_MICROS, low13, true, high100, true)), true));
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 10, timeStampColumnStats(5L, null, 100L))).isEqualTo(create(ValueSet.ofRanges(lessThanOrEqual(TIMESTAMP_TZ_MICROS, high100)), true));
assertThat(getDomain(TIMESTAMP_TZ_MICROS, 10, timeStampColumnStats(5L, 13L, null))).isEqualTo(create(ValueSet.ofRanges(greaterThanOrEqual(TIMESTAMP_TZ_MICROS, low13)), true));
}
use of io.trino.spi.type.LongTimestampWithTimeZone in project trino by trinodb.
the class PartitionTransforms method extractTimestampWithTimeZone.
private static Block extractTimestampWithTimeZone(Block block, ToLongFunction<LongTimestampWithTimeZone> function) {
BlockBuilder builder = INTEGER.createFixedSizeBlockBuilder(block.getPositionCount());
for (int position = 0; position < block.getPositionCount(); position++) {
if (block.isNull(position)) {
builder.appendNull();
continue;
}
LongTimestampWithTimeZone value = getTimestampTz(block, position);
INTEGER.writeLong(builder, function.applyAsLong(value));
}
return builder.build();
}
Aggregations