Search in sources :

Example 1 with LongTimestampWithTimeZone

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);
}
Also used : ZoneId(java.time.ZoneId) LongTimestampWithTimeZone(io.trino.spi.type.LongTimestampWithTimeZone)

Example 2 with LongTimestampWithTimeZone

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);
        }
    }
}
Also used : LongTimestampWithTimeZone(io.trino.spi.type.LongTimestampWithTimeZone) BooleanStreamCheckpoint(io.trino.orc.checkpoint.BooleanStreamCheckpoint) LongStreamCheckpoint(io.trino.orc.checkpoint.LongStreamCheckpoint)

Example 3 with LongTimestampWithTimeZone

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));
}
Also used : LongTimestampWithTimeZone(io.trino.spi.type.LongTimestampWithTimeZone) Test(org.testng.annotations.Test)

Example 4 with LongTimestampWithTimeZone

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));
}
Also used : LongTimestampWithTimeZone(io.trino.spi.type.LongTimestampWithTimeZone) Test(org.testng.annotations.Test)

Example 5 with LongTimestampWithTimeZone

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();
}
Also used : LongTimestampWithTimeZone(io.trino.spi.type.LongTimestampWithTimeZone) SliceUtf8.offsetOfCodePoint(io.airlift.slice.SliceUtf8.offsetOfCodePoint) BlockBuilder(io.trino.spi.block.BlockBuilder)

Aggregations

LongTimestampWithTimeZone (io.trino.spi.type.LongTimestampWithTimeZone)6 Test (org.testng.annotations.Test)2 Slice (io.airlift.slice.Slice)1 SliceUtf8.offsetOfCodePoint (io.airlift.slice.SliceUtf8.offsetOfCodePoint)1 BooleanStreamCheckpoint (io.trino.orc.checkpoint.BooleanStreamCheckpoint)1 LongStreamCheckpoint (io.trino.orc.checkpoint.LongStreamCheckpoint)1 StandardColumnMappings.fromTrinoTimestamp (io.trino.plugin.jdbc.StandardColumnMappings.fromTrinoTimestamp)1 TrinoException (io.trino.spi.TrinoException)1 BlockBuilder (io.trino.spi.block.BlockBuilder)1 ArrayType (io.trino.spi.type.ArrayType)1 CharType (io.trino.spi.type.CharType)1 DecimalType (io.trino.spi.type.DecimalType)1 Int128 (io.trino.spi.type.Int128)1 TimestampType (io.trino.spi.type.TimestampType)1 TimestampWithTimeZoneType (io.trino.spi.type.TimestampWithTimeZoneType)1 VarcharType (io.trino.spi.type.VarcharType)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 MathContext (java.math.MathContext)1 Date (java.sql.Date)1