use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class TestGenericUDFOPMinus method testDateMinusIntervalDayTime.
@Test
public void testDateMinusIntervalDayTime() throws Exception {
GenericUDFOPMinus udf = new GenericUDFOPMinus();
DateWritable left = new DateWritable(Date.valueOf("2001-01-01"));
HiveIntervalDayTimeWritable right = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 0:0:0.555"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, 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("2000-12-30 23:59:59.445"), res.getTimestamp());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class TestGenericUDFOPMinus method testDateMinusIntervalYearMonth.
@Test
public void testDateMinusIntervalYearMonth() throws Exception {
GenericUDFOPMinus udf = new GenericUDFOPMinus();
DateWritable left = new DateWritable(Date.valueOf("2004-02-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("2001-06-15"), res.get());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class TestGenericUDFTrunc method testDateWritableToDateWithQuarterFormat.
public void testDateWritableToDateWithQuarterFormat() throws HiveException {
GenericUDFTrunc udf = new GenericUDFTrunc();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
ObjectInspector[] initArgs = { valueOI0, valueOI1 };
DeferredObject valueObjFmt = new DeferredJavaObject(new Text("Q"));
DeferredObject valueObj0;
DeferredObject[] evalArgs;
// test date string
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2014-01-01")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2014-01-14")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2014-01-31")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2014-02-02")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2014-02-28")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2016-02-03")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2016-02-28")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2016-02-29")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2016-05-11")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-04-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2016-07-01")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-07-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2016-12-31")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-10-01", udf, initArgs, evalArgs);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class TestGenericUDFMonthsBetween method testMonthsBetweenForDate.
public void testMonthsBetweenForDate() throws HiveException {
GenericUDFMonthsBetween udf = new GenericUDFMonthsBetween();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
testMonthsBetweenForDate(udf);
// Run without round-off
GenericUDFMonthsBetween udfWithoutRoundOff = new GenericUDFMonthsBetween();
ObjectInspector vOI1 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector vOI2 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector vOI3 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.booleanTypeInfo, new BooleanWritable(false));
ObjectInspector[] args = { vOI1, vOI2, vOI3 };
udfWithoutRoundOff.initialize(args);
testMonthsBetweenForDate(udfWithoutRoundOff);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class GenericUDF method obtainDateConverter.
protected void obtainDateConverter(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException {
PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i];
PrimitiveCategory inputType = inOi.getPrimitiveCategory();
ObjectInspector outOi;
switch(inputType) {
case STRING:
case VARCHAR:
case CHAR:
outOi = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
break;
case TIMESTAMP:
case DATE:
case VOID:
case TIMESTAMPLOCALTZ:
outOi = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
break;
default:
throw new UDFArgumentTypeException(i, getFuncName() + " only takes STRING_GROUP or DATE_GROUP types as " + getArgOrder(i) + " argument, got " + inputType);
}
converters[i] = ObjectInspectorConverters.getConverter(inOi, outOi);
inputTypes[i] = inputType;
}
Aggregations