assertEquals("abs() test for String failed ", "123.45", output.toString());
}
public void testHiveDecimal() throws HiveException {
GenericUDFAbs udf = new GenericUDFAbs();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector;
ObjectInspector[] arguments = {valueOI};
udf.initialize(arguments);
DeferredObject valueObj = new DeferredJavaObject(new HiveDecimalWritable(HiveDecimal.create(
"107.123456789")));
DeferredObject[] args = {valueObj};
HiveDecimalWritable output = (HiveDecimalWritable) udf.evaluate(args);
assertEquals("abs() test for HiveDecimal failed ", 107.123456789, output.getHiveDecimal()
.doubleValue());
valueObj = new DeferredJavaObject(new HiveDecimalWritable(HiveDecimal.create("-107.123456789")));
args[0] = valueObj;
output = (HiveDecimalWritable) udf.evaluate(args);
assertEquals("abs() test for HiveDecimal failed ", 107.123456789, output.getHiveDecimal()
.doubleValue());
}