use of org.apache.hadoop.hive.serde2.io.DateWritableV2 in project hive by apache.
the class TestGenericUDFNullif method testDateCompareEq.
@Test
public void testDateCompareEq() throws HiveException {
GenericUDFNullif udf = new GenericUDFNullif();
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, PrimitiveObjectInspectorFactory.writableDateObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(new DateWritableV2(4)), new DeferredJavaObject(new DateWritableV2(4)) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.dateTypeInfo, oi.getTypeInfo());
Assert.assertEquals(null, udf.evaluate(args));
}
use of org.apache.hadoop.hive.serde2.io.DateWritableV2 in project hive by apache.
the class TestGenericUDFNullif method testNotSupportedArgumentMix.
@Test(expected = UDFArgumentException.class)
public void testNotSupportedArgumentMix() throws HiveException {
GenericUDFNullif udf = new GenericUDFNullif();
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, PrimitiveObjectInspectorFactory.writableByteObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(new DateWritableV2(4)), new DeferredJavaObject(new ByteWritable((byte) 4)) };
udf.initialize(inputOIs);
}
use of org.apache.hadoop.hive.serde2.io.DateWritableV2 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"));
DateWritableV2 right = new DateWritableV2(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());
DateWritableV2 res = (DateWritableV2) udf.evaluate(args);
Assert.assertEquals(Date.valueOf("2004-02-15"), res.get());
}
use of org.apache.hadoop.hive.serde2.io.DateWritableV2 in project hive by apache.
the class TestGenericUDFDateSub method testTimestampToDate.
@Test
public void testTimestampToDate() throws HiveException {
GenericUDFDateSub udf = new GenericUDFDateSub();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new TimestampWritableV2(Timestamp.valueOf(LocalDateTime.of(109, 06, 20, 4, 17, 52, 0).toString())));
DeferredObject valueObj2 = new DeferredJavaObject(Integer.valueOf(3));
DeferredObject[] args = { valueObj1, valueObj2 };
DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
assertEquals("date_sub() test for TIMESTAMP failed ", "0109-06-17", output.toString());
// Test with null args
args = new DeferredObject[] { new DeferredJavaObject(null), valueObj2 };
assertNull("date_add() 1st arg null", udf.evaluate(args));
args = new DeferredObject[] { valueObj1, new DeferredJavaObject(null) };
assertNull("date_add() 2nd arg null", udf.evaluate(args));
args = new DeferredObject[] { new DeferredJavaObject(null), new DeferredJavaObject(null) };
assertNull("date_add() both args null", udf.evaluate(args));
}
use of org.apache.hadoop.hive.serde2.io.DateWritableV2 in project hive by apache.
the class TestGenericUDFDateSub method testStringToDate.
@Test
public void testStringToDate() throws HiveException {
GenericUDFDateSub udf = new GenericUDFDateSub();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new Text("2009-07-20 04:17:52"));
DeferredObject valueObj2 = new DeferredJavaObject(Integer.valueOf(2));
DeferredObject[] args = { valueObj1, valueObj2 };
DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
assertEquals("date_sub() test for STRING failed ", "2009-07-18", output.toString());
// Test with null args
args = new DeferredObject[] { new DeferredJavaObject(null), valueObj2 };
assertNull("date_add() 1st arg null", udf.evaluate(args));
args = new DeferredObject[] { valueObj1, new DeferredJavaObject(null) };
assertNull("date_add() 2nd arg null", udf.evaluate(args));
args = new DeferredObject[] { new DeferredJavaObject(null), new DeferredJavaObject(null) };
assertNull("date_add() both args null", udf.evaluate(args));
}
Aggregations