use of org.apache.hadoop.hive.ql.exec.vector.LongColumnVector in project hive by apache.
the class TestConstantVectorExpression method testConstantExpression.
@Test
public void testConstantExpression() {
ConstantVectorExpression longCve = new ConstantVectorExpression(0, 17);
ConstantVectorExpression doubleCve = new ConstantVectorExpression(1, 17.34);
String str = "alpha";
ConstantVectorExpression bytesCve = new ConstantVectorExpression(2, str.getBytes());
HiveDecimal decVal = HiveDecimal.create("25.8");
ConstantVectorExpression decimalCve = new ConstantVectorExpression(3, decVal, "decimal");
ConstantVectorExpression nullCve = new ConstantVectorExpression(4, "string", 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 TestVectorConditionalExpressions method testLongScalarScalarIfExpr.
@Test
public void testLongScalarScalarIfExpr() {
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.LongColumnVector in project hive by apache.
the class TestVectorConditionalExpressions method testLongColumnScalarIfExpr.
@Test
public void testLongColumnScalarIfExpr() {
VectorizedRowBatch batch = getBatch4LongVectors();
VectorExpression expr = new IfExprLongColumnLongScalar(0, 1, 100, 3);
LongColumnVector r = (LongColumnVector) batch.cols[3];
expr.evaluate(batch);
assertEquals(100, r.vector[0]);
assertEquals(100, r.vector[1]);
assertEquals(-3, r.vector[2]);
assertEquals(-4, r.vector[3]);
}
use of org.apache.hadoop.hive.ql.exec.vector.LongColumnVector 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;
}
use of org.apache.hadoop.hive.ql.exec.vector.LongColumnVector 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;
}
Aggregations