Search in sources :

Example 1 with DecimalColModuloDecimalScalar

use of org.apache.hadoop.hive.ql.exec.vector.expressions.gen.DecimalColModuloDecimalScalar in project hive by apache.

the class TestVectorArithmeticExpressions method testDecimalColModuloDecimalScalar.

// Spot check Decimal Col-Scalar Modulo
@Test
public void testDecimalColModuloDecimalScalar() {
    VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
    HiveDecimal d = HiveDecimal.create("2.00");
    VectorExpression expr = new DecimalColModuloDecimalScalar(0, d, 2);
    // test without nulls
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("1.20")));
    assertTrue(r.vector[1].getHiveDecimal().equals(HiveDecimal.create("-1.30")));
    assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("0")));
    // try again with some different data values and divisor
    DecimalColumnVector in = (DecimalColumnVector) b.cols[0];
    in.vector[0].set(HiveDecimal.create("15.40"));
    in.vector[1].set(HiveDecimal.create("-17.20"));
    in.vector[2].set(HiveDecimal.create("70.00"));
    d = HiveDecimal.create("4.75");
    expr = new DecimalColModuloDecimalScalar(0, d, 2);
    expr.evaluate(b);
    assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("1.15")));
    assertTrue(r.vector[1].getHiveDecimal().equals(HiveDecimal.create("-2.95")));
    assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("3.50")));
    // try a zero-divide to show a repeating NULL is produced
    d = HiveDecimal.create("0.00");
    expr = new DecimalColModuloDecimalScalar(0, d, 2);
    expr.evaluate(b);
    assertFalse(r.noNulls);
    assertTrue(r.isNull[0]);
    assertTrue(r.isRepeating);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TestVectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch) DecimalColModuloDecimalScalar(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.DecimalColModuloDecimalScalar) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) Test(org.junit.Test)

Aggregations

HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)1 DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)1 TestVectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch)1 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)1 DecimalColModuloDecimalScalar (org.apache.hadoop.hive.ql.exec.vector.expressions.gen.DecimalColModuloDecimalScalar)1 Test (org.junit.Test)1