use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFCeil method testDouble.
@Test
public void testDouble() throws HiveException {
GenericUDFCeil udf = new GenericUDFCeil();
DoubleWritable input = new DoubleWritable(32300.004747);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector };
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(32301L, res.get());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFCeil method testDecimal.
@Test
public void testDecimal() throws HiveException {
GenericUDFCeil udf = new GenericUDFCeil();
HiveDecimalWritable input = new HiveDecimalWritable(HiveDecimal.create("32300.004747"));
DecimalTypeInfo inputTypeInfo = TypeInfoFactory.getDecimalTypeInfo(11, 6);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo) };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(6, 0), oi.getTypeInfo());
HiveDecimalWritable res = (HiveDecimalWritable) udf.evaluate(args);
Assert.assertEquals(HiveDecimal.create("32301"), res.getHiveDecimal());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFCeil method testByte.
@Test
public void testByte() throws HiveException {
GenericUDFCeil udf = new GenericUDFCeil();
ByteWritable input = new ByteWritable((byte) 4);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableByteObjectInspector };
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(4L, res.get());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFLpad method runAndVerify.
private void runAndVerify(String str, int len, String pad, String expResult, GenericUDF udf) throws HiveException {
DeferredObject valueObj1 = new DeferredJavaObject(new Text(str));
DeferredObject valueObj2 = new DeferredJavaObject(new IntWritable(len));
DeferredObject valueObj3 = new DeferredJavaObject(new Text(pad));
DeferredObject[] args = { valueObj1, valueObj2, valueObj3 };
Object output = udf.evaluate(args);
if (expResult != null) {
assertEquals("lpad() test ", expResult, output.toString());
} else {
assertNull("lpad() test ", output);
}
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFMonthsBetween method runTestTs.
protected void runTestTs(String ts1, String ts2, Double expDiff, GenericUDFMonthsBetween udf) throws HiveException {
TimestampWritable tsWr1 = ts1 == null ? null : new TimestampWritable(Timestamp.valueOf(ts1));
TimestampWritable tsWr2 = ts2 == null ? null : new TimestampWritable(Timestamp.valueOf(ts2));
DeferredJavaObject valueObj1 = new DeferredJavaObject(tsWr1);
DeferredJavaObject valueObj2 = new DeferredJavaObject(tsWr2);
DeferredObject[] args = new DeferredObject[] { valueObj1, valueObj2 };
DoubleWritable output = (DoubleWritable) udf.evaluate(args);
if (expDiff == null) {
assertNull("months_between() test for NULL TIMESTAMP failed", output);
} else {
assertNotNull("months_between() test for NOT NULL TIMESTAMP failed", output);
assertEquals("months_between() test for TIMESTAMP failed", expDiff, output.get(), 0.00000001D);
}
}
Aggregations