Search in sources :

Example 6 with GenericUDFAbs

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFAbs in project hive by apache.

the class TestGenericUDFAbs method testLong.

public void testLong() throws HiveException {
    GenericUDFAbs udf = new GenericUDFAbs();
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
    ObjectInspector[] arguments = { valueOI };
    udf.initialize(arguments);
    DeferredObject valueObj = new DeferredJavaObject(new LongWritable(107L));
    DeferredObject[] args = { valueObj };
    LongWritable output = (LongWritable) udf.evaluate(args);
    assertEquals("abs() test for LONG failed ", 107, output.get());
    valueObj = new DeferredJavaObject(new LongWritable(-107L));
    args[0] = valueObj;
    output = (LongWritable) udf.evaluate(args);
    assertEquals("abs() test for LONG failed ", 107, output.get());
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) GenericUDFAbs(org.apache.hadoop.hive.ql.udf.generic.GenericUDFAbs) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) LongWritable(org.apache.hadoop.io.LongWritable)

Aggregations

DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)6 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)6 GenericUDFAbs (org.apache.hadoop.hive.ql.udf.generic.GenericUDFAbs)6 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)6 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)6 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)3 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)1 FloatWritable (org.apache.hadoop.io.FloatWritable)1 IntWritable (org.apache.hadoop.io.IntWritable)1 LongWritable (org.apache.hadoop.io.LongWritable)1 Text (org.apache.hadoop.io.Text)1