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;
}
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);
}
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);
}
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);
}
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;
}
Aggregations