use of org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector in project hive by apache.
the class TestVectorConditionalExpressions method testDoubleColumnScalarIfExpr.
@Test
public void testDoubleColumnScalarIfExpr() {
VectorizedRowBatch batch = getBatch1Long3DoubleVectors();
VectorExpression expr = new IfExprDoubleColumnDoubleScalar(0, 1, 200d, 3);
DoubleColumnVector r = (DoubleColumnVector) batch.cols[3];
expr.evaluate(batch);
assertEquals(true, 200d == r.vector[0]);
assertEquals(true, 200d == r.vector[1]);
assertEquals(true, -3d == r.vector[2]);
assertEquals(true, -4d == r.vector[3]);
}
use of org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector in project hive by apache.
the class TestVectorConditionalExpressions method getBatch1Long3DoubleVectors.
private VectorizedRowBatch getBatch1Long3DoubleVectors() {
VectorizedRowBatch batch = new VectorizedRowBatch(4);
LongColumnVector lv = new LongColumnVector();
// set first argument to IF -- boolean flag
lv.vector[0] = 0;
lv.vector[1] = 0;
lv.vector[2] = 1;
lv.vector[3] = 1;
batch.cols[0] = lv;
// set second argument to IF
DoubleColumnVector v = new DoubleColumnVector();
v.vector[0] = -1;
v.vector[1] = -2;
v.vector[2] = -3;
v.vector[3] = -4;
batch.cols[1] = v;
// set third argument to IF
v = new DoubleColumnVector();
v.vector[0] = 1;
v.vector[1] = 2;
v.vector[2] = 3;
v.vector[3] = 4;
batch.cols[2] = v;
// set output column
batch.cols[3] = new DoubleColumnVector();
batch.size = 4;
return batch;
}
use of org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector in project hive by apache.
the class TestVectorConditionalExpressions method testDoubleScalarColumnIfExpr.
@Test
public void testDoubleScalarColumnIfExpr() {
VectorizedRowBatch batch = getBatch1Long3DoubleVectors();
VectorExpression expr = new IfExprDoubleScalarDoubleColumn(0, 100.0d, 2, 3);
DoubleColumnVector r = (DoubleColumnVector) batch.cols[3];
expr.evaluate(batch);
assertEquals(true, 1d == r.vector[0]);
assertEquals(true, 2d == r.vector[1]);
assertEquals(true, 100d == r.vector[2]);
assertEquals(true, 100d == r.vector[3]);
}
use of org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector in project hive by apache.
the class TestVectorArithmeticExpressions method testLongColDivideLongColumn.
@Test
public void testLongColDivideLongColumn() {
/* Testing for equality of doubles after a math operation is
* not always reliable so use this as a tolerance.
*/
final double eps = 1e-7d;
VectorizedRowBatch batch = getVectorizedRowBatch2LongInDoubleOut();
LongColDivideLongColumn expr = new LongColDivideLongColumn(0, 1, 2);
batch.cols[0].isNull[1] = true;
batch.cols[0].noNulls = false;
batch.cols[1].noNulls = false;
DoubleColumnVector out = (DoubleColumnVector) batch.cols[2];
// Set so we can verify they are reset by operation
out.noNulls = true;
out.isRepeating = true;
expr.evaluate(batch);
// 0/0 for entry 0 should work but generate NaN
assertFalse(out.noNulls);
assertTrue(out.isNull[0]);
assertTrue(Double.isNaN(out.vector[0]));
// verify NULL output in entry 1 is correct
assertTrue(out.isNull[1]);
assertTrue(Double.isNaN(out.vector[1]));
// check entries beyond first 2
for (int i = 2; i != batch.size; i++) {
assertTrue(out.vector[i] > 1.0d - eps && out.vector[i] < 1.0d + eps);
}
assertFalse(out.noNulls);
assertFalse(out.isRepeating);
}
use of org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector in project hive by apache.
the class VectorizedRowGroupGenUtil method generateDoubleColumnVector.
public static DoubleColumnVector generateDoubleColumnVector(boolean nulls, boolean repeating, int size, Random rand) {
DoubleColumnVector dcv = new DoubleColumnVector(size);
dcv.noNulls = !nulls;
dcv.isRepeating = repeating;
double repeatingValue;
do {
repeatingValue = rand.nextDouble();
} while (repeatingValue == 0);
int nullFrequency = generateNullFrequency(rand);
for (int i = 0; i < size; i++) {
if (nulls && (repeating || i % nullFrequency == 0)) {
dcv.isNull[i] = true;
dcv.vector[i] = DOUBLE_VECTOR_NULL_VALUE;
} else {
dcv.isNull[i] = false;
dcv.vector[i] = repeating ? repeatingValue : rand.nextDouble();
if (dcv.vector[i] == 0) {
i--;
}
}
}
return dcv;
}
Aggregations