use of org.apache.hadoop.hive.ql.exec.vector.LongColumnVector in project hive by apache.
the class TestConstantVectorExpression method testConstantExpression.
@Test
public void testConstantExpression() throws Exception {
ConstantVectorExpression longCve = new ConstantVectorExpression(0, 17, TypeInfoFactory.longTypeInfo);
ConstantVectorExpression doubleCve = new ConstantVectorExpression(1, 17.34, TypeInfoFactory.doubleTypeInfo);
String str = "alpha";
ConstantVectorExpression bytesCve = new ConstantVectorExpression(2, str.getBytes(), TypeInfoFactory.stringTypeInfo);
HiveDecimal decVal = HiveDecimal.create("25.8");
ConstantVectorExpression decimalCve = new ConstantVectorExpression(3, decVal, TypeInfoFactory.decimalTypeInfo);
ConstantVectorExpression nullCve = new ConstantVectorExpression(4, TypeInfoFactory.stringTypeInfo, true);
int size = 20;
VectorizedRowBatch vrg = VectorizedRowGroupGenUtil.getVectorizedRowBatch(size, 5, 0);
LongColumnVector lcv = (LongColumnVector) vrg.cols[0];
DoubleColumnVector dcv = new DoubleColumnVector(size);
BytesColumnVector bcv = new BytesColumnVector(size);
DecimalColumnVector dv = new DecimalColumnVector(5, 1);
BytesColumnVector bcvn = new BytesColumnVector(size);
vrg.cols[1] = dcv;
vrg.cols[2] = bcv;
vrg.cols[3] = dv;
vrg.cols[4] = bcvn;
longCve.evaluate(vrg);
doubleCve.evaluate(vrg);
bytesCve.evaluate(vrg);
decimalCve.evaluate(vrg);
nullCve.evaluate(vrg);
assertTrue(lcv.isRepeating);
assertTrue(dcv.isRepeating);
assertTrue(bcv.isRepeating);
assertEquals(17, lcv.vector[0]);
assertTrue(17.34 == dcv.vector[0]);
assertTrue(bcvn.isRepeating);
assertTrue(bcvn.isNull[0]);
assertTrue(!bcvn.noNulls);
byte[] alphaBytes = "alpha".getBytes();
assertTrue(bcv.length[0] == alphaBytes.length);
assertTrue(sameFirstKBytes(alphaBytes, bcv.vector[0], alphaBytes.length));
// Evaluation of the bytes Constant Vector Expression after the vector is
// modified.
((BytesColumnVector) (vrg.cols[2])).vector[0] = "beta".getBytes();
bytesCve.evaluate(vrg);
assertTrue(bcv.length[0] == alphaBytes.length);
assertTrue(sameFirstKBytes(alphaBytes, bcv.vector[0], alphaBytes.length));
assertTrue(25.8 == dv.vector[0].getHiveDecimal().doubleValue());
// Evaluation of the decimal Constant Vector Expression after the vector is
// modified.
((DecimalColumnVector) (vrg.cols[3])).vector[0].set(HiveDecimal.create("39.7"));
decimalCve.evaluate(vrg);
assertTrue(25.8 == dv.vector[0].getHiveDecimal().doubleValue());
}
use of org.apache.hadoop.hive.ql.exec.vector.LongColumnVector in project hive by apache.
the class TestUnaryMinus method testUnaryMinus.
@Test
public void testUnaryMinus() {
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.LongColumnVector in project hive by apache.
the class TestUnaryMinus method testUnaryMinusCheckedOverflow.
@Test
public void testUnaryMinusCheckedOverflow() {
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.LongColumnVector in project hive by apache.
the class TestVectorArithmeticExpressions method longColAddLongScalarNoNulls.
private void longColAddLongScalarNoNulls(boolean checked) {
VectorizedRowBatch vrg = getVectorizedRowBatchSingleLongVector(VectorizedRowBatch.DEFAULT_SIZE);
VectorExpression expr;
if (checked) {
expr = new LongColAddLongScalarChecked(0, 23, 1);
expr.setOutputTypeInfo(TypeInfoFactory.getPrimitiveTypeInfo("bigint"));
} else {
expr = new LongColAddLongScalar(0, 23, 1);
}
expr.evaluate(vrg);
// verify
for (int i = 0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) {
Assert.assertEquals(i * 37 + 23, ((LongColumnVector) vrg.cols[1]).vector[i]);
}
Assert.assertTrue(((LongColumnVector) vrg.cols[1]).noNulls);
Assert.assertFalse(((LongColumnVector) vrg.cols[1]).isRepeating);
}
use of org.apache.hadoop.hive.ql.exec.vector.LongColumnVector in project hive by apache.
the class TestVectorArithmeticExpressions method longColAddLongColumnUtil.
private void longColAddLongColumnUtil(boolean isChecked) {
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