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