use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class TestETypeConverter method testGetInt64MillisTimestampProlepticConverter.
@Test
public void testGetInt64MillisTimestampProlepticConverter() throws Exception {
Timestamp timestamp = Timestamp.valueOf("1572-07-15 15:12:20.112");
PrimitiveType primitiveType = createInt64TimestampType(false, TimeUnit.MILLIS);
Writable writable = getWritableFromPrimitiveConverter(null, primitiveType, timestamp.toEpochMilli());
TimestampWritableV2 timestampWritable = (TimestampWritableV2) writable;
assertEquals(timestamp.toEpochMilli(), timestampWritable.getTimestamp().toEpochMilli());
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class GenericUDFTrunc method evaluateDate.
private Object evaluateDate(DeferredObject[] arguments) throws UDFArgumentLengthException, HiveException, UDFArgumentTypeException, UDFArgumentException {
if (arguments.length != 2) {
throw new UDFArgumentLengthException("trunc() requires 2 argument, got " + arguments.length);
}
if (arguments[0].get() == null || arguments[1].get() == null) {
return null;
}
if (textConverter2 != null) {
fmtInput = textConverter2.convert(arguments[1].get()).toString();
}
Date d;
switch(inputType1) {
case STRING:
String dateString = textConverter1.convert(arguments[0].get()).toString();
d = DateParser.parseDate(dateString);
if (d == null) {
return null;
}
break;
case TIMESTAMP:
Timestamp ts = ((TimestampWritableV2) timestampConverter.convert(arguments[0].get())).getTimestamp();
d = Date.ofEpochMilli(ts.toEpochMilli());
break;
case DATE:
DateWritableV2 dw = (DateWritableV2) dateWritableConverter.convert(arguments[0].get());
d = dw.get();
break;
default:
throw new UDFArgumentTypeException(0, "TRUNC() only takes STRING/TIMESTAMP/DATEWRITABLE types, got " + inputType1);
}
if (evalDate(d) == null) {
return null;
}
output.set(date.toString());
return output;
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class GenericUDFToUnixTimeStamp method evaluate.
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
if (arguments[0].get() == null) {
return null;
}
if (inputTextConverter != null) {
Timestamp timestamp;
String textVal = (String) inputTextConverter.convert(arguments[0].get());
if (textVal == null) {
return null;
}
if (patternConverter != null) {
if (arguments[1].get() == null) {
return null;
}
String patternVal = (String) patternConverter.convert(arguments[1].get());
if (patternVal == null) {
return null;
}
if (!patternVal.equals(lasPattern)) {
formatter = getFormatter(patternVal);
lasPattern = patternVal;
}
try {
ZonedDateTime zonedDateTime = ZonedDateTime.parse(textVal, formatter.withZone(timeZone)).withZoneSameInstant(timeZone);
timestamp = new Timestamp(zonedDateTime.toLocalDateTime());
} catch (DateTimeException e1) {
try {
LocalDate localDate = LocalDate.parse(textVal, formatter);
timestamp = new Timestamp(localDate.atStartOfDay());
} catch (DateTimeException e3) {
return null;
}
}
} else {
try {
timestamp = Timestamp.valueOf(textVal);
} catch (IllegalArgumentException e) {
return null;
}
}
TimestampTZ timestampTZ = TimestampTZUtil.convert(timestamp, timeZone);
retValue.set(timestampTZ.getEpochSecond());
} else if (inputDateOI != null) {
TimestampTZ timestampTZ = TimestampTZUtil.convert(inputDateOI.getPrimitiveJavaObject(arguments[0].get()), timeZone);
retValue.set(timestampTZ.getEpochSecond());
} else if (inputTimestampOI != null) {
TimestampTZ timestampTZ = TimestampTZUtil.convert(inputTimestampOI.getPrimitiveJavaObject(arguments[0].get()), timeZone);
retValue.set(timestampTZ.getEpochSecond());
} else {
TimestampTZ timestampTZ = inputTimestampLocalTzOI.getPrimitiveJavaObject(arguments[0].get());
retValue.set(timestampTZ.getEpochSecond());
}
return retValue;
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class DateTimeMath method add.
public Timestamp add(HiveIntervalDayTime interval, Timestamp ts) {
if (ts == null || interval == null) {
return null;
}
Timestamp tsResult = new Timestamp();
add(interval, ts, tsResult);
return tsResult;
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class DateTimeMath method subtract.
public Timestamp subtract(Timestamp left, HiveIntervalYearMonth right) {
if (left == null || right == null) {
return null;
}
Timestamp tsResult = new Timestamp();
subtract(left, right, tsResult);
return tsResult;
}
Aggregations