use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.
the class TestGenericUDFOPPlus method testDatePlusIntervalDayTime.
@Test
public void testDatePlusIntervalDayTime() throws Exception {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
DateWritable left = new DateWritable(Date.valueOf("2001-01-01"));
HiveIntervalDayTimeWritable right = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
// Date + day-time interval = timestamp
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
TimestampWritable res = (TimestampWritable) udf.evaluate(args);
Assert.assertEquals(Timestamp.valueOf("2001-01-02 2:3:4.567"), res.getTimestamp());
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.
the class TestGenericUDFOPPlus method testIntervalDayTimePlusDate.
@Test
public void testIntervalDayTimePlusDate() throws Exception {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
HiveIntervalDayTimeWritable left = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567"));
DateWritable right = new DateWritable(Date.valueOf("2001-01-01"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector, PrimitiveObjectInspectorFactory.writableDateObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
// Date + day-time interval = timestamp
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
TimestampWritable res = (TimestampWritable) udf.evaluate(args);
Assert.assertEquals(Timestamp.valueOf("2001-01-02 2:3:4.567"), res.getTimestamp());
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.
the class TestGenericUDFDateDiff method testTimestampToDate.
public void testTimestampToDate() throws HiveException {
GenericUDFDateDiff udf = new GenericUDFDateDiff();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new TimestampWritable(new Timestamp(109, 06, 20, 0, 0, 0, 0)));
DeferredObject valueObj2 = new DeferredJavaObject(new TimestampWritable(new Timestamp(109, 06, 17, 0, 0, 0, 0)));
DeferredObject[] args = { valueObj1, valueObj2 };
IntWritable output = (IntWritable) udf.evaluate(args);
assertEquals("datediff() test for TIMESTAMP failed ", "3", output.toString());
// Test with null args
args = new DeferredObject[] { new DeferredJavaObject(null), valueObj2 };
assertNull("date_add() 1st arg null", udf.evaluate(args));
args = new DeferredObject[] { valueObj1, new DeferredJavaObject(null) };
assertNull("date_add() 2nd arg null", udf.evaluate(args));
args = new DeferredObject[] { new DeferredJavaObject(null), new DeferredJavaObject(null) };
assertNull("date_add() both args null", udf.evaluate(args));
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.
the class TestGenericUDFDateFormat method runAndVerifyTs.
private void runAndVerifyTs(String str, Text fmtText, String expResult, GenericUDF udf) throws HiveException {
DeferredObject valueObj0 = new DeferredJavaObject(str != null ? new TimestampWritable(Timestamp.valueOf(str)) : null);
DeferredObject valueObj1 = new DeferredJavaObject(fmtText);
DeferredObject[] args = { valueObj0, valueObj1 };
Text output = (Text) udf.evaluate(args);
assertEquals("date_format() test ", expResult, output != null ? output.toString() : null);
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.
the class RecordReaderImpl method nextTimestamp.
static TimestampWritable nextTimestamp(ColumnVector vector, int row, Object previous) {
if (vector.isRepeating) {
row = 0;
}
if (vector.noNulls || !vector.isNull[row]) {
TimestampWritable result;
if (previous == null || previous.getClass() != TimestampWritable.class) {
result = new TimestampWritable();
} else {
result = (TimestampWritable) previous;
}
TimestampColumnVector tcv = (TimestampColumnVector) vector;
result.setInternal(tcv.time[row], tcv.nanos[row]);
return result;
} else {
return null;
}
}
Aggregations