Search in sources :

Example 66 with DoubleColumnVector

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]);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) FuncSinDoubleToDouble(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.FuncSinDoubleToDouble) Test(org.junit.Test)

Example 67 with DoubleColumnVector

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]);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) FuncACosDoubleToDouble(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.FuncACosDoubleToDouble) Test(org.junit.Test)

Example 68 with DoubleColumnVector

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;
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 69 with DoubleColumnVector

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]);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) FuncLog2DoubleToDouble(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.FuncLog2DoubleToDouble) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) FuncLog2LongToDouble(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.FuncLog2LongToDouble) Test(org.junit.Test)

Example 70 with DoubleColumnVector

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);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) Test(org.junit.Test)

Aggregations

DoubleColumnVector (org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)104 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)59 Test (org.junit.Test)37 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)33 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)18 DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)17 TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)13 ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)10 VectorizedParquetRecordReader (org.apache.hadoop.hive.ql.io.parquet.vector.VectorizedParquetRecordReader)9 Configuration (org.apache.hadoop.conf.Configuration)7 Random (java.util.Random)5 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)5 Timestamp (java.sql.Timestamp)4 TestVectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch)4 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)4 StructColumnVector (org.apache.hadoop.hive.ql.exec.vector.StructColumnVector)3 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)2 IntervalDayTimeColumnVector (org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector)2 ListColumnVector (org.apache.hadoop.hive.ql.exec.vector.ListColumnVector)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2