use of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector in project hive by apache.
the class TestGenericUDFOPMinus method testDecimalMinusDecimalSameParams.
@Test
public void testDecimalMinusDecimalSameParams() throws HiveException {
GenericUDFOPMinus udf = new GenericUDFOPMinus();
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(5, 2)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(5, 2)) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(6, 2), oi.getTypeInfo());
}
use of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector in project hive by apache.
the class TestGenericUDFOPMinus method testDoubleMinusLong.
@Test
public void testDoubleMinusLong() throws HiveException {
GenericUDFOPMinus udf = new GenericUDFOPMinus();
// Int
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(-5.5), new Double(res.get()));
}
use of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector in project hive by apache.
the class TestGenericUDFOPMinus method testDecimalMinusDecimal.
@Test
public void testDecimalMinusDecimal() throws HiveException {
GenericUDFOPMinus udf = new GenericUDFOPMinus();
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("-220.47"), res.getHiveDecimal());
}
use of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector in project hive by apache.
the class TestGenericUDFOPMinus method testTimestampMinusIntervalDayTime.
@Test
public void testTimestampMinusIntervalDayTime() throws Exception {
GenericUDFOPMinus udf = new GenericUDFOPMinus();
TimestampWritable left = new TimestampWritable(Timestamp.valueOf("2001-01-02 2:3:4.567"));
HiveIntervalDayTimeWritable right = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableTimestampObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
TimestampWritable res = (TimestampWritable) udf.evaluate(args);
Assert.assertEquals(Timestamp.valueOf("2001-01-01 00:00:00"), res.getTimestamp());
}
use of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector in project hive by apache.
the class TestGenericUDFRound method testDecimalRoundingMetaData1.
@Test
public void testDecimalRoundingMetaData1() 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(5, 0), outputTypeInfo);
}
Aggregations