Skip to content

Commit

Permalink
Avoid DateTimeZone.getDefault() in GenericHiveRecordCursor hot path
Browse files Browse the repository at this point in the history
  • Loading branch information
pettyjamesm committed Sep 15, 2020
1 parent 7042af0 commit 2bad2ed
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
class GenericHiveRecordCursor<K, V extends Writable>
implements RecordCursor
{
private static final DateTimeZone JVM_TIME_ZONE = DateTimeZone.getDefault();

private final Path path;
private final RecordReader<K, V> recordReader;
private final K key;
Expand Down Expand Up @@ -293,7 +295,7 @@ private static long getLongExpressedValue(Object value, DateTimeZone hiveTimeZon
if (value instanceof Date) {
long storageTime = ((Date) value).getTime();
// convert date from VM current time zone to UTC
long utcMillis = storageTime + DateTimeZone.getDefault().getOffset(storageTime);
long utcMillis = storageTime + JVM_TIME_ZONE.getOffset(storageTime);
return TimeUnit.MILLISECONDS.toDays(utcMillis);
}
if (value instanceof Timestamp) {
Expand All @@ -305,13 +307,10 @@ private static long getLongExpressedValue(Object value, DateTimeZone hiveTimeZon
long parsedJvmMillis = ((Timestamp) value).getTime();

// remove the JVM time zone correction from the timestamp
DateTimeZone jvmTimeZone = DateTimeZone.getDefault();
long hiveMillis = jvmTimeZone.convertUTCToLocal(parsedJvmMillis);
long hiveMillis = JVM_TIME_ZONE.convertUTCToLocal(parsedJvmMillis);

// convert to UTC using the real time zone for the underlying data
long utcMillis = hiveTimeZone.convertLocalToUTC(hiveMillis, false);

return utcMillis;
return hiveTimeZone.convertLocalToUTC(hiveMillis, false);
}
if (value instanceof Float) {
return floatToRawIntBits(((Float) value));
Expand Down

0 comments on commit 2bad2ed

Please sign in to comment.