use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class CastStringToTimestampWithFormat method evaluate.
@Override
protected void evaluate(TimestampColumnVector outputColVector, BytesColumnVector inputColVector, int i) {
String inputString = new String(inputColVector.vector[i], inputColVector.start[i], inputColVector.length[i], StandardCharsets.UTF_8);
Timestamp timestamp = formatter.parseTimestamp(inputString.replaceAll("\u0000", ""));
if (timestamp != null) {
outputColVector.set(i, timestamp.toSqlTimestamp());
} else {
super.setNull(outputColVector, i);
}
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class VectorUDFUnixTimeStampString method getField.
@Override
protected long getField(byte[] bytes, int start, int length) throws ParseException {
try {
Timestamp timestamp = Timestamp.valueOf(Text.decode(bytes, start, length));
TimestampTZ timestampTZ = TimestampTZUtil.convert(timestamp, timeZone);
return timestampTZ.getEpochSecond();
} catch (CharacterCodingException e) {
throw new ParseException(e.getMessage(), 0);
} catch (IllegalArgumentException e) {
throw new ParseException(e.getMessage(), 0);
}
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class GenericUDFTumbledWindow method evaluate.
/**
* Evaluate the GenericUDF with the arguments.
*
* @param arguments timestamp and interval.
*
* @return The truncated timestamp to the beginning of tumbled window interval.
*/
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
if (arguments[0] == null) {
return null;
}
Timestamp ts = PrimitiveObjectInspectorUtils.getTimestamp(arguments[0].get(), timestampOI);
HiveIntervalDayTime idt = PrimitiveObjectInspectorUtils.getHiveIntervalDayTime(arguments[1].get(), intervalOI);
Timestamp origin = originTsOI == null ? Timestamp.ofEpochMilli(0) : PrimitiveObjectInspectorUtils.getTimestamp(arguments[2].get(), originTsOI);
timestampResult.set(Timestamp.ofEpochMilli(truncate(ts, idt, origin)));
return timestampResult;
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class TestGenericUDFFromUnixTime method testTimestampOtherTimezone.
@Test
public void testTimestampOtherTimezone() throws HiveException {
ObjectInspector valueLongOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
GenericUDFFromUnixTime udf = new GenericUDFFromUnixTime();
ObjectInspector[] args = { valueLongOI };
udf.initialize(args);
Timestamp ts = Timestamp.valueOf("1969-12-31 15:59:46");
TimestampTZ tstz1 = TimestampTZUtil.convert(ts, ZoneId.of("America/Los_Angeles"));
TimestampTZ tstz2 = TimestampTZUtil.convert(ts, ZoneId.of("America/New_York"));
TimestampTZ tstz3 = TimestampTZUtil.convert(ts, ZoneId.of("Europe/London"));
TimestampTZ tstz4 = TimestampTZUtil.convert(ts, ZoneId.of("Europe/Rome"));
runAndVerify(udf, new LongWritable(tstz1.getEpochSecond()), new Text("1969-12-31 15:59:46"));
runAndVerify(udf, new LongWritable(tstz2.getEpochSecond()), new Text("1969-12-31 12:59:46"));
runAndVerify(udf, new LongWritable(tstz3.getEpochSecond()), new Text("1969-12-31 06:59:46"));
runAndVerify(udf, new LongWritable(tstz4.getEpochSecond()), new Text("1969-12-31 06:59:46"));
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class TestGenericUDFFromUnixTime method testTimestampWithArg2.
@Test
public void testTimestampWithArg2() throws HiveException {
ObjectInspector valueLongOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
ObjectInspector valueStringOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
GenericUDFFromUnixTime udf = new GenericUDFFromUnixTime();
ObjectInspector[] args = { valueLongOI, valueStringOI };
udf.initialize(args);
Timestamp ts = Timestamp.valueOf("2010-01-13 11:57:40");
TimestampTZ tstz1 = TimestampTZUtil.convert(ts, ZoneId.systemDefault());
runAndVerify(udf, new LongWritable(tstz1.getEpochSecond()), "MM/dd/yy HH:mm:ss", new Text("01/13/10 11:57:40"));
runAndVerify(udf, new LongWritable(tstz1.getEpochSecond()), "EEEE", new Text("Wednesday"));
runAndVerify(udf, new LongWritable(tstz1.getEpochSecond()), "yyyy-MM-dd'T'HH:mm:ssXXX", new Text("2010-01-13T11:57:40-08:00"));
runAndVerify(udf, new LongWritable(tstz1.getEpochSecond()), "uuuu-MM-dd'T'HH:mm:ssXXX", new Text("2010-01-13T11:57:40-08:00"));
}
Aggregations