use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.
the class TestGenericUDFQuarter method runAndVerifyTs.
private void runAndVerifyTs(String str, Integer expResult, GenericUDF udf) throws HiveException {
DeferredObject valueObj0 = new DeferredJavaObject(str != null ? new TimestampWritable(Timestamp.valueOf(str)) : null);
DeferredObject[] args = { valueObj0 };
IntWritable output = (IntWritable) udf.evaluate(args);
if (expResult == null) {
assertNull(output);
} else {
assertNotNull(output);
assertEquals("quarter() test ", expResult.intValue(), output.get());
}
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.
the class TestGenericUDFToUnixTimestamp method testTimestamp.
public void testTimestamp() throws HiveException {
GenericUDFToUnixTimeStamp udf = new GenericUDFToUnixTimeStamp();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
Timestamp ts = Timestamp.valueOf("1970-01-01 00:00:00");
runAndVerify(udf, new TimestampWritable(ts), new LongWritable(ts.getTime() / 1000));
ts = Timestamp.valueOf("2001-02-03 01:02:03");
runAndVerify(udf, new TimestampWritable(ts), new LongWritable(ts.getTime() / 1000));
// test null values
runAndVerify(udf, null, null);
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.
the class TestGenericUDFTrunc method testTimestampToDateWithYearFormat.
public void testTimestampToDateWithYearFormat() throws HiveException {
GenericUDFTrunc udf = new GenericUDFTrunc();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
ObjectInspector[] initArgs = { valueOI0, valueOI1 };
DeferredObject valueObjFmt = new DeferredJavaObject(new Text("YYYY"));
DeferredObject valueObj0;
DeferredObject[] evalArgs;
// test date string
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-01 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-14 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-31 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-02 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-28 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-03 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-28 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-29 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
// test timestamp string
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-01 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-14 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-31 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-02 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-28 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-03 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-28 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-29 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.
the class TestGenericUDFTrunc method testTimestampToDateWithQuarterFormat.
public void testTimestampToDateWithQuarterFormat() throws HiveException {
GenericUDFTrunc udf = new GenericUDFTrunc();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
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 TimestampWritable(Timestamp.valueOf("2014-01-01 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-14 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-31 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-02 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-28 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-03 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-28 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-29 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-05-11 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-04-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-07-01 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-07-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-12-31 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-10-01", udf, initArgs, evalArgs);
// test timestamp string
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-01 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-14 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-31 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-02 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-28 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-03 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-28 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-29 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-05-11 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-04-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-07-01 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-07-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-12-31 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-10-01", udf, initArgs, evalArgs);
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.
the class TestGenericUDFTrunc method testTimestampToDateWithMonthFormat.
public void testTimestampToDateWithMonthFormat() throws HiveException {
GenericUDFTrunc udf = new GenericUDFTrunc();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
ObjectInspector[] initArgs = { valueOI0, valueOI1 };
DeferredObject valueObjFmt = new DeferredJavaObject(new Text("MON"));
DeferredObject valueObj0;
DeferredObject[] evalArgs;
// test date string
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-01 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-14 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-31 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-02 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-02-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-28 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-02-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-03 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-02-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-28 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-02-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-29 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-02-01", udf, initArgs, evalArgs);
// test timestamp string
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-01 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-14 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-31 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-02 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-02-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-28 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-02-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-03 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-02-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-28 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-02-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-29 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-02-01", udf, initArgs, evalArgs);
}
Aggregations