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