use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class GenericUDFToDate method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length < 1) {
throw new UDFArgumentLengthException("The function CAST as DATE requires at least one argument, got " + arguments.length);
}
try {
argumentOI = (PrimitiveObjectInspector) arguments[0];
PrimitiveCategory pc = argumentOI.getPrimitiveCategory();
PrimitiveGrouping pg = PrimitiveObjectInspectorUtils.getPrimitiveGrouping(pc);
switch(pg) {
case DATE_GROUP:
case STRING_GROUP:
case VOID_GROUP:
break;
default:
throw new UDFArgumentException("CAST as DATE only allows date,string, or timestamp types");
}
} catch (ClassCastException e) {
throw new UDFArgumentException("The function CAST as DATE takes only primitive types");
}
dc = new DateConverter(argumentOI, PrimitiveObjectInspectorFactory.writableDateObjectInspector);
return PrimitiveObjectInspectorFactory.writableDateObjectInspector;
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class TestGenericUDFSortArray method testSortStruct.
@Test
public void testSortStruct() throws HiveException {
ObjectInspector[] inputOIs = { ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(asList("f1", "f2", "f3", "f4"), asList(PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.writableDateObjectInspector, ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableIntObjectInspector)))) };
udf.initialize(inputOIs);
Object i1 = asList(new Text("a"), new DoubleWritable(3.1415), new DateWritable(new Date(2015, 5, 26)), asList(new IntWritable(1), new IntWritable(3), new IntWritable(2), new IntWritable(4)));
Object i2 = asList(new Text("b"), new DoubleWritable(3.14), new DateWritable(new Date(2015, 5, 26)), asList(new IntWritable(1), new IntWritable(3), new IntWritable(2), new IntWritable(4)));
Object i3 = asList(new Text("a"), new DoubleWritable(3.1415), new DateWritable(new Date(2015, 5, 25)), asList(new IntWritable(1), new IntWritable(3), new IntWritable(2), new IntWritable(5)));
Object i4 = asList(new Text("a"), new DoubleWritable(3.1415), new DateWritable(new Date(2015, 5, 25)), asList(new IntWritable(1), new IntWritable(3), new IntWritable(2), new IntWritable(4)));
runAndVerify(asList(i1, i2, i3, i4), asList(i4, i3, i1, i2));
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector 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.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class TestGenericUDFQuarter method testQuarterDt.
public void testQuarterDt() throws HiveException {
GenericUDFQuarter udf = new GenericUDFQuarter();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector[] arguments = { valueOI0 };
udf.initialize(arguments);
// positive Unix time
runAndVerifyDt("2014-01-01", 1, udf);
runAndVerifyDt("2014-02-10", 1, udf);
runAndVerifyDt("2014-03-31", 1, udf);
runAndVerifyDt("2014-04-02", 2, udf);
runAndVerifyDt("2014-05-28", 2, udf);
runAndVerifyDt("2016-06-03", 2, udf);
runAndVerifyDt("2016-07-28", 3, udf);
runAndVerifyDt("2016-08-29", 3, udf);
runAndVerifyDt("2016-09-29", 3, udf);
runAndVerifyDt("2016-10-29", 4, udf);
runAndVerifyDt("2016-11-29", 4, udf);
runAndVerifyDt("2016-12-31", 4, udf);
// negative Unix time
runAndVerifyDt("1966-01-01", 1, udf);
runAndVerifyDt("1966-03-31", 1, udf);
runAndVerifyDt("1966-04-01", 2, udf);
runAndVerifyDt("1966-12-31", 4, udf);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector in project hive by apache.
the class TestGenericUDFToUnixTimestamp method testDate.
public void testDate() throws HiveException {
GenericUDFToUnixTimeStamp udf = new GenericUDFToUnixTimeStamp();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
Date date = Date.valueOf("1970-01-01");
runAndVerify(udf, new DateWritable(date), new LongWritable(date.getTime() / 1000));
// test null values
runAndVerify(udf, null, null);
}
Aggregations