use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class TestVectorFilterExpressions method testFilterStringIn.
@Test
public void testFilterStringIn() {
int seed = 17;
VectorizedRowBatch vrb = VectorizedRowGroupGenUtil.getVectorizedRowBatch(3, 2, seed);
vrb.cols[0] = new BytesColumnVector();
BytesColumnVector bcv = (BytesColumnVector) vrb.cols[0];
bcv.initBuffer();
bcv.setVal(0, a, 0, 1);
bcv.setVal(1, b, 0, 1);
bcv.setVal(2, c, 0, 1);
VectorExpression expr = new FilterStringColumnInList(0);
byte[][] inList = { b, c };
((FilterStringColumnInList) expr).setInListValues(inList);
// basic test
expr.evaluate(vrb);
assertEquals(2, vrb.size);
assertTrue(vrb.selectedInUse);
assertEquals(1, vrb.selected[0]);
assertEquals(2, vrb.selected[1]);
// nulls
vrb.selectedInUse = false;
vrb.size = 3;
bcv.noNulls = false;
bcv.isNull[2] = true;
expr.evaluate(vrb);
assertEquals(1, vrb.size);
assertEquals(1, vrb.selected[0]);
assertTrue(vrb.selectedInUse);
// repeating
vrb.selectedInUse = false;
vrb.size = 3;
bcv.noNulls = true;
bcv.isRepeating = true;
expr.evaluate(vrb);
assertEquals(0, vrb.size);
// nulls and repeating
vrb.selectedInUse = false;
vrb.size = 3;
bcv.noNulls = false;
bcv.isRepeating = true;
bcv.isNull[0] = true;
bcv.setVal(0, b, 0, 1);
expr.evaluate(vrb);
assertEquals(0, vrb.size);
}
use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class TestVectorGenericDateExpressions method testDateDiffColScalar.
@Test
public void testDateDiffColScalar() {
for (VectorExpression.Type colType1 : dateTimestampStringTypes) {
for (VectorExpression.Type scalarType2 : dateTimestampStringTypes) {
LongColumnVector date1 = newRandomLongColumnVector(10000, size);
LongColumnVector output = new LongColumnVector(size);
VectorizedRowBatch batch = new VectorizedRowBatch(2, size);
batch.cols[0] = castTo(date1, colType1);
batch.cols[1] = output;
long scalar2 = newRandom(1000);
validateDateDiff(batch, date1, scalar2, colType1, scalarType2);
TestVectorizedRowBatch.addRandomNulls(date1);
batch.cols[0] = castTo(date1, colType1);
validateDateDiff(batch, date1, scalar2, colType1, scalarType2);
}
}
VectorExpression udf;
byte[] bytes = "error".getBytes(utf8);
VectorizedRowBatch batch = new VectorizedRowBatch(2, 1);
udf = new VectorUDFDateDiffColScalar(0, 0L, 1);
udf.setInputTypes(VectorExpression.Type.TIMESTAMP, VectorExpression.Type.STRING);
batch.cols[0] = new BytesColumnVector(1);
batch.cols[1] = new LongColumnVector(1);
BytesColumnVector bcv = (BytesColumnVector) batch.cols[0];
bcv.vector[0] = bytes;
bcv.start[0] = 0;
bcv.length[0] = bytes.length;
udf.evaluate(batch);
Assert.assertEquals(batch.cols[1].isNull[0], true);
udf = new VectorUDFDateDiffColScalar(0, bytes, 1);
udf.setInputTypes(VectorExpression.Type.TIMESTAMP, VectorExpression.Type.STRING);
batch.cols[0] = new LongColumnVector(1);
batch.cols[1] = new LongColumnVector(1);
udf.evaluate(batch);
Assert.assertEquals(batch.cols[1].isNull[0], true);
}
use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class TestVectorGenericDateExpressions method toString.
private BytesColumnVector toString(LongColumnVector date) {
BytesColumnVector bcv = new BytesColumnVector(size);
for (int i = 0; i < size; i++) {
if (date.isNull[i]) {
bcv.isNull[i] = true;
bcv.noNulls = false;
} else {
bcv.vector[i] = toString(date.vector[i]);
bcv.start[i] = 0;
bcv.length[i] = bcv.vector[i].length;
}
}
return bcv;
}
use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class TestVectorGenericDateExpressions method testToDate.
@Test
public void testToDate() {
for (VectorExpression.Type type : Arrays.asList(VectorExpression.Type.TIMESTAMP, VectorExpression.Type.STRING)) {
LongColumnVector date = newRandomLongColumnVector(10000, size);
LongColumnVector output = new LongColumnVector(size);
VectorizedRowBatch batch = new VectorizedRowBatch(2, size);
batch.cols[0] = castTo(date, type);
batch.cols[1] = output;
validateToDate(batch, type, date);
TestVectorizedRowBatch.addRandomNulls(date);
batch.cols[0] = castTo(date, type);
validateToDate(batch, type, date);
}
VectorExpression udf = new CastStringToDate(0, 1);
udf.setInputTypes(VectorExpression.Type.STRING);
VectorizedRowBatch batch = new VectorizedRowBatch(2, 1);
batch.cols[0] = new BytesColumnVector(1);
batch.cols[1] = new LongColumnVector(1);
BytesColumnVector bcv = (BytesColumnVector) batch.cols[0];
byte[] bytes = "error".getBytes(utf8);
bcv.vector[0] = bytes;
bcv.start[0] = 0;
bcv.length[0] = bytes.length;
udf.evaluate(batch);
Assert.assertEquals(batch.cols[1].isNull[0], true);
}
use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class TestVectorMathFunctions method testVectorHex.
@Test
public void testVectorHex() {
// test long->string version
VectorizedRowBatch b = getBatchForStringMath();
BytesColumnVector resultV = (BytesColumnVector) b.cols[2];
b.cols[1].noNulls = true;
VectorExpression expr = new FuncHex(1, 2);
expr.evaluate(b);
String s = new String(resultV.vector[1], resultV.start[1], resultV.length[1]);
Assert.assertEquals("FF", s);
// test string->string version
b = getBatchForStringMath();
resultV = (BytesColumnVector) b.cols[2];
b.cols[0].noNulls = true;
expr = new StringHex(0, 2);
expr.evaluate(b);
s = new String(resultV.vector[1], resultV.start[1], resultV.length[1]);
Assert.assertEquals("33323332", s);
}
Aggregations