Search in sources :

Example 16 with PrimitiveObjectInspectorFactory.writableLongObjectInspector

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

the class TestGenericUDFExtractUnion method initialize_UnionAndTagArguments.

@Test
public void initialize_UnionAndTagArguments() throws UDFArgumentException {
    when(unionOI.getObjectInspectors()).thenReturn(ImmutableList.<ObjectInspector>of(PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableLongObjectInspector));
    when(tagOI.getWritableConstantValue()).thenReturn(new IntWritable(0));
    ObjectInspector result = underTest.initialize(new ObjectInspector[] { unionOI, tagOI });
    assertThat(result, is((ObjectInspector) PrimitiveObjectInspectorFactory.writableStringObjectInspector));
}
Also used : UnionObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.UnionObjectInspector) WritableConstantIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 17 with PrimitiveObjectInspectorFactory.writableLongObjectInspector

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

the class TestGenericUDFOPPlus method testDoublePlusLong.

@Test
public void testDoublePlusLong() throws HiveException {
    GenericUDFOPPlus udf = new GenericUDFOPPlus();
    // Int
    DoubleWritable left = new DoubleWritable(4.5);
    LongWritable right = new LongWritable(10);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.writableLongObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.doubleTypeInfo, oi.getTypeInfo());
    DoubleWritable res = (DoubleWritable) udf.evaluate(args);
    Assert.assertEquals(new Double(14.5), new Double(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) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) LongWritable(org.apache.hadoop.io.LongWritable) Test(org.junit.Test)

Example 18 with PrimitiveObjectInspectorFactory.writableLongObjectInspector

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

the class GenericUDFTrunc method initializeNumber.

private ObjectInspector initializeNumber(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length < 1 || arguments.length > 2) {
        throw new UDFArgumentLengthException("TRUNC requires one or two argument, got " + arguments.length);
    }
    if (arguments[0].getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0, "TRUNC input only takes primitive types, got " + arguments[0].getTypeName());
    }
    inputOI = (PrimitiveObjectInspector) arguments[0];
    if (arguments.length == 2) {
        if (arguments[1].getCategory() != Category.PRIMITIVE) {
            throw new UDFArgumentTypeException(1, "TRUNC second argument only takes primitive types, got " + arguments[1].getTypeName());
        }
        inputScaleOI = (PrimitiveObjectInspector) arguments[1];
        inputSacleConst = arguments[1] instanceof ConstantObjectInspector;
        if (inputSacleConst) {
            try {
                Object obj = ((ConstantObjectInspector) arguments[1]).getWritableConstantValue();
                fmtInput = obj != null ? obj.toString() : null;
                scale = Integer.parseInt(fmtInput);
            } catch (Exception e) {
                throw new UDFArgumentException("TRUNC input only takes integer values, got " + fmtInput);
            }
        } else {
            switch(inputScaleOI.getPrimitiveCategory()) {
                case BYTE:
                    byteConverter = ObjectInspectorConverters.getConverter(arguments[1], PrimitiveObjectInspectorFactory.writableByteObjectInspector);
                    break;
                case SHORT:
                    shortConverter = ObjectInspectorConverters.getConverter(arguments[1], PrimitiveObjectInspectorFactory.writableShortObjectInspector);
                    break;
                case INT:
                    intConverter = ObjectInspectorConverters.getConverter(arguments[1], PrimitiveObjectInspectorFactory.writableIntObjectInspector);
                    break;
                case LONG:
                    longConverter = ObjectInspectorConverters.getConverter(arguments[1], PrimitiveObjectInspectorFactory.writableLongObjectInspector);
                    break;
                default:
                    throw new UDFArgumentTypeException(1, getFuncName().toUpperCase() + " second argument only takes integer values");
            }
        }
    }
    inputType1 = inputOI.getPrimitiveCategory();
    ObjectInspector outputOI = null;
    switch(inputType1) {
        case DECIMAL:
            outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputType1);
            break;
        case VOID:
        case BYTE:
        case SHORT:
        case INT:
        case LONG:
        case FLOAT:
        case DOUBLE:
            outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputType1);
            break;
        default:
            throw new UDFArgumentTypeException(0, "Only numeric or string group data types are allowed for TRUNC function. Got " + inputType1.name());
    }
    return outputOI;
}
Also used : UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException) ParseException(java.text.ParseException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException)

Example 19 with PrimitiveObjectInspectorFactory.writableLongObjectInspector

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

the class GenericUDFSQCountCheck method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length > 2) {
        throw new UDFArgumentLengthException("Invalid scalar subquery expression. Subquery count check expected two argument but received: " + arguments.length);
    }
    converters[0] = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableLongObjectInspector);
    ObjectInspector outputOI = null;
    outputOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
    return outputOI;
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)

Example 20 with PrimitiveObjectInspectorFactory.writableLongObjectInspector

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

the class BitmapObjectInput method readInt.

@Override
public int readInt() throws IOException {
    if (bufferIter.hasNext()) {
        LongObjectInspector loi = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
        Long l = PrimitiveObjectInspectorUtils.getLong(bufferIter.next(), loi);
        return l.intValue();
    //return bufferIter.next().intValue();
    } else {
        throw new IOException();
    }
}
Also used : LongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector) LazyLong(org.apache.hadoop.hive.serde2.lazy.LazyLong) IOException(java.io.IOException)

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