use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class ScheduledQueryAnalyzer method parseTimeStamp.
private Timestamp parseTimeStamp(Tree offsetNode) {
if (offsetNode == null) {
return new Timestamp();
}
List<String> s = new ArrayList<>();
s.add(TimestampParser.ISO_8601_FORMAT_STR);
s.add(TimestampParser.RFC_1123_FORMAT_STR);
s.add("HH:mm:ss");
s.add("H:mm:ss");
s.add("HH:mm");
TimestampParser p = new TimestampParser(s);
return p.parseTimestamp(unescapeSQLString(offsetNode.getText()));
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class VectorUDFDatetimeLegacyHybridCalendarTimestamp method func.
protected void func(TimestampColumnVector outputColVector, TimestampColumnVector inputColVector, int i) {
String adjustedTimestampString = SIMPLE_DATE_FORMAT_THREAD_LOCAL.get().format(new java.sql.Timestamp(inputColVector.time[i]));
Timestamp adjustedTimestamp = Timestamp.valueOf(adjustedTimestampString);
outputColVector.time[i] = adjustedTimestamp.toEpochMilli();
// Nanos don't change
outputColVector.nanos[i] = inputColVector.nanos[i];
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class GenericUDFCastFormat method convert.
private Object convert(Object o) throws HiveException {
Object input;
switch(inputOI.getPrimitiveCategory()) {
case STRING:
input = ((StringObjectInspector) inputOI).getPrimitiveJavaObject(o);
break;
case CHAR:
input = ((HiveCharObjectInspector) inputOI).getPrimitiveJavaObject(o).getStrippedValue();
break;
case VARCHAR:
input = ((HiveVarcharObjectInspector) inputOI).getPrimitiveJavaObject(o).toString();
break;
case TIMESTAMP:
input = ((TimestampObjectInspector) inputOI).getPrimitiveWritableObject(o).getTimestamp();
break;
case DATE:
input = ((DateObjectInspector) inputOI).getPrimitiveWritableObject(o).get();
break;
default:
throw new HiveException("Input type " + inputOI.getPrimitiveCategory() + " not valid");
}
// format here
Object formattedOutput = null;
if (inputOI.getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.DATE || inputOI.getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.TIMESTAMP) {
if (inputOI.getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.DATE) {
try {
formattedOutput = formatter.format((Date) input);
} catch (IllegalArgumentException e) {
return null;
}
} else {
try {
formattedOutput = formatter.format((Timestamp) input);
} catch (IllegalArgumentException e) {
return null;
}
}
if (formattedOutput == null) {
return null;
}
}
// parse and create Writables
switch(outputOI.getPrimitiveCategory()) {
case STRING:
return new Text((String) formattedOutput);
case CHAR:
return ((SettableHiveCharObjectInspector) outputOI).create(new HiveChar((String) formattedOutput, -1));
case VARCHAR:
return ((SettableHiveVarcharObjectInspector) outputOI).create(new HiveVarchar((String) formattedOutput, -1));
case TIMESTAMP:
try {
Timestamp t = formatter.parseTimestamp((String) input);
if (t == null) {
return null;
}
return ((SettableTimestampObjectInspector) outputOI).create(t);
} catch (IllegalArgumentException e) {
return null;
}
case DATE:
try {
Date d = formatter.parseDate((String) input);
if (d == null) {
return null;
}
return ((SettableDateObjectInspector) outputOI).create(d);
} catch (IllegalArgumentException e) {
return null;
}
default:
throw new HiveException("Output type " + outputOI.getPrimitiveCategory() + " not valid");
}
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class GenericUDFDateDiff method evaluate.
@Override
public IntWritable evaluate(DeferredObject[] arguments) throws HiveException {
Timestamp ts1 = getTimestampValue(arguments, 0, tsConverters);
Timestamp ts2 = getTimestampValue(arguments, 1, tsConverters);
if (ts1 == null || ts2 == null) {
return null;
}
output.set(DateWritableV2.millisToDays(ts1.toEpochMilli()) - DateWritableV2.millisToDays(ts2.toEpochMilli()));
return output;
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class ColumnVectorGenUtil method generateTimestampColumnVector.
public static TimestampColumnVector generateTimestampColumnVector(boolean nulls, boolean repeating, int size, Random rand, Timestamp[] timestampValues) {
TimestampColumnVector tcv = new TimestampColumnVector(size);
tcv.noNulls = !nulls;
tcv.isRepeating = repeating;
Timestamp repeatingTimestamp = RandomTypeUtil.getRandTimestamp(rand);
int nullFrequency = generateNullFrequency(rand);
for (int i = 0; i < size; i++) {
if (nulls && (repeating || i % nullFrequency == 0)) {
tcv.isNull[i] = true;
tcv.setNullValue(i);
timestampValues[i] = null;
} else {
tcv.isNull[i] = false;
if (!repeating) {
Timestamp randomTimestamp = RandomTypeUtil.getRandTimestamp(rand);
tcv.set(i, randomTimestamp.toSqlTimestamp());
timestampValues[i] = randomTimestamp;
} else {
tcv.set(i, repeatingTimestamp.toSqlTimestamp());
timestampValues[i] = repeatingTimestamp;
}
}
}
return tcv;
}
Aggregations