use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.doubleTypeInfo 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(14.5, res.get(), EPSILON);
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.doubleTypeInfo in project hive by apache.
the class GenericUDFBaseNwayCompare method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length < 2) {
throw new UDFArgumentLengthException(getFuncName() + " requires at least 2 arguments, got " + arguments.length);
}
if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
throw new UDFArgumentException(getFuncName() + " only takes primitive types, got " + arguments[0].getTypeName());
}
argumentOIs = arguments;
converters = new Converter[arguments.length];
TypeInfo commonInfo = TypeInfoUtils.getTypeInfoFromObjectInspector(arguments[0]);
for (int i = 1; i < arguments.length; i++) {
PrimitiveTypeInfo currInfo = (PrimitiveTypeInfo) TypeInfoUtils.getTypeInfoFromObjectInspector(arguments[i]);
commonInfo = FunctionRegistry.getCommonClassForComparison(commonInfo, currInfo);
}
resultOI = TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo((commonInfo == null) ? TypeInfoFactory.doubleTypeInfo : commonInfo);
for (int i = 0; i < arguments.length; i++) {
converters[i] = ObjectInspectorConverters.getConverter(arguments[i], resultOI);
}
return resultOI;
}
Aggregations