use of org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector in project hive by apache.
the class TestVectorMathFunctions method testVectorSin.
/*
* The following tests spot-check that vectorized functions with signature
* DOUBLE func(DOUBLE) that came from template ColumnUnaryFunc.txt
* get the right result. Null propagation, isRepeating
* propagation will be checked once for a single expansion of the template
* (for FuncRoundDoubleToDouble).
*/
@Test
public void testVectorSin() {
VectorizedRowBatch b = getVectorizedRowBatchDoubleInDoubleOut();
DoubleColumnVector resultV = (DoubleColumnVector) b.cols[1];
b.cols[0].noNulls = true;
VectorExpression expr = new FuncSinDoubleToDouble(0, 1);
expr.evaluate(b);
Assert.assertEquals(Math.sin(0.5d), resultV.vector[4]);
}
use of org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector in project hive by apache.
the class TestVectorMathFunctions method testVectorACos.
@Test
public void testVectorACos() {
VectorizedRowBatch b = getVectorizedRowBatchDoubleInDoubleOut();
DoubleColumnVector resultV = (DoubleColumnVector) b.cols[1];
b.cols[0].noNulls = true;
VectorExpression expr = new FuncACosDoubleToDouble(0, 1);
expr.evaluate(b);
Assert.assertEquals(Math.acos(0.5d), resultV.vector[4]);
}
use of org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector in project hive by apache.
the class TestVectorMathFunctions method getVectorizedRowBatchDoubleInLongOut.
public static VectorizedRowBatch getVectorizedRowBatchDoubleInLongOut() {
VectorizedRowBatch batch = new VectorizedRowBatch(2);
LongColumnVector lcv;
DoubleColumnVector dcv;
lcv = new LongColumnVector();
dcv = new DoubleColumnVector();
dcv.vector[0] = -1.5d;
dcv.vector[1] = -0.5d;
dcv.vector[2] = -0.1d;
dcv.vector[3] = 0d;
dcv.vector[4] = 0.5d;
dcv.vector[5] = 0.7d;
dcv.vector[6] = 1.5d;
batch.cols[0] = dcv;
batch.cols[1] = lcv;
batch.size = 7;
return batch;
}
use of org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector in project hive by apache.
the class TestVectorMathFunctions method testVectorLog2.
@Test
public void testVectorLog2() {
// test double->double version
VectorizedRowBatch b = getVectorizedRowBatchDoubleInDoubleOut();
DoubleColumnVector resultV = (DoubleColumnVector) b.cols[1];
b.cols[0].noNulls = true;
VectorExpression expr = new FuncLog2DoubleToDouble(0, 1);
expr.evaluate(b);
Assert.assertEquals(Math.log(0.5d) / Math.log(2), resultV.vector[4]);
// test long->double version
b = getVectorizedRowBatchLongInDoubleOut();
resultV = (DoubleColumnVector) b.cols[1];
b.cols[0].noNulls = true;
expr = new FuncLog2LongToDouble(0, 1);
expr.evaluate(b);
Assert.assertEquals(Math.log(1) / Math.log(2), resultV.vector[3]);
}
use of org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector in project hive by apache.
the class TestVectorMathFunctions method testVectorRand.
@Test
public void testVectorRand() {
VectorizedRowBatch b = new VectorizedRowBatch(1);
DoubleColumnVector v = new DoubleColumnVector();
b.cols[0] = v;
b.size = VectorizedRowBatch.DEFAULT_SIZE;
int n = b.size;
v.noNulls = true;
VectorExpression expr = new FuncRandNoSeed(0);
expr.evaluate(b);
double sum = 0;
for (int i = 0; i != n; i++) {
sum += v.vector[i];
Assert.assertTrue(v.vector[i] >= 0.0 && v.vector[i] <= 1.0);
}
double avg = sum / n;
/* The random values must be between 0 and 1, distributed uniformly.
* So the average value of a large set should be about 0.5. Verify it is
* close to this value.
*/
Assert.assertTrue(avg > 0.3 && avg < 0.7);
// Now, test again with a seed.
Arrays.fill(v.vector, 0);
expr = new FuncRand(99999, 0);
expr.evaluate(b);
sum = 0;
for (int i = 0; i != n; i++) {
sum += v.vector[i];
Assert.assertTrue(v.vector[i] >= 0.0 && v.vector[i] <= 1.0);
}
avg = sum / n;
Assert.assertTrue(avg > 0.3 && avg < 0.7);
}
Aggregations