use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class TestVectorConditionalExpressions method testIfExprStringScalarStringColumn.
@Test
public void testIfExprStringScalarStringColumn() {
VectorizedRowBatch batch = getBatch1Long3BytesVectors();
byte[] scalar = getUTF8Bytes("scalar");
VectorExpression expr = new IfExprStringScalarStringGroupColumn(0, scalar, 2, 3);
BytesColumnVector r = (BytesColumnVector) batch.cols[3];
expr.evaluate(batch);
assertTrue(getString(r, 0).equals("arg3_0"));
assertTrue(getString(r, 1).equals("arg3_1"));
assertTrue(getString(r, 2).equals("scalar"));
assertTrue(getString(r, 3).equals("scalar"));
assertTrue(r.noNulls);
// test for null input strings
batch = getBatch1Long3BytesVectors();
BytesColumnVector arg3 = (BytesColumnVector) batch.cols[2];
arg3.noNulls = false;
arg3.isNull[1] = true;
arg3.vector[1] = null;
expr.evaluate(batch);
r = (BytesColumnVector) batch.cols[3];
assertTrue(!r.noNulls && r.isNull[1]);
}
use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class TestVectorConditionalExpressions method testIfExprStringColumnStringScalar.
@Test
public void testIfExprStringColumnStringScalar() {
VectorizedRowBatch batch = getBatch1Long3BytesVectors();
byte[] scalar = getUTF8Bytes("scalar");
VectorExpression expr = new IfExprStringGroupColumnStringScalar(0, 1, scalar, 3);
BytesColumnVector r = (BytesColumnVector) batch.cols[3];
expr.evaluate(batch);
assertTrue(getString(r, 0).equals("scalar"));
assertTrue(getString(r, 1).equals("scalar"));
assertTrue(getString(r, 2).equals("arg2_2"));
assertTrue(getString(r, 3).equals("arg2_3"));
assertTrue(r.noNulls);
// test for null input strings
batch = getBatch1Long3BytesVectors();
BytesColumnVector arg2 = (BytesColumnVector) batch.cols[1];
arg2.noNulls = false;
arg2.isNull[2] = true;
arg2.vector[2] = null;
expr.evaluate(batch);
r = (BytesColumnVector) batch.cols[3];
assertTrue(!r.noNulls && r.isNull[2]);
}
use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class DecimalToStringUnaryUDF method evaluate.
@Override
public void evaluate(VectorizedRowBatch batch) {
if (childExpressions != null) {
super.evaluateChildren(batch);
}
DecimalColumnVector inV = (DecimalColumnVector) batch.cols[inputColumn];
int[] sel = batch.selected;
int n = batch.size;
BytesColumnVector outV = (BytesColumnVector) batch.cols[outputColumn];
outV.initBuffer();
if (n == 0) {
//Nothing to do
return;
}
if (inV.noNulls) {
outV.noNulls = true;
if (inV.isRepeating) {
outV.isRepeating = true;
func(outV, inV, 0);
} else if (batch.selectedInUse) {
for (int j = 0; j != n; j++) {
int i = sel[j];
func(outV, inV, i);
}
outV.isRepeating = false;
} else {
for (int i = 0; i != n; i++) {
func(outV, inV, i);
}
outV.isRepeating = false;
}
} else {
// Handle case with nulls. Don't do function if the value is null,
// because the data may be undefined for a null value.
outV.noNulls = false;
if (inV.isRepeating) {
outV.isRepeating = true;
outV.isNull[0] = inV.isNull[0];
if (!inV.isNull[0]) {
func(outV, inV, 0);
}
} else if (batch.selectedInUse) {
for (int j = 0; j != n; j++) {
int i = sel[j];
outV.isNull[i] = inV.isNull[i];
if (!inV.isNull[i]) {
func(outV, inV, i);
}
}
outV.isRepeating = false;
} else {
System.arraycopy(inV.isNull, 0, outV.isNull, 0, n);
for (int i = 0; i != n; i++) {
if (!inV.isNull[i]) {
func(outV, inV, i);
}
}
outV.isRepeating = false;
}
}
}
use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class FilterStringColumnInList method evaluate.
@Override
public void evaluate(VectorizedRowBatch batch) {
if (childExpressions != null) {
super.evaluateChildren(batch);
}
if (inSet == null) {
inSet = new CuckooSetBytes(inListValues.length);
inSet.load(inListValues);
}
BytesColumnVector inputColVector = (BytesColumnVector) batch.cols[inputCol];
int[] sel = batch.selected;
boolean[] nullPos = inputColVector.isNull;
int n = batch.size;
byte[][] vector = inputColVector.vector;
int[] start = inputColVector.start;
int[] len = inputColVector.length;
// return immediately if batch is empty
if (n == 0) {
return;
}
if (inputColVector.noNulls) {
if (inputColVector.isRepeating) {
// Repeating property will not change.
if (!(inSet.lookup(vector[0], start[0], len[0]))) {
// Entire batch is filtered out.
batch.size = 0;
}
} else if (batch.selectedInUse) {
int newSize = 0;
for (int j = 0; j != n; j++) {
int i = sel[j];
if (inSet.lookup(vector[i], start[i], len[i])) {
sel[newSize++] = i;
}
}
batch.size = newSize;
} else {
int newSize = 0;
for (int i = 0; i != n; i++) {
if (inSet.lookup(vector[i], start[i], len[i])) {
sel[newSize++] = i;
}
}
if (newSize < n) {
batch.size = newSize;
batch.selectedInUse = true;
}
}
} else {
if (inputColVector.isRepeating) {
// Repeating property will not change.
if (!nullPos[0]) {
if (!inSet.lookup(vector[0], start[0], len[0])) {
// Entire batch is filtered out.
batch.size = 0;
}
} else {
batch.size = 0;
}
} else if (batch.selectedInUse) {
int newSize = 0;
for (int j = 0; j != n; j++) {
int i = sel[j];
if (!nullPos[i]) {
if (inSet.lookup(vector[i], start[i], len[i])) {
sel[newSize++] = i;
}
}
}
// Change the selected vector
batch.size = newSize;
} else {
int newSize = 0;
for (int i = 0; i != n; i++) {
if (!nullPos[i]) {
if (inSet.lookup(vector[i], start[i], len[i])) {
sel[newSize++] = i;
}
}
}
if (newSize < n) {
batch.size = newSize;
batch.selectedInUse = true;
}
}
}
}
use of org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector in project hive by apache.
the class FuncLongToString method evaluate.
@Override
public void evaluate(VectorizedRowBatch batch) {
if (childExpressions != null) {
super.evaluateChildren(batch);
}
LongColumnVector inputColVector = (LongColumnVector) batch.cols[inputCol];
int[] sel = batch.selected;
int n = batch.size;
long[] vector = inputColVector.vector;
BytesColumnVector outV = (BytesColumnVector) batch.cols[outputCol];
outV.initBuffer();
if (n == 0) {
//Nothing to do
return;
}
if (inputColVector.noNulls) {
outV.noNulls = true;
if (inputColVector.isRepeating) {
outV.isRepeating = true;
prepareResult(0, vector, outV);
} else if (batch.selectedInUse) {
for (int j = 0; j != n; j++) {
int i = sel[j];
prepareResult(i, vector, outV);
}
outV.isRepeating = false;
} else {
for (int i = 0; i != n; i++) {
prepareResult(i, vector, outV);
}
outV.isRepeating = false;
}
} else {
// Handle case with nulls. Don't do function if the value is null, to save time,
// because calling the function can be expensive.
outV.noNulls = false;
if (inputColVector.isRepeating) {
outV.isRepeating = true;
outV.isNull[0] = inputColVector.isNull[0];
if (!inputColVector.isNull[0]) {
prepareResult(0, vector, outV);
}
} else if (batch.selectedInUse) {
for (int j = 0; j != n; j++) {
int i = sel[j];
if (!inputColVector.isNull[i]) {
prepareResult(i, vector, outV);
}
outV.isNull[i] = inputColVector.isNull[i];
}
outV.isRepeating = false;
} else {
for (int i = 0; i != n; i++) {
if (!inputColVector.isNull[i]) {
prepareResult(i, vector, outV);
}
outV.isNull[i] = inputColVector.isNull[i];
}
outV.isRepeating = false;
}
}
}
Aggregations