Search in sources :

Example 6 with TimestampColumnVector

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

the class TestVectorTypeCasts method testCastTimestampToDecimal.

@Test
public void testCastTimestampToDecimal() {
    // The input timestamps are stored as long values
    // measured in nanoseconds from the epoch.
    HiveDecimal[] hiveDecimalValues = new HiveDecimal[500];
    VectorizedRowBatch b = getBatchTimestampDecimal(hiveDecimalValues);
    VectorExpression expr = new CastTimestampToDecimal(0, 1);
    TimestampColumnVector inT = (TimestampColumnVector) b.cols[0];
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[1];
    for (int i = 0; i < hiveDecimalValues.length; i++) {
        HiveDecimal hiveDecimal = r.vector[i].getHiveDecimal();
        HiveDecimal expectedHiveDecimal = hiveDecimalValues[i];
        if (!hiveDecimal.equals(expectedHiveDecimal)) {
            assertTrue(false);
        }
    }
    // Try again with a value that won't fit in 5 digits, to make
    // sure that NULL is produced.
    b.cols[1] = r = new DecimalColumnVector(hiveDecimalValues.length, 5, 2);
    expr.evaluate(b);
    r = (DecimalColumnVector) b.cols[1];
    for (int i = 0; i < hiveDecimalValues.length; i++) {
        HiveDecimal hiveDecimal = r.vector[i].getHiveDecimal();
        HiveDecimal expectedHiveDecimal = hiveDecimalValues[i];
        if (HiveDecimal.enforcePrecisionScale(expectedHiveDecimal, 5, 2) == null) {
            assertTrue(r.isNull[i]);
        } else {
            assertTrue(!r.isNull[i]);
            if (!hiveDecimal.equals(expectedHiveDecimal)) {
                assertTrue(false);
            }
        }
    }
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) Test(org.junit.Test)

Example 7 with TimestampColumnVector

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

the class TestVectorTimestampExpressions method getVectorizedRowBatchTimestampLong.

/*
   * Input array is used to fill the entire size of the vector row batch
   */
private VectorizedRowBatch getVectorizedRowBatchTimestampLong(Timestamp[] inputs, int size) {
    VectorizedRowBatch batch = new VectorizedRowBatch(2, size);
    TimestampColumnVector tcv = new TimestampColumnVector(size);
    for (int i = 0; i < size; i++) {
        tcv.set(i, inputs[i % inputs.length]);
    }
    batch.cols[0] = tcv;
    batch.cols[1] = new LongColumnVector(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) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 8 with TimestampColumnVector

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

the class TestVectorTypeCasts method testCastDoubleToTimestamp.

@Test
public void testCastDoubleToTimestamp() {
    VectorizedRowBatch b = TestVectorMathFunctions.getVectorizedRowBatchDoubleInTimestampOut();
    TimestampColumnVector resultV = (TimestampColumnVector) b.cols[1];
    b.cols[0].noNulls = true;
    VectorExpression expr = new CastDoubleToTimestamp(0, 1);
    expr.evaluate(b);
    Assert.assertEquals(0.0, TimestampUtils.getDouble(resultV.asScratchTimestamp(3)));
    Assert.assertEquals(0.5d, TimestampUtils.getDouble(resultV.asScratchTimestamp(4)));
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) Test(org.junit.Test)

Example 9 with TimestampColumnVector

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

the class TestVectorTypeCasts method testCastLongToTimestamp.

@Test
public void testCastLongToTimestamp() {
    long[] longValues = new long[500];
    VectorizedRowBatch b = TestVectorMathFunctions.getVectorizedRowBatchLongInTimestampOut(longValues);
    TimestampColumnVector resultV = (TimestampColumnVector) b.cols[1];
    b.cols[0].noNulls = true;
    VectorExpression expr = new CastLongToTimestamp(0, 1);
    expr.evaluate(b);
    for (int i = 0; i < longValues.length; i++) {
        Timestamp timestamp = resultV.asScratchTimestamp(i);
        long actual = TimestampWritable.getLong(timestamp);
        assertEquals(actual, longValues[i]);
    }
}
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 10 with TimestampColumnVector

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

the class TestVectorTypeCasts method testCastTimestampToLong.

@Test
public void testCastTimestampToLong() {
    long[] longValues = new long[500];
    VectorizedRowBatch b = TestVectorMathFunctions.getVectorizedRowBatchTimestampInLongOut(longValues);
    TimestampColumnVector inV = (TimestampColumnVector) b.cols[0];
    LongColumnVector resultV = (LongColumnVector) b.cols[1];
    b.cols[0].noNulls = true;
    VectorExpression expr = new CastTimestampToLong(0, 1);
    expr.evaluate(b);
    for (int i = 0; i < longValues.length; i++) {
        long actual = resultV.vector[i];
        long timestampLong = inV.getTimestampAsLong(i);
        if (actual != timestampLong) {
            assertTrue(false);
        }
    }
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) Test(org.junit.Test)

Aggregations

TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)54 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)19 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)17 Timestamp (java.sql.Timestamp)13 Test (org.junit.Test)10 Random (java.util.Random)8 DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)8 DoubleColumnVector (org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)7 TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)7 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)6 TestVectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch)3 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)3 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)3 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)3 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)3 BooleanWritable (org.apache.hadoop.io.BooleanWritable)3 IntWritable (org.apache.hadoop.io.IntWritable)3 LongWritable (org.apache.hadoop.io.LongWritable)3 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)2 ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)2