use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFPrintf method testCharFormat.
@Test
public void testCharFormat() throws HiveException {
GenericUDFPrintf udf = new GenericUDFPrintf();
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getCharTypeInfo(10)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getVarcharTypeInfo(7)) };
HiveCharWritable formatChar = new HiveCharWritable();
formatChar.set("arg1=%s");
HiveVarcharWritable argVarchar = new HiveVarcharWritable();
argVarchar.set("world");
DeferredObject[] args = { new DeferredJavaObject(formatChar), new DeferredJavaObject(argVarchar) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(PrimitiveObjectInspectorFactory.writableStringObjectInspector, oi);
Text res = (Text) udf.evaluate(args);
Assert.assertEquals("arg1=world", res.toString());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFOPMod method testModByZero1.
@Test
public void testModByZero1() throws HiveException {
GenericUDFOPMod udf = new GenericUDFOPMod();
// 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 TestGenericUDFOPMod method testModByZero8.
@Test
public void testModByZero8() throws HiveException {
GenericUDFOPMod udf = new GenericUDFOPMod();
// Decimal
HiveDecimalWritable dec1 = new HiveDecimalWritable(HiveDecimal.create("4.5"));
HiveDecimalWritable dec2 = new HiveDecimalWritable(HiveDecimal.create("0"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(2, 1)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(1, 0)) };
DeferredObject[] args = { new DeferredJavaObject(dec1), new DeferredJavaObject(dec2) };
udf.initialize(inputOIs);
HiveDecimalWritable dec3 = (HiveDecimalWritable) udf.evaluate(args);
Assert.assertNull(dec3);
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFOPMod method testModByZero3.
@Test
public void testModByZero3() throws HiveException {
GenericUDFOPMod udf = new GenericUDFOPMod();
// Int
IntWritable i1 = new IntWritable(4);
IntWritable i2 = new IntWritable(0);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableIntObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(i1), new DeferredJavaObject(i2) };
udf.initialize(inputOIs);
IntWritable i3 = (IntWritable) udf.evaluate(args);
Assert.assertNull(i3);
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFOPMod method testModByZero6.
@Test
public void testModByZero6() throws HiveException {
GenericUDFOPMod udf = new GenericUDFOPMod();
// Double
DoubleWritable d1 = new DoubleWritable(4.5);
DoubleWritable d2 = new DoubleWritable(0.0);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(d1), new DeferredJavaObject(d2) };
udf.initialize(inputOIs);
DoubleWritable d3 = (DoubleWritable) udf.evaluate(args);
Assert.assertNull(d3);
}
Aggregations