use of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector 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.PrimitiveObjectInspector in project hive by apache.
the class TestGenericUDFPower method testVarcharPowerInt.
@Test
public void testVarcharPowerInt() throws HiveException {
GenericUDFPower udf = new GenericUDFPower();
HiveVarcharWritable left = new HiveVarcharWritable();
left.set("3.14");
IntWritable right = new IntWritable(2);
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(3.14 * 3.14), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector in project hive by apache.
the class TestGenericUDFPower method testDoublePowerLong.
@Test
public void testDoublePowerLong() throws HiveException {
GenericUDFPower udf = new GenericUDFPower();
DoubleWritable left = new DoubleWritable(4.5);
LongWritable right = new LongWritable(4);
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(4.5 * 4.5 * 4.5 * 4.5), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector 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.PrimitiveObjectInspector in project hive by apache.
the class TestGenericUDFPower method testDoulePowerDecimal.
@Test
public void testDoulePowerDecimal() throws HiveException {
GenericUDFPower udf = new GenericUDFPower();
DoubleWritable left = new DoubleWritable(-4.52);
HiveDecimalWritable right = new HiveDecimalWritable(HiveDecimal.create("3"));
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("Unexpected result", new Double(-4.52 * 4.52 * 4.52), new Double(res.get()), 1e-6);
}
Aggregations