use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableFloatObjectInspector in project hive by apache.
the class TestGenericUDFFloor method testFloat.
@Test
public void testFloat() throws HiveException {
GenericUDFFloor udf = new GenericUDFFloor();
FloatWritable input = new FloatWritable(-323.4747f);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.longTypeInfo, oi.getTypeInfo());
LongWritable res = (LongWritable) udf.evaluate(args);
Assert.assertEquals(-324L, res.get());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableFloatObjectInspector in project hive by apache.
the class TestGenericUDFBRound method testFloat.
@Test
public void testFloat() throws HiveException {
GenericUDFBRound udf = new GenericUDFBRound();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
IntWritable scale = new IntWritable(0);
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, scale);
ObjectInspector[] arguments = { valueOI0, valueOI1 };
udf.initialize(arguments);
runFloat(2.5f, scale, 2.0f, udf);
runFloat(3.5f, scale, 4.0f, udf);
runFloat(2.49f, scale, 2.0f, udf);
runFloat(3.49f, scale, 3.0f, udf);
runFloat(2.51f, scale, 3.0f, udf);
runFloat(3.51f, scale, 4.0f, udf);
runFloat(2.4f, scale, 2.0f, udf);
runFloat(3.4f, scale, 3.0f, udf);
runFloat(2.6f, scale, 3.0f, udf);
runFloat(3.6f, scale, 4.0f, udf);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableFloatObjectInspector in project hive by apache.
the class TestGenericUDFCeil method testFloat.
@Test
public void testFloat() throws HiveException {
GenericUDFCeil udf = new GenericUDFCeil();
FloatWritable input = new FloatWritable(323.4747f);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.longTypeInfo, oi.getTypeInfo());
LongWritable res = (LongWritable) udf.evaluate(args);
Assert.assertEquals(324L, res.get());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableFloatObjectInspector in project hive by apache.
the class TestGenericUDFOPMinus method testFloatMinusFloat.
@Test
public void testFloatMinusFloat() throws HiveException {
GenericUDFOPMinus udf = new GenericUDFOPMinus();
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) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.floatTypeInfo);
FloatWritable res = (FloatWritable) udf.evaluate(args);
Assert.assertEquals(new Float(4.5), new Float(res.get()));
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableFloatObjectInspector in project hive by apache.
the class TestGenericUDFOPMod method testModByZero5.
@Test
public void testModByZero5() throws HiveException {
GenericUDFOPMod udf = new GenericUDFOPMod();
// 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);
DoubleWritable f3 = (DoubleWritable) udf.evaluate(args);
Assert.assertNull(f3);
}
Aggregations