Search in sources :

Example 21 with PrimitiveObjectInspectorFactory.writableLongObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableLongObjectInspector in project hive by apache.

the class GenericUDFAbs method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 1) {
        throw new UDFArgumentLengthException("ABS() requires 1 argument, got " + arguments.length);
    }
    if (arguments[0].getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentException("ABS only takes primitive types, got " + arguments[0].getTypeName());
    }
    argumentOI = (PrimitiveObjectInspector) arguments[0];
    inputType = argumentOI.getPrimitiveCategory();
    ObjectInspector outputOI = null;
    switch(inputType) {
        case SHORT:
        case BYTE:
        case INT:
            inputConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableIntObjectInspector);
            outputOI = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
            break;
        case LONG:
            inputConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableLongObjectInspector);
            outputOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
            break;
        case FLOAT:
        case STRING:
        case DOUBLE:
            inputConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
            outputOI = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
            break;
        case DECIMAL:
            outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(((PrimitiveObjectInspector) arguments[0]).getTypeInfo());
            inputConverter = ObjectInspectorConverters.getConverter(arguments[0], outputOI);
            break;
        default:
            throw new UDFArgumentException("ABS only takes SHORT/BYTE/INT/LONG/DOUBLE/FLOAT/STRING/DECIMAL types, got " + inputType);
    }
    return outputOI;
}
Also used : UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) HiveDecimalObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.HiveDecimalObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)

Example 22 with PrimitiveObjectInspectorFactory.writableLongObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableLongObjectInspector in project hive by apache.

the class GenericUDFFactorial method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    checkArgsSize(arguments, 1, 1);
    checkArgPrimitive(arguments, 0);
    checkArgGroups(arguments, 0, inputTypes, NUMERIC_GROUP, VOID_GROUP);
    obtainIntConverter(arguments, 0, inputTypes, converters);
    ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
    return outputOI;
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Example 23 with PrimitiveObjectInspectorFactory.writableLongObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableLongObjectInspector in project hive by apache.

the class TestGenericUDFCeil method testLong.

@Test
public void testLong() throws HiveException {
    GenericUDFCeil udf = new GenericUDFCeil();
    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());
}
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) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) LongWritable(org.apache.hadoop.io.LongWritable) Test(org.junit.Test)

Example 24 with PrimitiveObjectInspectorFactory.writableLongObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableLongObjectInspector in project hive by apache.

the class TestStreamingMax method maxLong.

public void maxLong(Iterator<Long> inVals, int inSz, int numPreceding, int numFollowing, Iterator<Long> outVals) throws HiveException {
    GenericUDAFMax fnR = new GenericUDAFMax();
    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) GenericUDAFMax(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFMax) LongWritable(org.apache.hadoop.io.LongWritable) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)

Example 25 with PrimitiveObjectInspectorFactory.writableLongObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableLongObjectInspector 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

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)29 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)22 LongWritable (org.apache.hadoop.io.LongWritable)22 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)17 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)17 Test (org.junit.Test)17 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)8 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)6 UDFArgumentLengthException (org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)5 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)4 UDFArgumentTypeException (org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)4 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)3 IntWritable (org.apache.hadoop.io.IntWritable)3 ArrayList (java.util.ArrayList)2 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)2 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)2 ConstantObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector)2 Converter (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter)2 HiveDecimalObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.HiveDecimalObjectInspector)2 FloatWritable (org.apache.hadoop.io.FloatWritable)2