Search in sources :

Example 21 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestGenericUDFAbs method testHiveDecimal.

public void testHiveDecimal() throws HiveException {
    GenericUDFAbs udf = new GenericUDFAbs();
    int prec = 12;
    int scale = 9;
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(prec, scale));
    ObjectInspector[] arguments = { valueOI };
    PrimitiveObjectInspector outputOI = (PrimitiveObjectInspector) udf.initialize(arguments);
    // Make sure result precision/scale matches the input prec/scale
    assertEquals("result precision for abs()", prec, outputOI.precision());
    assertEquals("result scale for abs()", scale, outputOI.scale());
    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());
    // null input
    args[0] = new DeferredJavaObject(null);
    output = (HiveDecimalWritable) udf.evaluate(args);
    assertEquals("abs(null)", null, output);
    // if value too large, should also be null
    args[0] = new DeferredJavaObject(new HiveDecimalWritable(HiveDecimal.create("-1000.123456")));
    output = (HiveDecimalWritable) udf.evaluate(args);
    assertEquals("abs() of too large decimal value", null, output);
}
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) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)

Example 22 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestStreamingMin method minLong.

public void minLong(Iterator<Long> inVals, int inSz, int numPreceding, int numFollowing, Iterator<Long> outVals) throws HiveException {
    GenericUDAFMin fnR = new GenericUDAFMin();
    TypeInfo[] inputTypes = { TypeInfoFactory.longTypeInfo };
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableLongObjectInspector };
    LongWritable[] in = new LongWritable[1];
    in[0] = new LongWritable();
    TestStreamingSum._agg(fnR, inputTypes, inVals, TypeHandler.LongHandler, in, inputOIs, inSz, numPreceding, numFollowing, outVals);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) GenericUDAFMin(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFMin) LongWritable(org.apache.hadoop.io.LongWritable) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)

Example 23 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestStreamingSum method sumLong.

public void sumLong(Iterator<Long> inVals, int inSz, int numPreceding, int numFollowing, Iterator<Long> outVals) throws HiveException {
    GenericUDAFSum fnR = new GenericUDAFSum();
    TypeInfo[] inputTypes = { TypeInfoFactory.longTypeInfo };
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableLongObjectInspector };
    LongWritable[] in = new LongWritable[1];
    in[0] = new LongWritable();
    _agg(fnR, inputTypes, inVals, TypeHandler.LongHandler, in, inputOIs, inSz, numPreceding, numFollowing, outVals);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) LongWritable(org.apache.hadoop.io.LongWritable) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) GenericUDAFSum(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFSum)

Example 24 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestStreamingSum method sumHiveDecimal.

public void sumHiveDecimal(Iterator<HiveDecimal> inVals, int inSz, int numPreceding, int numFollowing, Iterator<HiveDecimal> outVals) throws HiveException {
    GenericUDAFSum fnR = new GenericUDAFSum();
    TypeInfo[] inputTypes = { TypeInfoFactory.decimalTypeInfo };
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector };
    HiveDecimalWritable[] in = new HiveDecimalWritable[1];
    in[0] = new HiveDecimalWritable();
    _agg(fnR, inputTypes, inVals, TypeHandler.HiveDecimalHandler, in, inputOIs, inSz, numPreceding, numFollowing, outVals);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) GenericUDAFSum(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFSum)

Example 25 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestStreamingSum method sumDouble.

public void sumDouble(Iterator<Double> inVals, int inSz, int numPreceding, int numFollowing, Iterator<Double> outVals) throws HiveException {
    GenericUDAFSum fnR = new GenericUDAFSum();
    TypeInfo[] inputTypes = { TypeInfoFactory.doubleTypeInfo };
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector };
    DoubleWritable[] in = new DoubleWritable[1];
    in[0] = new DoubleWritable();
    _agg(fnR, inputTypes, inVals, TypeHandler.DoubleHandler, in, inputOIs, inSz, numPreceding, numFollowing, outVals);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) GenericUDAFSum(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFSum)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)700 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)299 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)261 Test (org.junit.Test)241 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)163 ArrayList (java.util.ArrayList)159 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)159 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)107 Text (org.apache.hadoop.io.Text)103 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)89 StringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector)75 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)73 StructField (org.apache.hadoop.hive.serde2.objectinspector.StructField)66 IntWritable (org.apache.hadoop.io.IntWritable)65 LongObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector)58 LongWritable (org.apache.hadoop.io.LongWritable)54 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)53 IntObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector)53 DoubleObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector)51 BytesWritable (org.apache.hadoop.io.BytesWritable)51