use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFAddMonths method runAndVerify.
private void runAndVerify(String str, byte months, String expResult, GenericUDF udf) throws HiveException {
DeferredObject valueObj0 = new DeferredJavaObject(new Text(str));
DeferredObject valueObj1 = new DeferredJavaObject(new ByteWritable(months));
DeferredObject[] args = { valueObj0, valueObj1 };
Text output = (Text) udf.evaluate(args);
assertEquals("add_months() test ", expResult, output != null ? output.toString() : null);
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFOPPlus method testTimestampPlusIntervalYearMonth.
@Test
public void testTimestampPlusIntervalYearMonth() throws Exception {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
TimestampWritable left = new TimestampWritable(Timestamp.valueOf("2001-11-15 01:02:03.123456789"));
HiveIntervalYearMonthWritable right = new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-2"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableTimestampObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
TimestampWritable res = (TimestampWritable) udf.evaluate(args);
Assert.assertEquals(Timestamp.valueOf("2004-01-15 01:02:03.123456789"), res.getTimestamp());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFOPPlus method testTimestampPlusIntervalDayTime.
@Test
public void testTimestampPlusIntervalDayTime() throws Exception {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
TimestampWritable left = new TimestampWritable(Timestamp.valueOf("2001-01-01 00:00:00"));
HiveIntervalDayTimeWritable right = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableTimestampObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
TimestampWritable res = (TimestampWritable) udf.evaluate(args);
Assert.assertEquals(Timestamp.valueOf("2001-01-02 2:3:4.567"), res.getTimestamp());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFOPPositive method testShort.
@Test
public void testShort() throws HiveException {
GenericUDFOPPositive udf = new GenericUDFOPPositive();
ShortWritable input = new ShortWritable((short) 74);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableShortObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.shortTypeInfo, oi.getTypeInfo());
ShortWritable res = (ShortWritable) udf.evaluate(args);
Assert.assertEquals((short) 74, res.get());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFOPPositive method testDecimal.
@Test
public void testDecimal() throws HiveException {
GenericUDFOPPositive udf = new GenericUDFOPPositive();
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(inputTypeInfo, oi.getTypeInfo());
HiveDecimalWritable res = (HiveDecimalWritable) udf.evaluate(args);
Assert.assertEquals(HiveDecimal.create("32300.004747"), res.getHiveDecimal());
}
Aggregations