use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class TestGenericUDFLastDay method runAndVerifyTs.
private void runAndVerifyTs(String str, String expResult, GenericUDF udf) throws HiveException {
DeferredObject valueObj0 = new DeferredJavaObject(str != null ? new TimestampWritableV2(Timestamp.valueOf(str)) : null);
DeferredObject[] args = { valueObj0 };
Text output = (Text) udf.evaluate(args);
assertEquals("last_day() test ", expResult, output != null ? output.toString() : null);
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class TestGenericUDFDate method testTimestampToDate.
@Test
public void testTimestampToDate() throws HiveException {
GenericUDFDate udf = new GenericUDFDate();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
DeferredObject valueObj = new DeferredJavaObject(new TimestampWritableV2(Timestamp.valueOf(LocalDateTime.of(109, 06, 30, 4, 17, 52, 0).toString())));
DeferredObject[] args = { valueObj };
DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
assertEquals("to_date() test for TIMESTAMP failed ", "0109-06-30", output.toString());
// Try with null args
DeferredObject[] nullArgs = { new DeferredJavaObject(null) };
output = (DateWritableV2) udf.evaluate(nullArgs);
assertNull("to_date() with null TIMESTAMP", output);
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class TestGenericUDFDateDiff method testTimestampToDate.
@Test
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 TimestampWritableV2(Timestamp.valueOf(LocalDateTime.of(109, 06, 20, 0, 0, 0, 0).toString())));
DeferredObject valueObj2 = new DeferredJavaObject(new TimestampWritableV2(Timestamp.valueOf(LocalDateTime.of(109, 06, 17, 0, 0, 0, 0).toString())));
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.TimestampWritableV2 in project hive by apache.
the class TestVectorTimestampExpressions method compareToUDFMonthLong.
private void compareToUDFMonthLong(Timestamp t, int y) throws HiveException {
UDFMonth udf = new UDFMonth();
udf.initialize(new ObjectInspector[] { PrimitiveObjectInspectorFactory.writableTimestampObjectInspector });
TimestampWritableV2 tsw = new TimestampWritableV2(org.apache.hadoop.hive.common.type.Timestamp.ofEpochMilli(t.getTime(), t.getNanos()));
IntWritable res = (IntWritable) udf.evaluate(new GenericUDF.DeferredObject[] { new GenericUDF.DeferredJavaObject(tsw) });
Assert.assertEquals(res.get(), y);
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class TestVectorTimestampExpressions method compareToUDFMinuteLong.
private void compareToUDFMinuteLong(Timestamp t, int y) throws HiveException {
UDFMinute udf = new UDFMinute();
udf.initialize(new ObjectInspector[] { PrimitiveObjectInspectorFactory.writableTimestampObjectInspector });
TimestampWritableV2 tsw = new TimestampWritableV2(org.apache.hadoop.hive.common.type.Timestamp.ofEpochMilli(t.getTime(), t.getNanos()));
IntWritable res = (IntWritable) udf.evaluate(new GenericUDF.DeferredObject[] { new GenericUDF.DeferredJavaObject(tsw) });
Assert.assertEquals(res.get(), y);
}
Aggregations