use of org.apache.hadoop.hive.serde2.io.DateWritable in project hive by apache.
the class TestGenericUDFDateAdd method testShortDataTypeAsDays.
public void testShortDataTypeAsDays() throws HiveException {
GenericUDFDateAdd udf = new GenericUDFDateAdd();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaShortObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new DateWritable(new Date(109, 06, 20)));
DeferredObject valueObj2 = new DeferredJavaObject(new Short("4"));
DeferredObject[] args = { valueObj1, valueObj2 };
DateWritable output = (DateWritable) udf.evaluate(args);
assertEquals("date_add() test for SHORT failed ", "2009-07-24", output.toString());
}
use of org.apache.hadoop.hive.serde2.io.DateWritable in project hive by apache.
the class TestGenericUDFDateDiff method testDateWritablepToDate.
public void testDateWritablepToDate() throws HiveException {
GenericUDFDateDiff udf = new GenericUDFDateDiff();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new DateWritable(new Date(109, 06, 20)));
DeferredObject valueObj2 = new DeferredJavaObject(new DateWritable(new Date(109, 06, 10)));
DeferredObject[] args = { valueObj1, valueObj2 };
IntWritable output = (IntWritable) udf.evaluate(args);
assertEquals("datediff() test for DATEWRITABLE failed ", "10", 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.DateWritable in project hive by apache.
the class TestGenericUDFDateSub method testShortDataTypeAsDays.
public void testShortDataTypeAsDays() throws HiveException {
GenericUDFDateSub udf = new GenericUDFDateSub();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaShortObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new DateWritable(new Date(109, 06, 20)));
DeferredObject valueObj2 = new DeferredJavaObject(new Short("4"));
DeferredObject[] args = { valueObj1, valueObj2 };
DateWritable output = (DateWritable) udf.evaluate(args);
assertEquals("date_add() test for SHORT failed ", "2009-07-16", output.toString());
}
use of org.apache.hadoop.hive.serde2.io.DateWritable in project hive by apache.
the class RecordReaderImpl method nextDate.
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 TestSemanticAnalyzer method checkNormalization.
public void checkNormalization(String colType, String originalColSpec, String result, Object colValue) throws SemanticException {
final String colName = "col";
Map<String, String> partSpec = new HashMap<String, String>();
partSpec.put(colName, originalColSpec);
BaseSemanticAnalyzer.normalizeColSpec(partSpec, colName, colType, originalColSpec, colValue);
assertEquals(result, partSpec.get(colName));
if (colValue instanceof Date) {
DateWritable dw = new DateWritable((Date) colValue);
BaseSemanticAnalyzer.normalizeColSpec(partSpec, colName, colType, originalColSpec, dw);
assertEquals(result, partSpec.get(colName));
}
}
Aggregations