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));
}
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()));
}
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;
}
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;
}
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();
}
}
Aggregations