Пример #1
0
  private static long getLongOrTimestamp(Object value, DateTimeZone hiveTimeZone) {
    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);
      return TimeUnit.MILLISECONDS.toDays(utcMillis);
    }
    if (value instanceof Timestamp) {
      // The Hive SerDe parses timestamps using the default time zone of
      // this JVM, but the data might have been written using a different
      // time zone. We need to convert it to the configured time zone.

      // the timestamp that Hive parsed using the JVM time zone
      long parsedJvmMillis = ((Timestamp) value).getTime();

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

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

      return utcMillis;
    }
    return ((Number) value).longValue();
  }
 public long roundCeiling(long instant) {
   if (iTimeField) {
     int offset = getOffsetToAdd(instant);
     instant = iField.roundCeiling(instant + offset);
     return instant - offset;
   } else {
     long localInstant = iZone.convertUTCToLocal(instant);
     localInstant = iField.roundCeiling(localInstant);
     return iZone.convertLocalToUTC(localInstant, false, instant);
   }
 }
 public long addWrapField(long instant, int value) {
   if (iTimeField) {
     int offset = getOffsetToAdd(instant);
     long localInstant = iField.addWrapField(instant + offset, value);
     return localInstant - offset;
   } else {
     long localInstant = iZone.convertUTCToLocal(instant);
     localInstant = iField.addWrapField(localInstant, value);
     return iZone.convertLocalToUTC(localInstant, false, instant);
   }
 }
 public long set(long instant, int value) {
   long localInstant = iZone.convertUTCToLocal(instant);
   localInstant = iField.set(localInstant, value);
   long result = iZone.convertLocalToUTC(localInstant, false, instant);
   if (get(result) != value) {
     throw new IllegalFieldValueException(
         iField.getType(),
         Integer.valueOf(value),
         "Illegal instant due to time zone offset transition: "
             + DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")
                 .print(new Instant(localInstant))
             + " ("
             + iZone.getID()
             + ")");
   }
   return result;
 }
 public int getMaximumValue(long instant) {
   long localInstant = iZone.convertUTCToLocal(instant);
   return iField.getMaximumValue(localInstant);
 }
 public long remainder(long instant) {
   long localInstant = iZone.convertUTCToLocal(instant);
   return iField.remainder(localInstant);
 }
 public int getLeapAmount(long instant) {
   long localInstant = iZone.convertUTCToLocal(instant);
   return iField.getLeapAmount(localInstant);
 }
 public boolean isLeap(long instant) {
   long localInstant = iZone.convertUTCToLocal(instant);
   return iField.isLeap(localInstant);
 }
 public long set(long instant, String text, Locale locale) {
   // cannot verify that new value stuck because set may be lenient
   long localInstant = iZone.convertUTCToLocal(instant);
   localInstant = iField.set(localInstant, text, locale);
   return iZone.convertLocalToUTC(localInstant, false, instant);
 }
 public String getAsShortText(long instant, Locale locale) {
   long localInstant = iZone.convertUTCToLocal(instant);
   return iField.getAsShortText(localInstant, locale);
 }
 private long addOffset(long instant) {
   return iZone.convertUTCToLocal(instant);
 }