Search in sources :

Example 1 with TimestampTZ

use of org.apache.hadoop.hive.common.type.TimestampTZ in project hive by apache.

the class JavaTimestampLocalTZObjectInspector method create.

@Override
public Object create(byte[] bytes, int offset) {
    TimestampTZ t = new TimestampTZ();
    TimestampLocalTZWritable.setTimestampTZ(t, bytes, offset, ((TimestampLocalTZTypeInfo) typeInfo).timeZone());
    return t;
}
Also used : TimestampTZ(org.apache.hadoop.hive.common.type.TimestampTZ)

Example 2 with TimestampTZ

use of org.apache.hadoop.hive.common.type.TimestampTZ in project hive by apache.

the class TestTimestampTZWritable method verifyConversion.

private static void verifyConversion(TimestampTZ srcTstz) {
    TimestampLocalTZWritable src = new TimestampLocalTZWritable(srcTstz);
    byte[] bytes = src.getBytes();
    TimestampLocalTZWritable dest = new TimestampLocalTZWritable(bytes, 0, ZoneId.of("UTC"));
    TimestampTZ destTstz = dest.getTimestampTZ();
    String errMsg = "Src tstz with seconds " + srcTstz.getEpochSecond() + ", nanos " + srcTstz.getNanos() + ". Dest tstz with seconds " + destTstz.getEpochSecond() + ", nanos " + destTstz.getNanos();
    Assert.assertEquals(errMsg, srcTstz, destTstz);
}
Also used : TimestampTZ(org.apache.hadoop.hive.common.type.TimestampTZ)

Example 3 with TimestampTZ

use of org.apache.hadoop.hive.common.type.TimestampTZ in project hive by apache.

the class TestTimestampTZWritable method testSeconds.

@Test
@Repeating(repetition = 10)
public void testSeconds() {
    // just 1 VInt
    long seconds = ThreadLocalRandom.current().nextLong(Integer.MAX_VALUE);
    TimestampTZ tstz = new TimestampTZ(seconds, 0, ZoneId.of("UTC"));
    verifyConversion(tstz);
    // 2 VInt
    seconds = ThreadLocalRandom.current().nextLong(Integer.MAX_VALUE) + Integer.MAX_VALUE + 1;
    if (ThreadLocalRandom.current().nextBoolean()) {
        seconds = -seconds;
    }
    tstz.set(seconds, 0, ZoneId.of("UTC"));
    verifyConversion(tstz);
}
Also used : TimestampTZ(org.apache.hadoop.hive.common.type.TimestampTZ) Test(org.junit.Test) Repeating(com.google.code.tempusfugit.concurrency.annotations.Repeating)

Example 4 with TimestampTZ

use of org.apache.hadoop.hive.common.type.TimestampTZ in project hive by apache.

the class LazyTimestampLocalTZ method init.

@Override
public void init(ByteArrayRef bytes, int start, int length) {
    String s = null;
    if (!LazyUtils.isDateMaybe(bytes.getData(), start, length)) {
        isNull = true;
        return;
    }
    TimestampTZ t = null;
    try {
        s = new String(bytes.getData(), start, length, "US-ASCII");
        if (s.equals("NULL")) {
            isNull = true;
            logExceptionMessage(bytes, start, length, serdeConstants.TIMESTAMPLOCALTZ_TYPE_NAME.toUpperCase());
        } else {
            t = TimestampTZUtil.parse(s, timeZone);
            isNull = false;
        }
    } catch (UnsupportedEncodingException e) {
        isNull = true;
        LOG.error("Unsupported encoding found ", e);
    } catch (DateTimeParseException e) {
        isNull = true;
        logExceptionMessage(bytes, start, length, serdeConstants.TIMESTAMPLOCALTZ_TYPE_NAME.toUpperCase());
    }
    data.set(t);
}
Also used : TimestampTZ(org.apache.hadoop.hive.common.type.TimestampTZ) DateTimeParseException(java.time.format.DateTimeParseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with TimestampTZ

use of org.apache.hadoop.hive.common.type.TimestampTZ in project hive by apache.

the class UDFDateFloor method evaluate.

public TimestampLocalTZWritable evaluate(TimestampLocalTZWritable t) {
    if (t == null) {
        return null;
    }
    // default
    final ZonedDateTime localZDT = t.getTimestampTZ().getZonedDateTime();
    final long originalTimestampUTC = localZDT.withZoneSameLocal(ZoneOffset.UTC).toInstant().toEpochMilli();
    // utc
    final long newTimestampUTC = granularity.truncate(originalTimestampUTC);
    final ZonedDateTime newLocalZDT = ZonedDateTime.of(LocalDateTime.ofInstant(Instant.ofEpochMilli(newTimestampUTC), ZoneOffset.UTC), // utc -> default
    localZDT.getZone());
    resultTSLTZ.set(new TimestampTZ(newLocalZDT));
    return resultTSLTZ;
}
Also used : TimestampTZ(org.apache.hadoop.hive.common.type.TimestampTZ) ZonedDateTime(java.time.ZonedDateTime)

Aggregations

TimestampTZ (org.apache.hadoop.hive.common.type.TimestampTZ)13 TimestampLocalTZTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TimestampLocalTZTypeInfo)4 TimestampLocalTZWritable (org.apache.hadoop.hive.serde2.io.TimestampLocalTZWritable)3 Test (org.junit.Test)3 Repeating (com.google.code.tempusfugit.concurrency.annotations.Repeating)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Timestamp (java.sql.Timestamp)1 ParseException (java.text.ParseException)1 ZonedDateTime (java.time.ZonedDateTime)1 DateTimeParseException (java.time.format.DateTimeParseException)1 TimestampWithTimeZoneString (org.apache.calcite.util.TimestampWithTimeZoneString)1 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)1 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)1 VectorUDFUnixTimeStampString (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFUnixTimeStampString)1 VectorUDFUnixTimeStampTimestamp (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFUnixTimeStampTimestamp)1 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)1 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)1 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)1 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)1 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)1