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;
}
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;
}
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);
}
}
}
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;
}
Aggregations