use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFFloor method testLong.
@Test
public void testLong() throws HiveException {
GenericUDFFloor udf = new GenericUDFFloor();
LongWritable input = new LongWritable(3234747);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableLongObjectInspector };
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(3234747L, res.get());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFDate method testDateWritablepToDate.
public void testDateWritablepToDate() throws HiveException {
GenericUDFDate udf = new GenericUDFDate();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
DeferredObject valueObj = new DeferredJavaObject(new DateWritable(new Date(109, 06, 30)));
DeferredObject[] args = { valueObj };
DateWritable output = (DateWritable) udf.evaluate(args);
assertEquals("to_date() test for DATEWRITABLE failed ", "2009-07-30", output.toString());
// Try with null args
DeferredObject[] nullArgs = { new DeferredJavaObject(null) };
output = (DateWritable) udf.evaluate(nullArgs);
assertNull("to_date() with null DATE", output);
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFDate method testStringToDate.
public void testStringToDate() throws HiveException {
GenericUDFDate udf = new GenericUDFDate();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
DeferredObject valueObj = new DeferredJavaObject(new Text("2009-07-30"));
DeferredObject[] args = { valueObj };
DateWritable output = (DateWritable) udf.evaluate(args);
assertEquals("to_date() test for STRING failed ", "2009-07-30", output.toString());
// Try with null args
DeferredObject[] nullArgs = { new DeferredJavaObject(null) };
output = (DateWritable) udf.evaluate(nullArgs);
assertNull("to_date() with null STRING", output);
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFAesEncrypt method runAndVerifyStr.
private void runAndVerifyStr(String str, Text keyWr, String expResultBase64, GenericUDFAesEncrypt udf) throws HiveException {
DeferredObject valueObj0 = new DeferredJavaObject(str != null ? new Text(str) : null);
DeferredObject valueObj1 = new DeferredJavaObject(keyWr);
DeferredObject[] args = { valueObj0, valueObj1 };
BytesWritable output = (BytesWritable) udf.evaluate(args);
assertEquals("aes_encrypt() test ", expResultBase64, output != null ? copyBytesAndBase64(output) : null);
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFTrim method runAndVerify.
private void runAndVerify(String str, String expResult, GenericUDF udf) throws HiveException {
DeferredObject valueObj = new DeferredJavaObject(new Text(str));
DeferredObject[] args = { valueObj };
Text output = (Text) udf.evaluate(args);
assertEquals("trim() test ", expResult, output.toString());
}
Aggregations