Search in sources :

Example 56 with TimestampWritable

use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.

the class BatchToRowReader method nextTimestamp.

public static TimestampWritable nextTimestamp(ColumnVector vector, int row, Object previous) {
    if (vector.isRepeating) {
        row = 0;
    }
    if (vector.noNulls || !vector.isNull[row]) {
        TimestampWritable result;
        if (previous == null || previous.getClass() != TimestampWritable.class) {
            result = new TimestampWritable();
        } else {
            result = (TimestampWritable) previous;
        }
        TimestampColumnVector tcv = (TimestampColumnVector) vector;
        result.setInternal(tcv.time[row], tcv.nanos[row]);
        return result;
    } else {
        return null;
    }
}
Also used : TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable)

Example 57 with TimestampWritable

use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.

the class GenericUDFCurrentTimestamp method copyToNewInstance.

@Override
public void copyToNewInstance(Object newInstance) throws UDFArgumentException {
    super.copyToNewInstance(newInstance);
    // Need to preserve currentTimestamp
    GenericUDFCurrentTimestamp other = (GenericUDFCurrentTimestamp) newInstance;
    if (this.currentTimestamp != null) {
        other.currentTimestamp = new TimestampWritable(this.currentTimestamp);
    }
}
Also used : TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable)

Example 58 with TimestampWritable

use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.

the class GenericUDF method getTimestampValue.

protected Timestamp getTimestampValue(DeferredObject[] arguments, int i, Converter[] converters) throws HiveException {
    Object obj;
    if ((obj = arguments[i].get()) == null) {
        return null;
    }
    Object writableValue = converters[i].convert(obj);
    // if string can not be parsed converter will return null
    if (writableValue == null) {
        return null;
    }
    Timestamp ts = ((TimestampWritable) writableValue).getTimestamp();
    return ts;
}
Also used : TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) Timestamp(java.sql.Timestamp)

Example 59 with TimestampWritable

use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.

the class TestVectorExpressionWriters method testSetterTimestamp.

private void testSetterTimestamp(TypeInfo type) throws HiveException {
    Timestamp[] timestampValues = new Timestamp[vectorSize];
    TimestampColumnVector tcv = VectorizedRowGroupGenUtil.generateTimestampColumnVector(true, false, vectorSize, new Random(10), timestampValues);
    tcv.isNull[3] = true;
    Object[] values = new Object[this.vectorSize];
    VectorExpressionWriter vew = getWriter(type);
    for (int i = 0; i < vectorSize; i++) {
        // setValue() should be able to handle null input
        values[i] = null;
        values[i] = vew.setValue(values[i], tcv, i);
        if (values[i] != null) {
            Writable expected = getWritableValue(type, timestampValues[i]);
            TimestampWritable t1 = (TimestampWritable) expected;
            TimestampWritable t2 = (TimestampWritable) values[i];
            Assert.assertTrue(t1.equals(t2));
        } else {
            Assert.assertTrue(tcv.isNull[i]);
        }
    }
}
Also used : TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) Random(java.util.Random) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) Writable(org.apache.hadoop.io.Writable) LongWritable(org.apache.hadoop.io.LongWritable) BytesWritable(org.apache.hadoop.io.BytesWritable) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) IntWritable(org.apache.hadoop.io.IntWritable) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) BooleanWritable(org.apache.hadoop.io.BooleanWritable) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) FloatWritable(org.apache.hadoop.io.FloatWritable) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) Timestamp(java.sql.Timestamp)

Example 60 with TimestampWritable

use of org.apache.hadoop.hive.serde2.io.TimestampWritable in project hive by apache.

the class TestVectorDateExpressions method compareToUDFDayOfMonthDate.

private void compareToUDFDayOfMonthDate(long t, int y) {
    UDFDayOfMonth udf = new UDFDayOfMonth();
    TimestampWritable tsw = toTimestampWritable(t);
    IntWritable res = udf.evaluate(tsw);
    Assert.assertEquals(res.get(), y);
}
Also used : UDFDayOfMonth(org.apache.hadoop.hive.ql.udf.UDFDayOfMonth) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) IntWritable(org.apache.hadoop.io.IntWritable)

Aggregations

TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)87 IntWritable (org.apache.hadoop.io.IntWritable)41 Text (org.apache.hadoop.io.Text)34 DateWritable (org.apache.hadoop.hive.serde2.io.DateWritable)33 Timestamp (java.sql.Timestamp)30 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)29 LongWritable (org.apache.hadoop.io.LongWritable)28 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)25 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)25 BooleanWritable (org.apache.hadoop.io.BooleanWritable)25 FloatWritable (org.apache.hadoop.io.FloatWritable)25 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)24 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)24 HiveIntervalDayTimeWritable (org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable)23 BytesWritable (org.apache.hadoop.io.BytesWritable)23 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)20 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)20 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)20 HiveIntervalYearMonthWritable (org.apache.hadoop.hive.serde2.io.HiveIntervalYearMonthWritable)19 Test (org.junit.Test)19