use of org.apache.hadoop.hive.serde2.io.DateWritable in project hive by apache.
the class BatchToRowReader method nextDate.
public static DateWritable nextDate(ColumnVector vector, int row, Object previous) {
if (vector.isRepeating) {
row = 0;
}
if (vector.noNulls || !vector.isNull[row]) {
DateWritable result;
if (previous == null || previous.getClass() != DateWritable.class) {
result = new DateWritable();
} else {
result = (DateWritable) previous;
}
int date = (int) ((LongColumnVector) vector).vector[row];
result.set(date);
return result;
} else {
return null;
}
}
use of org.apache.hadoop.hive.serde2.io.DateWritable in project hive by apache.
the class ColumnStatsTask method unpackDateStats.
private void unpackDateStats(ObjectInspector oi, Object o, String fName, ColumnStatisticsObj statsObj) {
if (fName.equals("countnulls")) {
long v = ((LongObjectInspector) oi).get(o);
statsObj.getStatsData().getDateStats().setNumNulls(v);
} else if (fName.equals("numdistinctvalues")) {
long v = ((LongObjectInspector) oi).get(o);
statsObj.getStatsData().getDateStats().setNumDVs(v);
} else if (fName.equals("max")) {
DateWritable v = ((DateObjectInspector) oi).getPrimitiveWritableObject(o);
statsObj.getStatsData().getDateStats().setHighValue(new Date(v.getDays()));
} else if (fName.equals("min")) {
DateWritable v = ((DateObjectInspector) oi).getPrimitiveWritableObject(o);
statsObj.getStatsData().getDateStats().setLowValue(new Date(v.getDays()));
} else if (fName.equals("ndvbitvector")) {
PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi;
String v = ((StringObjectInspector) poi).getPrimitiveJavaObject(o);
statsObj.getStatsData().getDateStats().setBitVectors(v);
;
}
}
use of org.apache.hadoop.hive.serde2.io.DateWritable 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 DateWritable(4)), new DeferredJavaObject(new ByteWritable((byte) 4)) };
udf.initialize(inputOIs);
}
use of org.apache.hadoop.hive.serde2.io.DateWritable 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 DateWritable(4)), new DeferredJavaObject(new DateWritable(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.DateWritable in project hive by apache.
the class TestGenericUDFDateAdd method testDateWritablepToDate.
public void testDateWritablepToDate() throws HiveException {
GenericUDFDateAdd udf = new GenericUDFDateAdd();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new DateWritable(new Date(109, 06, 20)));
DeferredObject valueObj2 = new DeferredJavaObject(new Integer("4"));
DeferredObject[] args = { valueObj1, valueObj2 };
DateWritable output = (DateWritable) udf.evaluate(args);
assertEquals("date_add() test for DATEWRITABLE failed ", "2009-07-24", 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