use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getDecimalTypeInfo in project hive by apache.
the class TestGenericUDFOPMinus method testLongMinusDecimal.
@Test
public void testLongMinusDecimal() throws HiveException {
GenericUDFOPMinus udf = new GenericUDFOPMinus();
LongWritable left = new LongWritable(104);
HiveDecimalWritable right = new HiveDecimalWritable(HiveDecimal.create("234.97"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableLongObjectInspector, PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(9, 4)) };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(24, 4), oi.getTypeInfo());
HiveDecimalWritable res = (HiveDecimalWritable) udf.evaluate(args);
Assert.assertEquals(HiveDecimal.create("-130.97"), res.getHiveDecimal());
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getDecimalTypeInfo in project hive by apache.
the class TestGenericUDFPower method testLongPowerDecimal.
@Test
public void testLongPowerDecimal() throws HiveException {
GenericUDFPower udf = new GenericUDFPower();
LongWritable left = new LongWritable(10);
HiveDecimalWritable right = new HiveDecimalWritable(HiveDecimal.create("3.14"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableLongObjectInspector, PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(9, 4)) };
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(1380.3842646028852, res.get(), EPSILON);
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getDecimalTypeInfo in project hive by apache.
the class TestGenericUDFRound method testDecimalRoundingMetaData.
@Test
public void testDecimalRoundingMetaData() throws UDFArgumentException {
GenericUDFRound udf = new GenericUDFRound();
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(7, 3)), PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, new IntWritable(2)) };
PrimitiveObjectInspector outputOI = (PrimitiveObjectInspector) udf.initialize(inputOIs);
DecimalTypeInfo outputTypeInfo = (DecimalTypeInfo) outputOI.getTypeInfo();
Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(7, 2), outputTypeInfo);
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getDecimalTypeInfo in project hive by apache.
the class TestGenericUDFRound method testDecimalRoundingMetaData2.
@Test
public void testDecimalRoundingMetaData2() throws UDFArgumentException {
GenericUDFRound udf = new GenericUDFRound();
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(7, 3)), PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, new IntWritable(5)) };
PrimitiveObjectInspector outputOI = (PrimitiveObjectInspector) udf.initialize(inputOIs);
DecimalTypeInfo outputTypeInfo = (DecimalTypeInfo) outputOI.getTypeInfo();
Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(9, 5), outputTypeInfo);
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getDecimalTypeInfo in project hive by apache.
the class TestGenericUDFOPPlus method testDecimalPlusDecimal.
@Test
public void testDecimalPlusDecimal() throws HiveException {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
// Decimal
HiveDecimalWritable left = new HiveDecimalWritable(HiveDecimal.create("14.5"));
HiveDecimalWritable right = new HiveDecimalWritable(HiveDecimal.create("234.97"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(3, 1)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(5, 2)) };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(6, 2), oi.getTypeInfo());
HiveDecimalWritable res = (HiveDecimalWritable) udf.evaluate(args);
Assert.assertEquals(HiveDecimal.create("249.47"), res.getHiveDecimal());
}
Aggregations