use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFDateSub method testTimestampToDate.
public void testTimestampToDate() throws HiveException {
GenericUDFDateSub udf = new GenericUDFDateSub();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new TimestampWritable(new Timestamp(109, 06, 20, 4, 17, 52, 0)));
DeferredObject valueObj2 = new DeferredJavaObject(new Integer("3"));
DeferredObject[] args = { valueObj1, valueObj2 };
DateWritable output = (DateWritable) udf.evaluate(args);
assertEquals("date_sub() test for TIMESTAMP failed ", "2009-07-17", 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.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFDateSub method testStringToDate.
public void testStringToDate() throws HiveException {
GenericUDFDateSub udf = new GenericUDFDateSub();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new Text("2009-07-20 04:17:52"));
DeferredObject valueObj2 = new DeferredJavaObject(new Integer("2"));
DeferredObject[] args = { valueObj1, valueObj2 };
DateWritable output = (DateWritable) udf.evaluate(args);
assertEquals("date_sub() test for STRING failed ", "2009-07-18", 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.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFDateSub method testByteDataTypeAsDays.
public void testByteDataTypeAsDays() throws HiveException {
GenericUDFDateSub udf = new GenericUDFDateSub();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaByteObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new DateWritable(new Date(109, 06, 20)));
DeferredObject valueObj2 = new DeferredJavaObject(new Byte("4"));
DeferredObject[] args = { valueObj1, valueObj2 };
DateWritable output = (DateWritable) udf.evaluate(args);
assertEquals("date_add() test for BYTE failed ", "2009-07-16", output.toString());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFFloor method testByte.
@Test
public void testByte() throws HiveException {
GenericUDFFloor udf = new GenericUDFFloor();
ByteWritable input = new ByteWritable((byte) 4);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableByteObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.longTypeInfo, oi.getTypeInfo());
LongWritable res = (LongWritable) udf.evaluate(args);
Assert.assertEquals(4L, res.get());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFFloor method testLong.
@Test
public void testLong() throws HiveException {
GenericUDFFloor udf = new GenericUDFFloor();
LongWritable input = new LongWritable(3234747);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableLongObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.longTypeInfo, oi.getTypeInfo());
LongWritable res = (LongWritable) udf.evaluate(args);
Assert.assertEquals(3234747L, res.get());
}
Aggregations