use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFPosMod method testPosModByZero5.
@Test
public void testPosModByZero5() throws HiveException {
GenericUDFPosMod udf = new GenericUDFPosMod();
// Float
FloatWritable f1 = new FloatWritable(4.5f);
FloatWritable f2 = new FloatWritable(0.0f);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableFloatObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(f1), new DeferredJavaObject(f2) };
udf.initialize(inputOIs);
FloatWritable f3 = (FloatWritable) udf.evaluate(args);
Assert.assertNull(f3);
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFPosMod method testPosModByZero1.
@Test
public void testPosModByZero1() throws HiveException {
GenericUDFPosMod udf = new GenericUDFPosMod();
// Byte
ByteWritable b1 = new ByteWritable((byte) 4);
ByteWritable b2 = new ByteWritable((byte) 0);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableByteObjectInspector, PrimitiveObjectInspectorFactory.writableByteObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(b1), new DeferredJavaObject(b2) };
udf.initialize(inputOIs);
ByteWritable b3 = (ByteWritable) udf.evaluate(args);
Assert.assertNull(b3);
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFPosMod method testPosModByZero2.
@Test
public void testPosModByZero2() throws HiveException {
GenericUDFPosMod udf = new GenericUDFPosMod();
// Short
ShortWritable s1 = new ShortWritable((short) 4);
ShortWritable s2 = new ShortWritable((short) 0);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableShortObjectInspector, PrimitiveObjectInspectorFactory.writableShortObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(s1), new DeferredJavaObject(s2) };
udf.initialize(inputOIs);
ShortWritable s3 = (ShortWritable) udf.evaluate(args);
Assert.assertNull(s3);
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject 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.ql.udf.generic.GenericUDF.DeferredJavaObject 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()));
}
Aggregations