use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.
the class TestVectorDateExpressions method testVectorUDFWeekOfYear.
@Test
public void testVectorUDFWeekOfYear() throws HiveException {
VectorizedRowBatch batch = getVectorizedRowBatch(new int[] { 0 }, VectorizedRowBatch.DEFAULT_SIZE);
Assert.assertTrue(((LongColumnVector) batch.cols[1]).noNulls);
Assert.assertFalse(((LongColumnVector) batch.cols[1]).isRepeating);
verifyUDFWeekOfYear(batch);
TestVectorizedRowBatch.addRandomNulls(batch.cols[0]);
verifyUDFWeekOfYear(batch);
int[] boundaries = getAllBoundaries();
batch = getVectorizedRowBatch(boundaries, boundaries.length);
verifyUDFWeekOfYear(batch);
TestVectorizedRowBatch.addRandomNulls(batch.cols[0]);
verifyUDFWeekOfYear(batch);
TestVectorizedRowBatch.addRandomNulls(batch.cols[1]);
verifyUDFWeekOfYear(batch);
batch = getVectorizedRowBatch(new int[] { 0 }, 1);
batch.cols[0].isRepeating = true;
verifyUDFWeekOfYear(batch);
batch.cols[0].noNulls = false;
batch.cols[0].isNull[0] = true;
verifyUDFWeekOfYear(batch);
batch = getVectorizedRandomRowBatch(200, VectorizedRowBatch.DEFAULT_SIZE);
verifyUDFWeekOfYear(batch);
TestVectorizedRowBatch.addRandomNulls(batch.cols[0]);
verifyUDFWeekOfYear(batch);
TestVectorizedRowBatch.addRandomNulls(batch.cols[1]);
verifyUDFWeekOfYear(batch);
}
use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.
the class TestUnaryMinus method testUnaryMinusCheckedOverflow.
@Test
public void testUnaryMinusCheckedOverflow() throws HiveException {
VectorizedRowBatch vrg = VectorizedRowGroupGenUtil.getVectorizedRowBatch(1, 2, 0);
// set value to MIN_VALUE so that -MIN_VALUE overflows and gets set to MIN_VALUE again
((LongColumnVector) vrg.cols[0]).vector[0] = Integer.MIN_VALUE;
LongColUnaryMinusChecked expr = new LongColUnaryMinusChecked(0, 1);
expr.setOutputTypeInfo(TypeInfoFactory.getPrimitiveTypeInfo("int"));
expr.evaluate(vrg);
// verify
long[] inVector = ((LongColumnVector) vrg.cols[0]).vector;
long[] outVector = ((LongColumnVector) vrg.cols[1]).vector;
for (int i = 0; i < outVector.length; i++) {
assertEquals(Integer.MIN_VALUE, outVector[i]);
}
}
use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.
the class TestUnaryMinus method testUnaryMinus.
@Test
public void testUnaryMinus() throws HiveException {
VectorizedRowBatch vrg = VectorizedRowGroupGenUtil.getVectorizedRowBatch(1024, 2, 23);
LongColUnaryMinus expr = new LongColUnaryMinus(0, 1);
expr.evaluate(vrg);
// verify
long[] inVector = ((LongColumnVector) vrg.cols[0]).vector;
long[] outVector = ((LongColumnVector) vrg.cols[1]).vector;
for (int i = 0; i < outVector.length; i++) {
assertEquals(0, inVector[i] + outVector[i]);
}
}
use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.
the class TestVectorArithmeticExpressions method testDecimalColDivideDecimalColumn.
@Test
public void testDecimalColDivideDecimalColumn() throws HiveException {
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 longColAddLongColumnUtil.
private void longColAddLongColumnUtil(boolean isChecked) throws HiveException {
int seed = 17;
VectorizedRowBatch vrg = VectorizedRowGroupGenUtil.getVectorizedRowBatch(VectorizedRowBatch.DEFAULT_SIZE, 6, seed);
LongColumnVector lcv0 = (LongColumnVector) vrg.cols[0];
LongColumnVector lcv1 = (LongColumnVector) vrg.cols[1];
LongColumnVector lcv2 = (LongColumnVector) vrg.cols[2];
LongColumnVector lcv3 = (LongColumnVector) vrg.cols[3];
LongColumnVector lcv4 = (LongColumnVector) vrg.cols[4];
LongColumnVector lcv5 = (LongColumnVector) vrg.cols[5];
VectorExpression expr;
if (isChecked) {
expr = new LongColAddLongColumnChecked(0, 1, 2);
expr.setOutputTypeInfo(TypeInfoFactory.getPrimitiveTypeInfo("bigint"));
} else {
expr = new LongColAddLongColumn(0, 1, 2);
}
expr.evaluate(vrg);
for (int i = 0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) {
assertEquals((i + 1) * seed * 3, lcv2.vector[i]);
}
assertTrue(lcv2.noNulls);
// Now set one column nullable
lcv1.noNulls = false;
lcv1.isNull[1] = true;
// set output isRepeating to true to make sure it gets over-written
lcv2.isRepeating = true;
// similarly with noNulls
lcv2.noNulls = true;
expr.evaluate(vrg);
assertTrue(lcv2.isNull[1]);
assertFalse(lcv2.noNulls);
assertFalse(lcv2.isRepeating);
verifyLongNullDataVectorEntries(lcv2, vrg.selected, vrg.selectedInUse, vrg.size);
// Now set other column nullable too
lcv0.noNulls = false;
lcv0.isNull[1] = true;
lcv0.isNull[3] = true;
expr.evaluate(vrg);
assertTrue(lcv2.isNull[1]);
assertTrue(lcv2.isNull[3]);
assertFalse(lcv2.noNulls);
verifyLongNullDataVectorEntries(lcv2, vrg.selected, vrg.selectedInUse, vrg.size);
// Now test with repeating flag
lcv3.isRepeating = true;
VectorExpression expr2;
if (isChecked) {
expr2 = new LongColAddLongColumnChecked(3, 4, 5);
expr2.setOutputTypeInfo(TypeInfoFactory.getPrimitiveTypeInfo("bigint"));
} else {
expr2 = new LongColAddLongColumn(3, 4, 5);
}
expr2.evaluate(vrg);
for (int i = 0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) {
assertEquals(seed * (4 + 5 * (i + 1)), lcv5.vector[i]);
}
// Repeating with other as nullable
lcv4.noNulls = false;
lcv4.isNull[0] = true;
expr2.evaluate(vrg);
assertTrue(lcv5.isNull[0]);
assertFalse(lcv5.noNulls);
verifyLongNullDataVectorEntries(lcv5, vrg.selected, vrg.selectedInUse, vrg.size);
// Repeating null value
lcv3.isRepeating = true;
lcv3.noNulls = false;
lcv3.isNull[0] = true;
expr2.evaluate(vrg);
assertFalse(lcv5.noNulls);
assertTrue(lcv5.isRepeating);
assertTrue(lcv5.isNull[0]);
verifyLongNullDataVectorEntries(lcv5, vrg.selected, vrg.selectedInUse, vrg.size);
// Neither input has nulls. Verify that this propagates to output.
vrg.selectedInUse = false;
lcv0.noNulls = true;
lcv1.noNulls = true;
lcv0.isRepeating = false;
lcv1.isRepeating = false;
lcv2.reset();
expr.evaluate(vrg);
assertTrue(lcv2.noNulls);
assertFalse(lcv2.isRepeating);
}
Aggregations