use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFFloor method testDecimal.
@Test
public void testDecimal() throws HiveException {
GenericUDFFloor udf = new GenericUDFFloor();
HiveDecimalWritable input = new HiveDecimalWritable(HiveDecimal.create("32300.004747"));
DecimalTypeInfo inputTypeInfo = TypeInfoFactory.getDecimalTypeInfo(11, 6);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo) };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(6, 0), oi.getTypeInfo());
HiveDecimalWritable res = (HiveDecimalWritable) udf.evaluate(args);
Assert.assertEquals(HiveDecimal.create("32300"), res.getHiveDecimal());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFFromUtcTimestamp method runAndVerify.
public static void runAndVerify(GenericUDF udf, Object arg1, Object arg2, Object expected) throws HiveException {
DeferredObject[] args = { new DeferredJavaObject(arg1), new DeferredJavaObject(arg2) };
Object result = udf.evaluate(args);
if (expected == null) {
assertNull(result);
} else {
assertEquals(expected.toString(), result.toString());
}
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFGreatest method runAndVerify.
private void runAndVerify(Object[] v, Object expResult, GenericUDF udf) throws HiveException {
DeferredObject[] args = new DeferredObject[v.length];
for (int i = 0; i < v.length; i++) {
args[i] = new DeferredJavaObject(getWritable(v[i]));
}
Object output = udf.evaluate(args);
output = parseOutput(output);
assertEquals("greatest() test ", expResult, output != null ? output : null);
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFDateAdd method testDateWritablepToDate.
public void testDateWritablepToDate() throws HiveException {
GenericUDFDateAdd udf = new GenericUDFDateAdd();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new DateWritable(new Date(109, 06, 20)));
DeferredObject valueObj2 = new DeferredJavaObject(new Integer("4"));
DeferredObject[] args = { valueObj1, valueObj2 };
DateWritable output = (DateWritable) udf.evaluate(args);
assertEquals("date_add() test for DATEWRITABLE failed ", "2009-07-24", 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 TestGenericUDFDateFormat method runAndVerifyDate.
private void runAndVerifyDate(String str, Text fmtText, String expResult, GenericUDF udf) throws HiveException {
DeferredObject valueObj0 = new DeferredJavaObject(str != null ? new DateWritable(Date.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);
}
Aggregations