use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject 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.ql.udf.generic.GenericUDF.DeferredJavaObject 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.ql.udf.generic.GenericUDF.DeferredJavaObject 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.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFSha2 method runAndVerifyStr.
private void runAndVerifyStr(String str, IntWritable lenWr, String expResult, GenericUDFSha2 udf) throws HiveException {
DeferredObject valueObj0 = new DeferredJavaObject(str != null ? new Text(str) : null);
DeferredObject valueObj1 = new DeferredJavaObject(lenWr);
DeferredObject[] args = { valueObj0, valueObj1 };
Text output = (Text) udf.evaluate(args);
assertEquals("sha2() test ", expResult, output != null ? output.toString() : null);
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject 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(new Float(-323.4747f), new Float(res.get()));
}
Aggregations