use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class GenericUDFReflect2 method evaluate.
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
Object targetObject = targetOI.getPrimitiveJavaObject(arguments[0].get());
if (targetObject == null) {
return null;
}
Object result = null;
try {
result = method.invoke(targetObject, setupParameters(arguments, 2));
} catch (InvocationTargetException e) {
throw new HiveException(e.getCause());
} catch (Exception e) {
throw new HiveException(e);
}
if (result == null) {
return null;
}
switch(returnOI.getPrimitiveCategory()) {
case VOID:
return null;
case BOOLEAN:
((BooleanWritable) returnObj).set((Boolean) result);
return returnObj;
case BYTE:
((ByteWritable) returnObj).set((Byte) result);
return returnObj;
case SHORT:
((ShortWritable) returnObj).set((Short) result);
return returnObj;
case INT:
((IntWritable) returnObj).set((Integer) result);
return returnObj;
case LONG:
((LongWritable) returnObj).set((Long) result);
return returnObj;
case FLOAT:
((FloatWritable) returnObj).set((Float) result);
return returnObj;
case DOUBLE:
((DoubleWritable) returnObj).set((Double) result);
return returnObj;
case STRING:
((Text) returnObj).set((String) result);
return returnObj;
case TIMESTAMP:
((TimestampWritableV2) returnObj).set((Timestamp) result);
return returnObj;
case BINARY:
((BytesWritable) returnObj).set((byte[]) result, 0, ((byte[]) result).length);
return returnObj;
case DECIMAL:
((HiveDecimalWritable) returnObj).set((HiveDecimal) result);
return returnObj;
}
throw new HiveException("Invalid type " + returnOI.getPrimitiveCategory());
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class TestETypeConverter method testGetInt64MillisTimestampConverter.
@Test
public void testGetInt64MillisTimestampConverter() throws Exception {
Timestamp timestamp = Timestamp.valueOf("2018-07-15 15:12:20.112");
PrimitiveType primitiveType = createInt64TimestampType(false, TimeUnit.MILLIS);
Writable writable = getWritableFromPrimitiveConverter(null, primitiveType, timestamp.toEpochMilli());
TimestampWritableV2 timestampWritable = (TimestampWritableV2) writable;
assertEquals(timestamp.toEpochMilli(), timestampWritable.getTimestamp().toEpochMilli());
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class TestETypeConverter method testGetInt64NanosTimestampConverter.
@Test
public void testGetInt64NanosTimestampConverter() throws Exception {
Timestamp timestamp = Timestamp.valueOf("2018-07-15 15:12:20.11223344");
PrimitiveType primitiveType = createInt64TimestampType(false, TimeUnit.NANOS);
long time = timestamp.toEpochSecond() * 1000000000 + timestamp.getNanos();
Writable writable = getWritableFromPrimitiveConverter(null, primitiveType, time);
TimestampWritableV2 timestampWritable = (TimestampWritableV2) writable;
assertEquals(timestamp.toEpochMilli(), timestampWritable.getTimestamp().toEpochMilli());
assertEquals(timestamp.getNanos(), timestampWritable.getNanos());
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class TestETypeConverter method testGetInt64MicrosTimestampConverter.
@Test
public void testGetInt64MicrosTimestampConverter() throws Exception {
Timestamp timestamp = Timestamp.valueOf("2018-07-15 15:12:20.112233");
PrimitiveType primitiveType = createInt64TimestampType(false, TimeUnit.MICROS);
long time = timestamp.toEpochSecond() * 1000000 + timestamp.getNanos() / 1000;
Writable writable = getWritableFromPrimitiveConverter(null, primitiveType, time);
TimestampWritableV2 timestampWritable = (TimestampWritableV2) writable;
assertEquals(timestamp.toEpochMilli(), timestampWritable.getTimestamp().toEpochMilli());
assertEquals(timestamp.getNanos(), timestampWritable.getNanos());
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class TestETypeConverter method testGetTimestampProlepticConverter.
@Test
public void testGetTimestampProlepticConverter() throws Exception {
Timestamp timestamp = Timestamp.valueOf("1572-06-15 15:12:20.0");
NanoTime nanoTime = NanoTimeUtils.getNanoTime(timestamp, ZoneOffset.UTC, false);
PrimitiveType primitiveType = Types.optional(PrimitiveTypeName.INT96).named("value");
Writable writable = getWritableFromBinaryConverter(null, primitiveType, nanoTime.toBinary());
TimestampWritableV2 timestampWritable = (TimestampWritableV2) writable;
assertEquals(timestamp.getNanos(), timestampWritable.getNanos());
}
Aggregations