Search in sources :

Example 71 with TimestampColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector in project hive by apache.

the class TestVectorTypeCasts method testCastDecimalToTimestamp.

@Test
public void testCastDecimalToTimestamp() throws HiveException {
    double[] doubleValues = new double[500];
    VectorizedRowBatch b = getBatchDecimalTimestamp(doubleValues);
    VectorExpression expr = new CastDecimalToTimestamp(0, 1);
    expr.evaluate(b);
    TimestampColumnVector r = (TimestampColumnVector) b.cols[1];
    for (int i = 0; i < doubleValues.length; i++) {
        Timestamp timestamp = r.asScratchTimestamp(i);
        double asDouble = TimestampUtils.getDouble(timestamp);
        double expectedDouble = doubleValues[i];
        if (expectedDouble != asDouble) {
            assertTrue(false);
        }
    }
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 72 with TimestampColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector in project hive by apache.

the class TestVectorUDFDatetimeLegacyHybridCalendar method getVectorizedRowBatch.

/**
 * Input array is used to fill the entire specified size of the vector row batch.
 */
private VectorizedRowBatch getVectorizedRowBatch(java.sql.Timestamp[] inputs, int size) {
    VectorizedRowBatch batch = new VectorizedRowBatch(2, size);
    TimestampColumnVector inputCol = new TimestampColumnVector(size);
    for (int i = 0; i < size; i++) {
        inputCol.set(i, inputs[i % inputs.length]);
    }
    batch.cols[0] = inputCol;
    batch.cols[1] = new TimestampColumnVector(size);
    batch.size = size;
    return batch;
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TestVectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch) TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)

Example 73 with TimestampColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector in project hive by apache.

the class VectorUDFDateAddColScalar method evaluateTimestamp.

protected long evaluateTimestamp(ColumnVector columnVector, int index) {
    TimestampColumnVector tcv = (TimestampColumnVector) columnVector;
    // Convert to date value (in days)
    long days = DateWritableV2.millisToDays(tcv.getTime(index));
    if (isPositive) {
        days += numDays;
    } else {
        days -= numDays;
    }
    return days;
}
Also used : TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)

Example 74 with TimestampColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector in project hive by apache.

the class VectorUDFDateDiffColCol method toDateArray.

private LongColumnVector toDateArray(VectorizedRowBatch batch, TypeInfo typeInfo, ColumnVector inputColVector, LongColumnVector dateVector) {
    PrimitiveCategory primitiveCategory = ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory();
    int size = batch.size;
    if (primitiveCategory == PrimitiveCategory.DATE) {
        return (LongColumnVector) inputColVector;
    }
    if (size > dateVector.vector.length) {
        if (dateVector1 == dateVector) {
            dateVector1 = new LongColumnVector(size * 2);
            dateVector = dateVector1;
        } else {
            dateVector2 = new LongColumnVector(size * 2);
            dateVector = dateVector2;
        }
    }
    switch(primitiveCategory) {
        case TIMESTAMP:
            TimestampColumnVector tcv = (TimestampColumnVector) inputColVector;
            copySelected(tcv, batch.selectedInUse, batch.selected, batch.size, dateVector);
            return dateVector;
        case STRING:
        case CHAR:
        case VARCHAR:
            BytesColumnVector bcv = (BytesColumnVector) inputColVector;
            copySelected(bcv, batch.selectedInUse, batch.selected, batch.size, dateVector);
            return dateVector;
        default:
            throw new Error("Unsupported input type " + primitiveCategory.name());
    }
}
Also used : TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) PrimitiveCategory(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 75 with TimestampColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector in project hive by apache.

the class VectorUDFDateDiffScalarCol method evaluateTimestamp.

protected int evaluateTimestamp(ColumnVector columnVector, int index) {
    TimestampColumnVector tcv = (TimestampColumnVector) columnVector;
    date.setTime(tcv.getTime(index));
    return baseDate - DateWritableV2.dateToDays(date);
}
Also used : TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)

Aggregations

TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)85 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)31 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)26 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)21 DoubleColumnVector (org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)18 DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)17 Timestamp (java.sql.Timestamp)16 Test (org.junit.Test)11 Random (java.util.Random)10 ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)9 TimestampWritableV2 (org.apache.hadoop.hive.serde2.io.TimestampWritableV2)7 IntervalDayTimeColumnVector (org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector)6 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)5 TestVectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch)4 Timestamp (org.apache.hadoop.hive.common.type.Timestamp)3 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)2 HiveIntervalDayTime (org.apache.hadoop.hive.common.type.HiveIntervalDayTime)2 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)2 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)2 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)2