use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFOPPlus method testIntervalYearMonthPlusDate.
@Test
public void testIntervalYearMonthPlusDate() throws Exception {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
HiveIntervalYearMonthWritable left = new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-8"));
DateWritable right = new DateWritable(Date.valueOf("2001-06-15"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector, PrimitiveObjectInspectorFactory.writableDateObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.dateTypeInfo, oi.getTypeInfo());
DateWritable res = (DateWritable) udf.evaluate(args);
Assert.assertEquals(Date.valueOf("2004-02-15"), res.get());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFOPPlus method testFloatPlusFloat.
@Test
public void testFloatPlusFloat() throws HiveException {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
// 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) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.floatTypeInfo);
FloatWritable res = (FloatWritable) udf.evaluate(args);
Assert.assertEquals(new Float(4.5), new Float(res.get()));
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFQuarter method runAndVerifyDt.
private void runAndVerifyDt(String str, Integer expResult, GenericUDF udf) throws HiveException {
DeferredObject valueObj0 = new DeferredJavaObject(str != null ? new DateWritable(Date.valueOf(str)) : null);
DeferredObject[] args = { valueObj0 };
IntWritable output = (IntWritable) udf.evaluate(args);
if (expResult == null) {
assertNull(output);
} else {
assertNotNull(output);
assertEquals("quarter() test ", expResult.intValue(), output.get());
}
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFSoundex method runAndVerify.
private void runAndVerify(String str0, String expResult, GenericUDF udf) throws HiveException {
DeferredObject valueObj0 = new DeferredJavaObject(str0 != null ? new Text(str0) : null);
DeferredObject[] args = { valueObj0 };
Text output = (Text) udf.evaluate(args);
if (expResult == null) {
assertNull("soundex test ", output);
} else {
assertNotNull("soundex test", output);
assertEquals("soundex test", expResult, output.toString());
}
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.
the class TestGenericUDFSubstringIndex method runAndVerifyConst.
private void runAndVerifyConst(String str, String expResult, GenericUDF udf) throws HiveException {
DeferredObject valueObj0 = new DeferredJavaObject(str != null ? new Text(str) : null);
DeferredObject[] args = { valueObj0 };
Text output = (Text) udf.evaluate(args);
assertEquals("substring_index() test ", expResult, output != null ? output.toString() : null);
}
Aggregations