Search in sources :

Example 91 with Timestamp

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

the class CastStringToTimestampWithFormat method evaluate.

@Override
protected void evaluate(TimestampColumnVector outputColVector, BytesColumnVector inputColVector, int i) {
    String inputString = new String(inputColVector.vector[i], inputColVector.start[i], inputColVector.length[i], StandardCharsets.UTF_8);
    Timestamp timestamp = formatter.parseTimestamp(inputString.replaceAll("\u0000", ""));
    if (timestamp != null) {
        outputColVector.set(i, timestamp.toSqlTimestamp());
    } else {
        super.setNull(outputColVector, i);
    }
}
Also used : Timestamp(org.apache.hadoop.hive.common.type.Timestamp)

Example 92 with Timestamp

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

the class VectorUDFUnixTimeStampString method getField.

@Override
protected long getField(byte[] bytes, int start, int length) throws ParseException {
    try {
        Timestamp timestamp = Timestamp.valueOf(Text.decode(bytes, start, length));
        TimestampTZ timestampTZ = TimestampTZUtil.convert(timestamp, timeZone);
        return timestampTZ.getEpochSecond();
    } catch (CharacterCodingException e) {
        throw new ParseException(e.getMessage(), 0);
    } catch (IllegalArgumentException e) {
        throw new ParseException(e.getMessage(), 0);
    }
}
Also used : TimestampTZ(org.apache.hadoop.hive.common.type.TimestampTZ) CharacterCodingException(java.nio.charset.CharacterCodingException) ParseException(java.text.ParseException) Timestamp(org.apache.hadoop.hive.common.type.Timestamp)

Example 93 with Timestamp

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

the class GenericUDFTumbledWindow method evaluate.

/**
 * Evaluate the GenericUDF with the arguments.
 *
 * @param arguments timestamp and interval.
 *
 * @return The truncated timestamp to the beginning of tumbled window interval.
 */
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
    if (arguments[0] == null) {
        return null;
    }
    Timestamp ts = PrimitiveObjectInspectorUtils.getTimestamp(arguments[0].get(), timestampOI);
    HiveIntervalDayTime idt = PrimitiveObjectInspectorUtils.getHiveIntervalDayTime(arguments[1].get(), intervalOI);
    Timestamp origin = originTsOI == null ? Timestamp.ofEpochMilli(0) : PrimitiveObjectInspectorUtils.getTimestamp(arguments[2].get(), originTsOI);
    timestampResult.set(Timestamp.ofEpochMilli(truncate(ts, idt, origin)));
    return timestampResult;
}
Also used : Timestamp(org.apache.hadoop.hive.common.type.Timestamp) HiveIntervalDayTime(org.apache.hadoop.hive.common.type.HiveIntervalDayTime)

Example 94 with Timestamp

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

the class TestGenericUDFFromUnixTime method testTimestampOtherTimezone.

@Test
public void testTimestampOtherTimezone() throws HiveException {
    ObjectInspector valueLongOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
    GenericUDFFromUnixTime udf = new GenericUDFFromUnixTime();
    ObjectInspector[] args = { valueLongOI };
    udf.initialize(args);
    Timestamp ts = Timestamp.valueOf("1969-12-31 15:59:46");
    TimestampTZ tstz1 = TimestampTZUtil.convert(ts, ZoneId.of("America/Los_Angeles"));
    TimestampTZ tstz2 = TimestampTZUtil.convert(ts, ZoneId.of("America/New_York"));
    TimestampTZ tstz3 = TimestampTZUtil.convert(ts, ZoneId.of("Europe/London"));
    TimestampTZ tstz4 = TimestampTZUtil.convert(ts, ZoneId.of("Europe/Rome"));
    runAndVerify(udf, new LongWritable(tstz1.getEpochSecond()), new Text("1969-12-31 15:59:46"));
    runAndVerify(udf, new LongWritable(tstz2.getEpochSecond()), new Text("1969-12-31 12:59:46"));
    runAndVerify(udf, new LongWritable(tstz3.getEpochSecond()), new Text("1969-12-31 06:59:46"));
    runAndVerify(udf, new LongWritable(tstz4.getEpochSecond()), new Text("1969-12-31 06:59:46"));
}
Also used : TimestampTZ(org.apache.hadoop.hive.common.type.TimestampTZ) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Text(org.apache.hadoop.io.Text) LongWritable(org.apache.hadoop.io.LongWritable) Timestamp(org.apache.hadoop.hive.common.type.Timestamp) Test(org.junit.Test)

Example 95 with Timestamp

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

the class TestGenericUDFFromUnixTime method testTimestampWithArg2.

@Test
public void testTimestampWithArg2() throws HiveException {
    ObjectInspector valueLongOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
    ObjectInspector valueStringOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    GenericUDFFromUnixTime udf = new GenericUDFFromUnixTime();
    ObjectInspector[] args = { valueLongOI, valueStringOI };
    udf.initialize(args);
    Timestamp ts = Timestamp.valueOf("2010-01-13 11:57:40");
    TimestampTZ tstz1 = TimestampTZUtil.convert(ts, ZoneId.systemDefault());
    runAndVerify(udf, new LongWritable(tstz1.getEpochSecond()), "MM/dd/yy HH:mm:ss", new Text("01/13/10 11:57:40"));
    runAndVerify(udf, new LongWritable(tstz1.getEpochSecond()), "EEEE", new Text("Wednesday"));
    runAndVerify(udf, new LongWritable(tstz1.getEpochSecond()), "yyyy-MM-dd'T'HH:mm:ssXXX", new Text("2010-01-13T11:57:40-08:00"));
    runAndVerify(udf, new LongWritable(tstz1.getEpochSecond()), "uuuu-MM-dd'T'HH:mm:ssXXX", new Text("2010-01-13T11:57:40-08:00"));
}
Also used : TimestampTZ(org.apache.hadoop.hive.common.type.TimestampTZ) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Text(org.apache.hadoop.io.Text) LongWritable(org.apache.hadoop.io.LongWritable) Timestamp(org.apache.hadoop.hive.common.type.Timestamp) Test(org.junit.Test)

Aggregations

Timestamp (org.apache.hadoop.hive.common.type.Timestamp)116 Test (org.junit.Test)36 TimestampWritableV2 (org.apache.hadoop.hive.serde2.io.TimestampWritableV2)32 Date (org.apache.hadoop.hive.common.type.Date)27 BytesWritable (org.apache.hadoop.io.BytesWritable)25 LongWritable (org.apache.hadoop.io.LongWritable)25 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)24 Text (org.apache.hadoop.io.Text)22 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)21 IntWritable (org.apache.hadoop.io.IntWritable)21 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)20 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)20 BooleanWritable (org.apache.hadoop.io.BooleanWritable)19 FloatWritable (org.apache.hadoop.io.FloatWritable)19 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)18 ArrayList (java.util.ArrayList)17 DateWritableV2 (org.apache.hadoop.hive.serde2.io.DateWritableV2)17 HiveIntervalDayTime (org.apache.hadoop.hive.common.type.HiveIntervalDayTime)16 List (java.util.List)15 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)12