use of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector in project hive by apache.
the class TestGenericUDFOPDivide method testVarcharDivideInt.
@Test
public void testVarcharDivideInt() throws HiveException {
GenericUDFOPDivide udf = new GenericUDFOPDivide();
HiveVarcharWritable left = new HiveVarcharWritable();
left.set("123");
IntWritable right = new IntWritable(456);
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(123.0 / 456.0), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector in project hive by apache.
the class TestGenericUDFOPDivide method testDoubleDivideLong.
@Test
public void testDoubleDivideLong() throws HiveException {
GenericUDFOPDivide udf = new GenericUDFOPDivide();
DoubleWritable left = new DoubleWritable(4.5);
LongWritable right = new LongWritable(10);
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(0.45), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector in project hive by apache.
the class TestGenericUDFOPDivide method testDouleDivideDecimal.
@Test
public void testDouleDivideDecimal() throws HiveException {
GenericUDFOPDivide udf = new GenericUDFOPDivide();
DoubleWritable left = new DoubleWritable(74.52);
HiveDecimalWritable right = new HiveDecimalWritable(HiveDecimal.create("234.97"));
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(new Double(74.52 / 234.97), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector in project hive by apache.
the class TestGenericUDFOPDivide method testDecimalDivisionResultType.
private void testDecimalDivisionResultType(int prec1, int scale1, int prec2, int scale2, int prec3, int scale3) throws HiveException {
GenericUDFOPDivide udf = new GenericUDFOPDivide();
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(prec1, scale1)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(prec2, scale2)) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(prec3, scale3), oi.getTypeInfo());
}
use of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector in project hive by apache.
the class TestGenericUDFCeil method testShort.
@Test
public void testShort() throws HiveException {
GenericUDFCeil udf = new GenericUDFCeil();
ShortWritable input = new ShortWritable((short) -74);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableShortObjectInspector };
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(-74L, res.get());
}
Aggregations