Search in sources :

Example 96 with BytesColumnVector

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]);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) IfExprStringScalarStringGroupColumn(org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprStringScalarStringGroupColumn) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) Test(org.junit.Test)

Example 97 with BytesColumnVector

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]);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) IfExprStringGroupColumnStringScalar(org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprStringGroupColumnStringScalar) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) Test(org.junit.Test)

Example 98 with BytesColumnVector

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;
        }
    }
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)

Example 99 with BytesColumnVector

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;
            }
        }
    }
}
Also used : BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)

Example 100 with BytesColumnVector

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;
        }
    }
}
Also used : BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Aggregations

BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)124 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)66 Test (org.junit.Test)50 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)44 TestVectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch)12 DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)10 DoubleColumnVector (org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)8 TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)8 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)8 Text (org.apache.hadoop.io.Text)8 ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Path (org.apache.hadoop.fs.Path)4 JoinUtil (org.apache.hadoop.hive.ql.exec.JoinUtil)4 VectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression)4 TypeDescription (org.apache.orc.TypeDescription)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ParseException (java.text.ParseException)3 Random (java.util.Random)3