Search in sources :

Example 16 with Date

use of org.apache.hadoop.hive.common.type.Date in project hive by apache.

the class GenericUDFDatetimeLegacyHybridCalendar method evaluate.

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
    Object input = arguments[0].get();
    if (input == null) {
        return null;
    }
    input = converter.convert(input);
    switch(resultOI.getPrimitiveCategory()) {
        case DATE:
            Date date = ((DateWritableV2) input).get();
            java.sql.Date oldDate = new java.sql.Date(date.toEpochMilli());
            dateWritable.set(Date.valueOf(formatter.format(oldDate)));
            return dateWritable;
        case TIMESTAMP:
            Timestamp timestamp = ((TimestampWritableV2) input).getTimestamp();
            Timestamp adjustedTimestamp = Timestamp.valueOf(formatter.format(new java.sql.Timestamp(timestamp.toEpochMilli())));
            adjustedTimestamp.setNanos(timestamp.getNanos());
            timestampWritable.set(adjustedTimestamp);
            return timestampWritable;
        default:
            // Should never happen.
            throw new IllegalStateException("Unexpected type in evaluating datetime_legacy_hybrid_calendar: " + inputOI.getPrimitiveCategory());
    }
}
Also used : DateWritableV2(org.apache.hadoop.hive.serde2.io.DateWritableV2) Timestamp(org.apache.hadoop.hive.common.type.Timestamp) VectorUDFDatetimeLegacyHybridCalendarTimestamp(org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFDatetimeLegacyHybridCalendarTimestamp) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) Date(org.apache.hadoop.hive.common.type.Date) VectorUDFDatetimeLegacyHybridCalendarDate(org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFDatetimeLegacyHybridCalendarDate)

Example 17 with Date

use of org.apache.hadoop.hive.common.type.Date in project hive by apache.

the class TruncDateFromTimestamp method truncDate.

protected void truncDate(ColumnVector inV, BytesColumnVector outV, int i) {
    Date date = Date.ofEpochMilli(((TimestampColumnVector) inV).getTime(i));
    processDate(outV, i, date);
}
Also used : Date(org.apache.hadoop.hive.common.type.Date)

Example 18 with Date

use of org.apache.hadoop.hive.common.type.Date in project hive by apache.

the class VectorUDFDatetimeLegacyHybridCalendarDate method func.

protected void func(LongColumnVector outputColVector, LongColumnVector inputColVector, int i) {
    // get number of milliseconds from number of days
    Date inputDate = Date.ofEpochDay((int) inputColVector.vector[i]);
    java.sql.Date oldDate = new java.sql.Date(inputDate.toEpochMilli());
    Date adjustedDate = Date.valueOf(SIMPLE_DATE_FORMAT_THREAD_LOCAL.get().format(oldDate));
    outputColVector.vector[i] = adjustedDate.toEpochDay();
}
Also used : Date(org.apache.hadoop.hive.common.type.Date)

Example 19 with Date

use of org.apache.hadoop.hive.common.type.Date 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;
}
Also used : UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException) DateWritableV2(org.apache.hadoop.hive.serde2.io.DateWritableV2) TruncDateFromString(org.apache.hadoop.hive.ql.exec.vector.expressions.TruncDateFromString) TruncDateFromTimestamp(org.apache.hadoop.hive.ql.exec.vector.expressions.TruncDateFromTimestamp) Timestamp(org.apache.hadoop.hive.common.type.Timestamp) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) Date(org.apache.hadoop.hive.common.type.Date) TruncDateFromDate(org.apache.hadoop.hive.ql.exec.vector.expressions.TruncDateFromDate)

Example 20 with Date

use of org.apache.hadoop.hive.common.type.Date in project hive by apache.

the class DateTimeMath method add.

/**
 * Perform date + int operation .
 * @param dt the date
 * @param interval the int (days)
 * @return the resulting date
 */
public Date add(Date dt, int interval) {
    if (dt == null) {
        return null;
    }
    Date dtResult = new Date();
    dtResult.setTimeInDays(dt.toEpochDay() + interval);
    return dtResult;
}
Also used : Date(org.apache.hadoop.hive.common.type.Date)

Aggregations

Date (org.apache.hadoop.hive.common.type.Date)71 Timestamp (org.apache.hadoop.hive.common.type.Timestamp)26 DateWritableV2 (org.apache.hadoop.hive.serde2.io.DateWritableV2)21 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)18 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)18 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)17 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)15 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)14 Text (org.apache.hadoop.io.Text)14 Test (org.junit.Test)14 HiveIntervalYearMonth (org.apache.hadoop.hive.common.type.HiveIntervalYearMonth)13 BytesWritable (org.apache.hadoop.io.BytesWritable)12 HiveIntervalDayTime (org.apache.hadoop.hive.common.type.HiveIntervalDayTime)11 TimestampWritableV2 (org.apache.hadoop.hive.serde2.io.TimestampWritableV2)11 DecimalTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo)11 List (java.util.List)10 LongWritable (org.apache.hadoop.io.LongWritable)10 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)9 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)9 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)9