use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class TestGenericUDFOPPlus method testDatePlusIntervalDayTime.
@Test
public void testDatePlusIntervalDayTime() throws Exception {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
DateWritable left = new DateWritable(Date.valueOf("2001-01-01"));
HiveIntervalDayTimeWritable right = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
// Date + day-time interval = timestamp
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.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class TestGenericUDFOPPlus method testDatePlusIntervalYearMonth.
@Test
public void testDatePlusIntervalYearMonth() throws Exception {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
DateWritable left = new DateWritable(Date.valueOf("2001-06-15"));
HiveIntervalYearMonthWritable right = new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-8"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector };
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.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class TestGenericUDFOPPlus method testIntervalDayTimePlusDate.
@Test
public void testIntervalDayTimePlusDate() throws Exception {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
HiveIntervalDayTimeWritable left = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567"));
DateWritable right = new DateWritable(Date.valueOf("2001-01-01"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector, PrimitiveObjectInspectorFactory.writableDateObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
// Date + day-time interval = timestamp
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.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class TestGenericUDFGreatest method testGreatestDate.
public void testGreatestDate() throws HiveException {
GenericUDFGreatest udf = new GenericUDFGreatest();
ObjectInspector[] arguments = new ObjectInspector[3];
for (int i = 0; i < arguments.length; i++) {
arguments[i] = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
}
udf.initialize(arguments);
Date d1 = Date.valueOf("2015-03-20");
Date d2 = Date.valueOf("2015-03-21");
Date d3 = Date.valueOf("2014-03-20");
runAndVerify(new Date[] { d1, d2, d3 }, d2, udf);
runAndVerify(new Date[] { null, d2, d3 }, null, udf);
runAndVerify(new Date[] { d1, null, d3 }, null, udf);
runAndVerify(new Date[] { d1, d2, null }, null, udf);
runAndVerify(new Date[] { null, null, null }, null, udf);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class TestGenericUDFDateAdd method testByteDataTypeAsDays.
public void testByteDataTypeAsDays() throws HiveException {
GenericUDFDateAdd udf = new GenericUDFDateAdd();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaByteObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new DateWritable(new Date(109, 06, 20)));
DeferredObject valueObj2 = new DeferredJavaObject(new Byte("4"));
DeferredObject[] args = { valueObj1, valueObj2 };
DateWritable output = (DateWritable) udf.evaluate(args);
assertEquals("date_add() test for BYTE failed ", "2009-07-24", output.toString());
}
Aggregations