use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector in project hive by apache.
the class TestGenericUDFOPMultiply method testDouleTimesDecimal.
@Test
public void testDouleTimesDecimal() throws HiveException {
GenericUDFOPMultiply udf = new GenericUDFOPMultiply();
DoubleWritable left = new DoubleWritable(74.52);
HiveDecimalWritable right = new HiveDecimalWritable(HiveDecimal.create("234.97"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(5, 2)) };
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(17509.9644), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector in project hive by apache.
the class TestGenericUDFSortArrayByField method testSortPrimitiveTupleOneFieldOrderASC.
@Test
public void testSortPrimitiveTupleOneFieldOrderASC() throws HiveException {
List<ObjectInspector> tuple = new ArrayList<ObjectInspector>();
tuple.add(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
tuple.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
ObjectInspector[] inputOIs = { ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(asList("Company", "Salary"), tuple)), PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector, PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector };
udf.initialize(inputOIs);
Object i1 = asList(new Text("Facebook"), new DoubleWritable(80223.25));
Object i2 = asList(new Text("Facebook"), new DoubleWritable(50223.25));
Object i3 = asList(new Text("Facebook"), new DoubleWritable(40223.25));
Object i4 = asList(new Text("Facebook"), new DoubleWritable(60223.25));
HiveVarchar vc = new HiveVarchar();
vc.setValue("Salary");
HiveVarchar order = new HiveVarchar();
order.setValue("ASC");
GenericUDF.DeferredJavaObject[] argas = { new GenericUDF.DeferredJavaObject(asList(i1, i2, i3, i4)), new GenericUDF.DeferredJavaObject(new HiveVarcharWritable(vc)), new GenericUDF.DeferredJavaObject(new HiveVarcharWritable(order)) };
runAndVerify(argas, asList(i3, i2, i4, i1));
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector in project hive by apache.
the class TestGenericUDFSortArrayByField method testSortPrimitiveTupleOneField.
@Test
public void testSortPrimitiveTupleOneField() throws HiveException {
List<ObjectInspector> tuple = new ArrayList<ObjectInspector>();
tuple.add(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
tuple.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
ObjectInspector[] inputOIs = { ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(asList("Company", "Salary"), tuple)), PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector };
udf.initialize(inputOIs);
Object i1 = asList(new Text("Facebook"), new DoubleWritable(80223.25));
Object i2 = asList(new Text("Facebook"), new DoubleWritable(50223.25));
Object i3 = asList(new Text("Facebook"), new DoubleWritable(40223.25));
Object i4 = asList(new Text("Facebook"), new DoubleWritable(60223.25));
HiveVarchar vc = new HiveVarchar();
vc.setValue("Salary");
GenericUDF.DeferredJavaObject[] argas = { new GenericUDF.DeferredJavaObject(asList(i1, i2, i3, i4)), new GenericUDF.DeferredJavaObject(new HiveVarcharWritable(vc)) };
runAndVerify(argas, asList(i3, i2, i4, i1));
}
Aggregations