use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.
the class TestVectorArithmeticExpressions method testLongColAddLongScalarWithNulls.
@Test
public void testLongColAddLongScalarWithNulls() {
VectorizedRowBatch batch = getVectorizedRowBatchSingleLongVector(VectorizedRowBatch.DEFAULT_SIZE);
LongColumnVector lcv = (LongColumnVector) batch.cols[0];
LongColumnVector lcvOut = (LongColumnVector) batch.cols[1];
TestVectorizedRowBatch.addRandomNulls(lcv);
LongColAddLongScalar expr = new LongColAddLongScalar(0, 23, 1);
expr.evaluate(batch);
// verify
for (int i = 0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) {
if (!lcv.isNull[i]) {
Assert.assertEquals(i * 37 + 23, lcvOut.vector[i]);
} else {
Assert.assertTrue(lcvOut.isNull[i]);
}
}
Assert.assertFalse(lcvOut.noNulls);
Assert.assertFalse(lcvOut.isRepeating);
verifyLongNullDataVectorEntries(lcvOut, batch.selected, batch.selectedInUse, batch.size);
}
use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.
the class TestVectorArithmeticExpressions method testDecimalColDivideDecimalColumn.
@Test
public void testDecimalColDivideDecimalColumn() {
VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
DecimalColumnVector in1 = (DecimalColumnVector) b.cols[1];
for (int i = 0; i < 3; i++) {
in1.vector[i].set(HiveDecimal.create("0.50"));
}
VectorExpression expr = new DecimalColDivideDecimalColumn(0, 1, 2);
expr.evaluate(b);
DecimalColumnVector r = (DecimalColumnVector) b.cols[2];
// all divides are by 0.50 so the result column is 2 times col 0.
assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("2.4")));
assertTrue(r.vector[1].getHiveDecimal().equals(HiveDecimal.create("-6.6")));
assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("0")));
// test null on left
b.cols[0].noNulls = false;
b.cols[0].isNull[0] = true;
expr.evaluate(b);
assertFalse(r.noNulls);
assertTrue(r.isNull[0]);
// test null on right
b = getVectorizedRowBatch3DecimalCols();
b.cols[1].noNulls = false;
b.cols[1].isNull[0] = true;
r = (DecimalColumnVector) b.cols[2];
expr.evaluate(b);
assertFalse(r.noNulls);
assertTrue(r.isNull[0]);
// test null on both sides
b = getVectorizedRowBatch3DecimalCols();
b.cols[0].noNulls = false;
b.cols[0].isNull[0] = true;
b.cols[1].noNulls = false;
b.cols[1].isNull[0] = true;
expr.evaluate(b);
assertFalse(r.noNulls);
assertTrue(r.isNull[0]);
assertFalse(r.isNull[1]);
assertFalse(r.isNull[2]);
// test repeating on left
b = getVectorizedRowBatch3DecimalCols();
b.cols[0].isRepeating = true;
expr.evaluate(b);
r = (DecimalColumnVector) b.cols[2];
assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("1.2")));
// test repeating on right
b = getVectorizedRowBatch3DecimalCols();
b.cols[1].isRepeating = true;
expr.evaluate(b);
r = (DecimalColumnVector) b.cols[2];
assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("0")));
// test both repeating
b = getVectorizedRowBatch3DecimalCols();
b.cols[0].isRepeating = true;
b.cols[1].isRepeating = true;
expr.evaluate(b);
r = (DecimalColumnVector) b.cols[2];
assertTrue(r.isRepeating);
assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("1.2")));
// test zero-divide to show it results in NULL
b = getVectorizedRowBatch3DecimalCols();
((DecimalColumnVector) b.cols[1]).vector[0].set(HiveDecimal.create("0"));
expr.evaluate(b);
r = (DecimalColumnVector) b.cols[2];
assertFalse(r.noNulls);
assertTrue(r.isNull[0]);
}
use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch 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.VectorizedRowBatch in project hive by apache.
the class TestVectorArithmeticExpressions method testDecimalColSubtractDecimalColumn.
// Spot check decimal column-column subtract
@Test
public void testDecimalColSubtractDecimalColumn() {
VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
VectorExpression expr = new DecimalColSubtractDecimalColumn(0, 1, 2);
DecimalColumnVector r = (DecimalColumnVector) b.cols[2];
// test without nulls
expr.evaluate(b);
assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("0.20")));
assertTrue(r.vector[1].getHiveDecimal().equals(HiveDecimal.create("-4.30")));
assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("-1.00")));
// test that underflow produces NULL
b = getVectorizedRowBatch3DecimalCols();
DecimalColumnVector c0 = (DecimalColumnVector) b.cols[0];
// set to min possible value
c0.vector[0].set(HiveDecimal.create("-9999999999999999.99"));
r = (DecimalColumnVector) b.cols[2];
// will cause underflow for result at position 0, must yield NULL
expr.evaluate(b);
assertTrue(!r.noNulls && r.isNull[0]);
}
use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.
the class TestVectorConditionalExpressions method testDoubleColumnColumnIfExpr.
@Test
public void testDoubleColumnColumnIfExpr() {
// Just spot check because we already checked the logic for long.
// The code is from the same template file.
VectorizedRowBatch batch = getBatch1Long3DoubleVectors();
VectorExpression expr = new IfExprDoubleColumnDoubleColumn(0, 1, 2, 3);
expr.evaluate(batch);
// get result vector
DoubleColumnVector r = (DoubleColumnVector) batch.cols[3];
// verify standard case
assertEquals(true, 1d == r.vector[0]);
assertEquals(true, 2d == r.vector[1]);
assertEquals(true, -3d == r.vector[2]);
assertEquals(true, -4d == r.vector[3]);
assertEquals(true, r.noNulls);
assertEquals(false, r.isRepeating);
}
Aggregations