Search in sources :

Example 51 with TimestampColumnVector

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

the class TestVectorTimestampExpressions method getVectorizedRandomRowBatchTimestampLong.

private VectorizedRowBatch getVectorizedRandomRowBatchTimestampLong(int seed, int size) {
    VectorizedRowBatch batch = new VectorizedRowBatch(2, size);
    TimestampColumnVector tcv = new TimestampColumnVector(size);
    Random rand = new Random(seed);
    for (int i = 0; i < size; i++) {
        tcv.set(i, RandomTypeUtil.getRandTimestamp(rand));
    }
    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) Random(java.util.Random) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 52 with TimestampColumnVector

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

the class TestVectorTypeCasts method getBatchTimestampDecimal.

private VectorizedRowBatch getBatchTimestampDecimal(HiveDecimal[] hiveDecimalValues) {
    Random r = new Random(994);
    VectorizedRowBatch b = new VectorizedRowBatch(2);
    TimestampColumnVector tcv;
    b.cols[0] = tcv = new TimestampColumnVector(hiveDecimalValues.length);
    b.cols[1] = new DecimalColumnVector(hiveDecimalValues.length, HiveDecimal.SYSTEM_DEFAULT_PRECISION, HiveDecimal.SYSTEM_DEFAULT_SCALE);
    for (int i = 0; i < hiveDecimalValues.length; i++) {
        int optionalNanos = 0;
        switch(r.nextInt(4)) {
            case 0:
                // No nanos.
                break;
            case 1:
                optionalNanos = r.nextInt((int) NANOSECONDS_PER_SECOND);
                break;
            case 2:
                // Limit to milliseconds only...
                optionalNanos = r.nextInt((int) MILLISECONDS_PER_SECOND) * (int) NANOSECONDS_PER_MILLISSECOND;
                break;
            case 3:
                // Limit to below milliseconds only...
                optionalNanos = r.nextInt((int) NANOSECONDS_PER_MILLISSECOND);
                break;
        }
        long millis = RandomTypeUtil.randomMillis(r);
        Timestamp ts = new Timestamp(millis);
        ts.setNanos(optionalNanos);
        TimestampWritable tsw = new TimestampWritable(ts);
        hiveDecimalValues[i] = tsw.getHiveDecimal();
        tcv.set(i, ts);
    }
    b.size = hiveDecimalValues.length;
    return b;
}
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) Random(java.util.Random) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) Timestamp(java.sql.Timestamp)

Example 53 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() {
    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 54 with TimestampColumnVector

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

the class TestVectorTypeCasts method getBatchDecimalTimestamp.

private VectorizedRowBatch getBatchDecimalTimestamp(double[] doubleValues) {
    VectorizedRowBatch b = new VectorizedRowBatch(2);
    DecimalColumnVector dv;
    b.cols[0] = dv = new DecimalColumnVector(doubleValues.length, HiveDecimal.SYSTEM_DEFAULT_PRECISION, HiveDecimal.SYSTEM_DEFAULT_SCALE);
    b.cols[1] = new TimestampColumnVector(doubleValues.length);
    dv.noNulls = true;
    Random r = new Random(94830);
    for (int i = 0; i < doubleValues.length; i++) {
        long millis = RandomTypeUtil.randomMillis(r);
        Timestamp ts = new Timestamp(millis);
        int nanos = RandomTypeUtil.randomNanos(r);
        ts.setNanos(nanos);
        TimestampWritable tsw = new TimestampWritable(ts);
        double asDouble = tsw.getDouble();
        doubleValues[i] = asDouble;
        HiveDecimal hiveDecimal = HiveDecimal.create(new BigDecimal(asDouble));
        dv.set(i, hiveDecimal);
    }
    b.size = doubleValues.length;
    return b;
}
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) Random(java.util.Random) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal)

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