Search in sources :

Example 16 with Calendar

use of java.util.Calendar in project hive by apache.

the class NanoTimeUtils method getNanoTime.

/**
   * Constructs a julian date from the floating time Timestamp.
   * If the timezone of the calendar is different from the current local
   * timezone, then the timestamp value will be adjusted.
   * Possible adjustments:
   *   - UTC Ts -> Local Ts copied to TableTZ Calendar -> UTC Ts -> JD
   * @param ts floating time timestamp to store
   * @param calendar timezone used to adjust the timestamp for parquet
   * @return adjusted julian date
   */
public static NanoTime getNanoTime(Timestamp ts, Calendar calendar) {
    Calendar localCalendar = getLocalCalendar();
    localCalendar.setTimeInMillis(ts.getTime());
    Calendar adjustedCalendar = copyToCalendarWithTZ(localCalendar, calendar);
    Calendar utcCalendar = getUTCCalendar();
    utcCalendar.setTimeInMillis(adjustedCalendar.getTimeInMillis());
    int year = utcCalendar.get(Calendar.YEAR);
    if (utcCalendar.get(Calendar.ERA) == GregorianCalendar.BC) {
        year = 1 - year;
    }
    JDateTime jDateTime = new JDateTime(year, //java calendar index starting at 1.
    utcCalendar.get(Calendar.MONTH) + 1, utcCalendar.get(Calendar.DAY_OF_MONTH));
    int days = jDateTime.getJulianDayNumber();
    long hour = utcCalendar.get(Calendar.HOUR_OF_DAY);
    long minute = utcCalendar.get(Calendar.MINUTE);
    long second = utcCalendar.get(Calendar.SECOND);
    long nanos = ts.getNanos();
    long nanosOfDay = nanos + NANOS_PER_SECOND * second + NANOS_PER_MINUTE * minute + NANOS_PER_HOUR * hour;
    return new NanoTime(days, nanosOfDay);
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) JDateTime(jodd.datetime.JDateTime)

Example 17 with Calendar

use of java.util.Calendar in project hive by apache.

the class NanoTimeUtils method getTimestamp.

/**
   * Constructs a floating time Timestamp from the julian date contained in NanoTime.
   * If the timezone of the calendar is different from the current local
   * timezone, then the timestamp value will be adjusted.
   * Possible adjustments:
   *   - JD -> UTC Ts -> TableTZ Calendar copied to LocalTZ Calendar -> UTC Ts
   * @param nt stored julian date
   * @param calendar timezone used to adjust the timestamp for parquet
   * @return floating time represented as a timestamp. Guaranteed to display
   * the same when formatted using the current local timezone as with the local
   * timezone at the time it was stored.
   */
public static Timestamp getTimestamp(NanoTime nt, Calendar calendar) {
    int julianDay = nt.getJulianDay();
    long nanosOfDay = nt.getTimeOfDayNanos();
    long remainder = nanosOfDay;
    julianDay += remainder / NANOS_PER_DAY;
    remainder %= NANOS_PER_DAY;
    if (remainder < 0) {
        remainder += NANOS_PER_DAY;
        julianDay--;
    }
    JDateTime jDateTime = new JDateTime((double) julianDay);
    Calendar utcCalendar = getUTCCalendar();
    utcCalendar.clear();
    utcCalendar.set(Calendar.YEAR, jDateTime.getYear());
    //java calendar index starting at 1.
    utcCalendar.set(Calendar.MONTH, jDateTime.getMonth() - 1);
    utcCalendar.set(Calendar.DAY_OF_MONTH, jDateTime.getDay());
    int hour = (int) (remainder / (NANOS_PER_HOUR));
    remainder = remainder % (NANOS_PER_HOUR);
    int minutes = (int) (remainder / (NANOS_PER_MINUTE));
    remainder = remainder % (NANOS_PER_MINUTE);
    int seconds = (int) (remainder / (NANOS_PER_SECOND));
    long nanos = remainder % NANOS_PER_SECOND;
    utcCalendar.set(Calendar.HOUR_OF_DAY, hour);
    utcCalendar.set(Calendar.MINUTE, minutes);
    utcCalendar.set(Calendar.SECOND, seconds);
    calendar.setTimeInMillis(utcCalendar.getTimeInMillis());
    Calendar adjusterCalendar = copyToCalendarWithTZ(calendar, Calendar.getInstance());
    Timestamp ts = new Timestamp(adjusterCalendar.getTimeInMillis());
    ts.setNanos((int) nanos);
    return ts;
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) JDateTime(jodd.datetime.JDateTime) Timestamp(java.sql.Timestamp)

Example 18 with Calendar

use of java.util.Calendar in project hive by apache.

the class VectorizedPrimitiveColumnReader method decodeDictionaryIds.

/**
   * Reads `num` values into column, decoding the values from `dictionaryIds` and `dictionary`.
   */
