use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.
the class TestVectorArithmeticExpressions method testDecimalColMultiplyDecimalScalar.
/* Spot check correctness of decimal column multiply decimal scalar. The case for
* addition checks all the cases for the template, so don't do that redundantly here.
*/
@Test
public void testDecimalColMultiplyDecimalScalar() throws HiveException {
VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
HiveDecimal d = HiveDecimal.create(2);
VectorExpression expr = new DecimalColMultiplyDecimalScalar(0, d, 2);
// test without nulls
expr.evaluate(b);
DecimalColumnVector r = (DecimalColumnVector) b.cols[2];
assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("2.40")));
assertTrue(r.vector[1].getHiveDecimal().equals(HiveDecimal.create("-6.60")));
assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("0")));
// test that overflow produces null
b = getVectorizedRowBatch3DecimalCols();
DecimalColumnVector in = (DecimalColumnVector) b.cols[0];
// set to max possible value
in.vector[0].set(HiveDecimal.create("9999999999999999.99"));
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 TestVectorConditionalExpressions method testLongScalarScalarIfExpr.
@Test
public void testLongScalarScalarIfExpr() throws HiveException {
VectorizedRowBatch batch = getBatch4LongVectors();
VectorExpression expr = new IfExprLongScalarLongScalar(0, 100, 200, 3);
LongColumnVector r = (LongColumnVector) batch.cols[3];
expr.evaluate(batch);
assertEquals(200, r.vector[0]);
assertEquals(200, r.vector[1]);
assertEquals(100, r.vector[2]);
assertEquals(100, r.vector[3]);
}
use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.
the class TestVectorConditionalExpressions method testIfExprStringScalarStringScalar.
@Test
public void testIfExprStringScalarStringScalar() throws HiveException {
// standard case
VectorizedRowBatch batch = getBatch1Long3BytesVectors();
byte[] scalar1 = getUTF8Bytes("scalar1");
byte[] scalar2 = getUTF8Bytes("scalar2");
VectorExpression expr = new IfExprStringScalarStringScalar(0, scalar1, scalar2, 3);
BytesColumnVector r = (BytesColumnVector) batch.cols[3];
expr.evaluate(batch);
assertTrue(getString(r, 0).equals("scalar2"));
assertTrue(getString(r, 1).equals("scalar2"));
assertTrue(getString(r, 2).equals("scalar1"));
assertTrue(getString(r, 3).equals("scalar1"));
assertFalse(r.isRepeating);
// repeating case for first (boolean flag) argument to IF
batch = getBatch1Long3BytesVectors();
batch.cols[0].isRepeating = true;
expr.evaluate(batch);
r = (BytesColumnVector) batch.cols[3];
assertTrue(r.isRepeating);
assertTrue(getString(r, 0).equals("scalar2"));
}
use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.
the class TestVectorConditionalExpressions method getBatch1Long3BytesVectors.
private VectorizedRowBatch getBatch1Long3BytesVectors() {
VectorizedRowBatch batch = new VectorizedRowBatch(4);
LongColumnVector lv = new LongColumnVector();
// set first argument to IF -- boolean flag
lv.vector[0] = 0;
lv.vector[1] = 0;
lv.vector[2] = 1;
lv.vector[3] = 1;
batch.cols[0] = lv;
// set second argument to IF
BytesColumnVector v = new BytesColumnVector();
v.initBuffer();
setString(v, 0, "arg2_0");
setString(v, 1, "arg2_1");
setString(v, 2, "arg2_2");
setString(v, 3, "arg2_3");
batch.cols[1] = v;
// set third argument to IF
v = new BytesColumnVector();
v.initBuffer();
setString(v, 0, "arg3_0");
setString(v, 1, "arg3_1");
setString(v, 2, "arg3_2");
setString(v, 3, "arg3_3");
batch.cols[2] = v;
// set output column
v = new BytesColumnVector();
v.initBuffer();
batch.cols[3] = v;
batch.size = 4;
return batch;
}
use of org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch in project hive by apache.
the class TestVectorConditionalExpressions method getBatch1Long3DoubleVectors.
private VectorizedRowBatch getBatch1Long3DoubleVectors() {
VectorizedRowBatch batch = new VectorizedRowBatch(4);
LongColumnVector lv = new LongColumnVector();
// set first argument to IF -- boolean flag
lv.vector[0] = 0;
lv.vector[1] = 0;
lv.vector[2] = 1;
lv.vector[3] = 1;
batch.cols[0] = lv;
// set second argument to IF
DoubleColumnVector v = new DoubleColumnVector();
v.vector[0] = -1;
v.vector[1] = -2;
v.vector[2] = -3;
v.vector[3] = -4;
batch.cols[1] = v;
// set third argument to IF
v = new DoubleColumnVector();
v.vector[0] = 1;
v.vector[1] = 2;
v.vector[2] = 3;
v.vector[3] = 4;
batch.cols[2] = v;
// set output column
batch.cols[3] = new DoubleColumnVector();
batch.size = 4;
return batch;
}
Aggregations