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(new Double(14.5), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.doubleTypeInfo in project hive by apache.
the class TestGenericUDFOPPlus method testVarcharPlusInt.
@Test
public void testVarcharPlusInt() throws HiveException {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
// Short
HiveVarcharWritable left = new HiveVarcharWritable();
left.set("123");
IntWritable right = new IntWritable(456);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.doubleTypeInfo);
DoubleWritable res = (DoubleWritable) udf.evaluate(args);
Assert.assertEquals(new Double(579.0), new Double(res.get()));
}
Aggregations