use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableFloatObjectInspector in project hive by apache.
the class TestGenericUDFAbs method testFloat.
public void testFloat() throws HiveException {
GenericUDFAbs udf = new GenericUDFAbs();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
DeferredObject valueObj = new DeferredJavaObject(new FloatWritable(107.78f));
DeferredObject[] args = { valueObj };
DoubleWritable output = (DoubleWritable) udf.evaluate(args);
// Make sure flow and double equality compare works
assertTrue("abs() test for Float failed ", Math.abs(107.78 - output.get()) < 0.0001);
valueObj = new DeferredJavaObject(new FloatWritable(-107.78f));
args[0] = valueObj;
output = (DoubleWritable) udf.evaluate(args);
assertTrue("abs() test for Float failed ", Math.abs(107.78 - output.get()) < 0.0001);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableFloatObjectInspector in project hive by apache.
the class TestGenericUDFOPPositive method testFloat.
@Test
public void testFloat() throws HiveException {
GenericUDFOPPositive udf = new GenericUDFOPPositive();
FloatWritable input = new FloatWritable(323.4747f);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.floatTypeInfo, oi.getTypeInfo());
FloatWritable res = (FloatWritable) udf.evaluate(args);
Assert.assertEquals(new Float(323.4747f), new Float(res.get()));
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableFloatObjectInspector in project hive by apache.
the class TestGenericUDFPosMod method testPosModByZero5.
@Test
public void testPosModByZero5() throws HiveException {
GenericUDFPosMod udf = new GenericUDFPosMod();
// Float
FloatWritable f1 = new FloatWritable(4.5f);
FloatWritable f2 = new FloatWritable(0.0f);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableFloatObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(f1), new DeferredJavaObject(f2) };
udf.initialize(inputOIs);
FloatWritable f3 = (FloatWritable) udf.evaluate(args);
Assert.assertNull(f3);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableFloatObjectInspector in project hive by apache.
the class TestGenericUDFPower method testFloatPowerFloat.
@Test
public void testFloatPowerFloat() throws HiveException {
GenericUDFPower udf = new GenericUDFPower();
FloatWritable f1 = new FloatWritable(4.5f);
FloatWritable f2 = new FloatWritable(-1.5f);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableFloatObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(f1), new DeferredJavaObject(f2) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.doubleTypeInfo);
DoubleWritable res = (DoubleWritable) udf.evaluate(args);
Assert.assertEquals(new Double(0.10475656017578482), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableFloatObjectInspector in project hive by apache.
the class TestGenericUDFPower method testShortPowerFloat.
@Test
public void testShortPowerFloat() throws HiveException {
GenericUDFPower udf = new GenericUDFPower();
ShortWritable base = new ShortWritable((short) 23);
FloatWritable power = new FloatWritable(-1.5f);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableShortObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(base), new DeferredJavaObject(power) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.doubleTypeInfo);
DoubleWritable res = (DoubleWritable) udf.evaluate(args);
Assert.assertEquals(new Double(0.009065844089438033), new Double(res.get()));
}
Aggregations