use of org.apache.hadoop.io.FloatWritable in project hive by apache.
the class TestETypeConverter method testGetFloatConverter.
@Test
public void testGetFloatConverter() throws Exception {
MyConverterParent converterParent = new MyConverterParent();
PrimitiveType primitiveType = Types.optional(PrimitiveTypeName.FLOAT).named("value");
PrimitiveConverter converter = ETypeConverter.getNewConverter(primitiveType, 1, converterParent, null);
((PrimitiveConverter) converter).addFloat(3276f);
Writable writable = converterParent.getValue();
FloatWritable floatWritable = (FloatWritable) writable;
assertEquals(3276f, floatWritable.get(), 0);
}
use of org.apache.hadoop.io.FloatWritable in project hive by apache.
the class TestGenericUDFAbs method testFloat.
@Test
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.io.FloatWritable in project hive by apache.
the class WritableHiveCharObjectInspector method getPrimitiveWritableObject.
@Override
public HiveCharWritable getPrimitiveWritableObject(Object o) {
// then output new writable with correct params.
if (o == null) {
return null;
}
if ((o instanceof Text) || (o instanceof TimestampWritableV2) || (o instanceof HiveDecimalWritable) || (o instanceof DoubleWritable) || (o instanceof FloatWritable) || (o instanceof LongWritable) || (o instanceof IntWritable) || (o instanceof BooleanWritable)) {
String str = o.toString();
HiveCharWritable hcw = new HiveCharWritable();
hcw.set(str, ((CharTypeInfo) typeInfo).getLength());
return hcw;
}
HiveCharWritable writable = ((HiveCharWritable) o);
if (doesWritableMatchTypeParams((HiveCharWritable) o)) {
return writable;
}
return getWritableWithParams(writable);
}
use of org.apache.hadoop.io.FloatWritable in project hive by apache.
the class TestGenericUDFOPNegative method testFloat.
@Test
public void testFloat() throws HiveException {
GenericUDFOPNegative udf = new GenericUDFOPNegative();
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(-323.4747f, res.get(), EPSILON);
}
use of org.apache.hadoop.io.FloatWritable in project hive by apache.
the class TestGenericUDFOPPlus method testFloatPlusFloat.
@Test
public void testFloatPlusFloat() throws HiveException {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
// 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) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.floatTypeInfo);
FloatWritable res = (FloatWritable) udf.evaluate(args);
Assert.assertEquals(4.5, res.get(), EPSILON);
}
Aggregations