private void decodeDictionaryIds(int rowId, int num, ColumnVector column, LongColumnVector dictionaryIds) {
    System.arraycopy(dictionaryIds.isNull, rowId, column.isNull, rowId, num);
    if (column.noNulls) {
        column.noNulls = dictionaryIds.noNulls;
    }
    column.isRepeating = column.isRepeating && dictionaryIds.isRepeating;
    switch(descriptor.getType()) {
        case INT32:
            for (int i = rowId; i < rowId + num; ++i) {
                ((LongColumnVector) column).vector[i] = dictionary.decodeToInt((int) dictionaryIds.vector[i]);
            }
            break;
        case INT64:
            for (int i = rowId; i < rowId + num; ++i) {
                ((LongColumnVector) column).vector[i] = dictionary.decodeToLong((int) dictionaryIds.vector[i]);
            }
            break;
        case FLOAT:
            for (int i = rowId; i < rowId + num; ++i) {
                ((DoubleColumnVector) column).vector[i] = dictionary.decodeToFloat((int) dictionaryIds.vector[i]);
            }
            break;
        case DOUBLE:
            for (int i = rowId; i < rowId + num; ++i) {
                ((DoubleColumnVector) column).vector[i] = dictionary.decodeToDouble((int) dictionaryIds.vector[i]);
            }
            break;
        case INT96:
            final Calendar calendar;
            if (Strings.isNullOrEmpty(this.conversionTimeZone)) {
                // Local time should be used if no timezone is specified
                calendar = Calendar.getInstance();
            } else {
                calendar = Calendar.getInstance(TimeZone.getTimeZone(this.conversionTimeZone));
            }
            for (int i = rowId; i < rowId + num; ++i) {
                ByteBuffer buf = dictionary.decodeToBinary((int) dictionaryIds.vector[i]).toByteBuffer();
                buf.order(ByteOrder.LITTLE_ENDIAN);
                long timeOfDayNanos = buf.getLong();
                int julianDay = buf.getInt();
                NanoTime nt = new NanoTime(julianDay, timeOfDayNanos);
                Timestamp ts = NanoTimeUtils.getTimestamp(nt, calendar);
                ((TimestampColumnVector) column).set(i, ts);
            }
            break;
        case BINARY:
        case FIXED_LEN_BYTE_ARRAY:
            if (column instanceof BytesColumnVector) {
                for (int i = rowId; i < rowId + num; ++i) {
                    ((BytesColumnVector) column).setVal(i, dictionary.decodeToBinary((int) dictionaryIds.vector[i]).getBytesUnsafe());
                }
            } else {
                DecimalColumnVector decimalColumnVector = ((DecimalColumnVector) column);
                decimalColumnVector.precision = (short) type.asPrimitiveType().getDecimalMetadata().getPrecision();
                decimalColumnVector.scale = (short) type.asPrimitiveType().getDecimalMetadata().getScale();
                for (int i = rowId; i < rowId + num; ++i) {
                    decimalColumnVector.vector[i].set(dictionary.decodeToBinary((int) dictionaryIds.vector[i]).getBytesUnsafe(), decimalColumnVector.scale);
                }
            }
            break;
        default:
            throw new UnsupportedOperationException("Unsupported type: " + descriptor.getType());
    }
}
Also used : NanoTime(org.apache.hadoop.hive.ql.io.parquet.timestamp.NanoTime) TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) Calendar(java.util.Calendar) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) ByteBuffer(java.nio.ByteBuffer) Timestamp(java.sql.Timestamp) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 19 with Calendar

use of java.util.Calendar in project GeekNews by codeestX.

the class GoldPresenter method getGoldData.

@Override
public void getGoldData(String type) {
    mType = type;
    currentPage = 0;
    totalList.clear();
    Observable<List<GoldListBean>> list = mRetrofitHelper.fetchGoldList(type, NUM_EACH_PAGE, currentPage++).compose(RxUtil.<GoldHttpResponse<List<GoldListBean>>>rxSchedulerHelper()).compose(RxUtil.<List<GoldListBean>>handleGoldResult());
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -3);
    Observable<List<GoldListBean>> hotList = mRetrofitHelper.fetchGoldHotList(type, new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()), NUM_HOT_LIMIT).compose(RxUtil.<GoldHttpResponse<List<GoldListBean>>>rxSchedulerHelper()).compose(RxUtil.<List<GoldListBean>>handleGoldResult());
    Subscription rxSubscription = Observable.concat(hotList, list).subscribe(new CommonSubscriber<List<GoldListBean>>(mView) {

        @Override
        public void onNext(List<GoldListBean> goldListBean) {
            if (isHotList) {
                isHotList = false;
                totalList.addAll(goldListBean);
            } else {
                isHotList = true;
                totalList.addAll(goldListBean);
                mView.showContent(totalList);
            }
        }
    });
    addSubscrebe(rxSubscription);
}
Also used : GoldHttpResponse(com.codeest.geeknews.model.http.response.GoldHttpResponse) GoldListBean(com.codeest.geeknews.model.bean.GoldListBean) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) List(java.util.List) Subscription(rx.Subscription) SimpleDateFormat(java.text.SimpleDateFormat)

Example 20 with Calendar

use of java.util.Calendar in project cw-omnibus by commonsguy.

the class TimePickerDemoActivity method onTimeChanged.

@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
    Calendar then = Calendar.getInstance();
    then.set(Calendar.HOUR_OF_DAY, hourOfDay);
    then.set(Calendar.MINUTE, minute);
    then.set(Calendar.SECOND, 0);
    Toast.makeText(this, then.getTime().toString(), Toast.LENGTH_SHORT).show();
}
Also used : Calendar(java.util.Calendar)

Aggregations

Calendar (java.util.Calendar)9441 Date (java.util.Date)2433 GregorianCalendar (java.util.GregorianCalendar)2129 Test (org.junit.Test)1734 SimpleDateFormat (java.text.SimpleDateFormat)889 ArrayList (java.util.ArrayList)476 ParseException (java.text.ParseException)352 HashMap (java.util.HashMap)270 TimeZone (java.util.TimeZone)270 IOException (java.io.IOException)235 DateFormat (java.text.DateFormat)224 Timestamp (java.sql.Timestamp)192 List (java.util.List)187 File (java.io.File)167 Map (java.util.Map)149 BigDecimal (java.math.BigDecimal)134 Locale (java.util.Locale)134 Test (org.testng.annotations.Test)118 Identity (org.olat.core.id.Identity)112 Date (java.sql.Date)110