Search in sources :

Example 61 with ColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.ColumnVector in project hive by apache.

the class VectorUDAFCount method aggregateInputSelection.

@Override
public void aggregateInputSelection(VectorAggregationBufferRow[] aggregationBufferSets, int aggregateIndex, VectorizedRowBatch batch) throws HiveException {
    int batchSize = batch.size;
    if (batchSize == 0) {
        return;
    }
    inputExpression.evaluate(batch);
    ColumnVector inputVector = batch.cols[this.inputExpression.getOutputColumnNum()];
    if (inputVector.isRepeating) {
        if (inputVector.noNulls || !inputVector.isNull[0]) {
            iterateNoNullsWithAggregationSelection(aggregationBufferSets, aggregateIndex, batchSize);
        }
    } else if (inputVector.noNulls) {
        // if there are no nulls then the iteration is the same on all cases
        iterateNoNullsWithAggregationSelection(aggregationBufferSets, aggregateIndex, batchSize);
    } else if (!batch.selectedInUse) {
        iterateHasNullsWithAggregationSelection(aggregationBufferSets, aggregateIndex, batchSize, inputVector.isNull);
    } else if (batch.selectedInUse) {
        iterateHasNullsSelectionWithAggregationSelection(aggregationBufferSets, aggregateIndex, batchSize, batch.selected, inputVector.isNull);
    }
}
Also used : ColumnVector(org.apache.hadoop.hive.ql.exec.vector.ColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 62 with ColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.ColumnVector in project hive by apache.

the class IfExprColumnCondExpr method evaluate.

@Override
public void evaluate(VectorizedRowBatch batch) {
    int n = batch.size;
    if (n <= 0) {
        // Nothing to do
        return;
    }
    /*
     * Do common analysis of the IF statement boolean expression.
     *
     * The following protected members can be examined afterwards:
     *
     *   boolean isIfStatementResultRepeated
     *   boolean isIfStatementResultThen
     *
     *   int thenSelectedCount
     *   int[] thenSelected
     *   int elseSelectedCount
     *   int[] elseSelected
     */
    super.evaluate(batch);
    ColumnVector outputColVector = batch.cols[outputColumnNum];
    boolean[] outputIsNull = outputColVector.isNull;
    // We do not need to do a column reset since we are carefully changing the output.
    outputColVector.isRepeating = false;
    // CONSIDER: Should be do this for all vector expressions that can
    // work on BytesColumnVector output columns???
    outputColVector.init();
    ColumnVector thenColVector = batch.cols[arg2Column];
    ColumnVector elseColVector = batch.cols[arg3Column];
    final int thenCount = thenSelectedCount;
    final int elseCount = elseSelectedCount;
    if (isIfStatementResultRepeated) {
        if (isIfStatementResultThen) {
            // Evaluate THEN expression (only) and copy all its results.
            childExpressions[1].evaluate(batch);
            thenColVector.copySelected(batch.selectedInUse, batch.selected, n, outputColVector);
        } else {
            // Evaluate ELSE expression (only) and copy all its results.
            childExpressions[2].evaluate(batch);
            elseColVector.copySelected(batch.selectedInUse, batch.selected, n, outputColVector);
        }
        return;
    }
    // NOTE: We cannot use copySelected below since it is a whole column operation.
    // The THEN expression is either IdentityExpression (a column) or a ConstantVectorExpression
    // (a scalar) and trivial to evaluate.
    childExpressions[1].evaluate(batch);
    for (int i = 0; i < thenCount; i++) {
        final int batchIndex = thenSelected[i];
        outputIsNull[batchIndex] = false;
        outputColVector.setElement(batchIndex, batchIndex, thenColVector);
    }
    conditionalEvaluate(batch, childExpressions[2], elseSelected, elseCount);
    for (int i = 0; i < elseCount; i++) {
        final int batchIndex = elseSelected[i];
        outputIsNull[batchIndex] = false;
        outputColVector.setElement(batchIndex, batchIndex, elseColVector);
    }
}
Also used : ColumnVector(org.apache.hadoop.hive.ql.exec.vector.ColumnVector)

Example 63 with ColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.ColumnVector in project hive by apache.

the class IfExprCondExprNull method evaluate.

@Override
public void evaluate(VectorizedRowBatch batch) {
    int n = batch.size;
    if (n <= 0) {
        // Nothing to do
        return;
    }
    /*
     * Do common analysis of the IF statement boolean expression.
     *
     * The following protected members can be examined afterwards:
     *
     *   boolean isIfStatementResultRepeated
     *   boolean isIfStatementResultThen
     *
     *   int thenSelectedCount
     *   int[] thenSelected
     *   int elseSelectedCount
     *   int[] elseSelected
     */
    super.evaluate(batch);
    ColumnVector outputColVector = batch.cols[outputColumnNum];
    boolean[] outputIsNull = outputColVector.isNull;
    // We do not need to do a column reset since we are carefully changing the output.
    outputColVector.isRepeating = false;
    // CONSIDER: Should be do this for all vector expressions that can
    // work on BytesColumnVector output columns???
    outputColVector.init();
    ColumnVector thenColVector = batch.cols[arg2Column];
    final int thenCount = thenSelectedCount;
    final int elseCount = elseSelectedCount;
    if (isIfStatementResultRepeated) {
        if (isIfStatementResultThen) {
            // Evaluate THEN expression (only) and copy all its results.
            childExpressions[1].evaluate(batch);
            thenColVector.copySelected(batch.selectedInUse, batch.selected, n, outputColVector);
        } else {
            outputIsNull[0] = true;
            outputColVector.noNulls = false;
            outputColVector.isRepeating = true;
        }
        return;
    }
    // NOTE: We cannot use copySelected below since it is a whole column operation.
    conditionalEvaluate(batch, childExpressions[1], thenSelected, thenCount);
    for (int i = 0; i < thenCount; i++) {
        final int batchIndex = thenSelected[i];
        outputIsNull[batchIndex] = false;
        outputColVector.setElement(batchIndex, batchIndex, thenColVector);
    }
    outputColVector.noNulls = false;
    for (int i = 0; i < elseCount; i++) {
        outputColVector.isNull[elseSelected[i]] = true;
    }
}
Also used : ColumnVector(org.apache.hadoop.hive.ql.exec.vector.ColumnVector)

Example 64 with ColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.ColumnVector in project hive by apache.

the class IfExprNullColumn method evaluate.

@Override
public void evaluate(VectorizedRowBatch batch) {
    if (childExpressions != null) {
        super.evaluateChildren(batch);
    }
    final LongColumnVector arg1ColVector = (LongColumnVector) batch.cols[arg1Column];
    final ColumnVector arg2ColVector = batch.cols[arg2Column];
    final ColumnVector outputColVector = batch.cols[outputColumnNum];
    final int[] sel = batch.selected;
    final int n = batch.size;
    final boolean[] null1 = arg1ColVector.isNull;
    final long[] vector1 = arg1ColVector.vector;
    final boolean[] isNull = outputColVector.isNull;
    if (n == 0) {
        return;
    }
    // We do not need to do a column reset since we are carefully changing the output.
    outputColVector.isRepeating = false;
    /*
     * Repeating IF expression?
     */
    if (arg1ColVector.isRepeating) {
        if ((arg1ColVector.noNulls || !null1[0]) && vector1[0] == 1) {
            outputColVector.isRepeating = true;
            outputColVector.noNulls = false;
            isNull[0] = true;
        } else {
            arg2ColVector.copySelected(batch.selectedInUse, sel, n, outputColVector);
        }
        return;
    }
    if (arg1ColVector.noNulls) {
        /*
       * Repeating ELSE expression?
       */
        if (arg2ColVector.isRepeating) {
            if (batch.selectedInUse) {
                for (int j = 0; j < n; j++) {
                    int i = sel[j];
                    if (vector1[i] == 1) {
                        isNull[i] = true;
                        outputColVector.noNulls = false;
                    } else {
                        isNull[i] = false;
                        outputColVector.setElement(i, 0, arg2ColVector);
                    }
                }
            } else {
                for (int i = 0; i < n; i++) {
                    if (vector1[i] == 1) {
                        isNull[i] = true;
                        outputColVector.noNulls = false;
                    } else {
                        isNull[i] = false;
                        outputColVector.setElement(i, 0, arg2ColVector);
                    }
                }
            }
        } else {
            if (batch.selectedInUse) {
                for (int j = 0; j < n; j++) {
                    int i = sel[j];
                    if (vector1[i] == 1) {
                        isNull[i] = true;
                        outputColVector.noNulls = false;
                    } else {
                        isNull[i] = false;
                        outputColVector.setElement(i, i, arg2ColVector);
                    }
                }
            } else {
                for (int i = 0; i < n; i++) {
                    if (vector1[i] == 1) {
                        isNull[i] = true;
                        outputColVector.noNulls = false;
                    } else {
                        isNull[i] = false;
                        outputColVector.setElement(i, i, arg2ColVector);
                    }
                }
            }
        }
    } else {
        /*
       * Repeating ELSE expression?
       */
        if (arg2ColVector.isRepeating) {
            if (batch.selectedInUse) {
                for (int j = 0; j < n; j++) {
                    int i = sel[j];
                    if (!null1[i] && vector1[i] == 1) {
                        isNull[i] = true;
                        outputColVector.noNulls = false;
                    } else {
                        isNull[i] = false;
                        outputColVector.setElement(i, 0, arg2ColVector);
                    }
                }
            } else {
                for (int i = 0; i < n; i++) {
                    if (!null1[i] && vector1[i] == 1) {
                        isNull[i] = true;
                        outputColVector.noNulls = false;
                    } else {
                        isNull[i] = false;
                        outputColVector.setElement(i, 0, arg2ColVector);
                    }
                }
            }
        } else {
            if (batch.selectedInUse) {
                for (int j = 0; j < n; j++) {
                    int i = sel[j];
                    if (!null1[i] && vector1[i] == 1) {
                        isNull[i] = true;
                        outputColVector.noNulls = false;
                    } else {
                        isNull[i] = false;
                        outputColVector.setElement(i, i, arg2ColVector);
                    }
                }
            } else {
                for (int i = 0; i < n; i++) {
                    if (!null1[i] && vector1[i] == 1) {
                        isNull[i] = true;
                        outputColVector.noNulls = false;
                    } else {
                        isNull[i] = false;
                        outputColVector.setElement(i, i, arg2ColVector);
                    }
                }
            }
        }
    }
}
Also used : LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) ColumnVector(org.apache.hadoop.hive.ql.exec.vector.ColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 65 with ColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.ColumnVector in project hive by apache.

the class IsNotNull method evaluate.

@Override
public void evaluate(VectorizedRowBatch batch) {
    if (childExpressions != null) {
        super.evaluateChildren(batch);
    }
    ColumnVector inputColVector = batch.cols[colNum];
    int[] sel = batch.selected;
    boolean[] inputIsNull = inputColVector.isNull;
    int n = batch.size;
    LongColumnVector outputColVector = (LongColumnVector) batch.cols[outputColumnNum];
    long[] outputVector = outputColVector.vector;
    boolean[] outputIsNull = outputColVector.isNull;
    if (n <= 0) {
        // Nothing to do
        return;
    }
    // We do not need to do a column reset since we are carefully changing the output.
    outputColVector.isRepeating = false;
    if (inputColVector.noNulls) {
        outputColVector.isRepeating = true;
        outputIsNull[0] = false;
        outputVector[0] = 1;
    } else if (inputColVector.isRepeating) {
        outputColVector.isRepeating = true;
        outputIsNull[0] = false;
        outputVector[0] = inputIsNull[0] ? 0 : 1;
    } else {
        if (batch.selectedInUse) {
            for (int j = 0; j != n; j++) {
                int i = sel[j];
                outputIsNull[i] = false;
                outputVector[i] = inputIsNull[i] ? 0 : 1;
            }
        } else {
            Arrays.fill(outputIsNull, 0, n, false);
            for (int i = 0; i != n; i++) {
                outputVector[i] = inputIsNull[i] ? 0 : 1;
            }
        }
    }
}
Also used : LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) ColumnVector(org.apache.hadoop.hive.ql.exec.vector.ColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Aggregations

ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)72 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)41 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)30 TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)20 DoubleColumnVector (org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)19 DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)14 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)11 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)6 IOException (java.io.IOException)5 ListColumnVector (org.apache.hadoop.hive.ql.exec.vector.ListColumnVector)5 TestVectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch)5 StructColumnVector (org.apache.hadoop.hive.ql.exec.vector.StructColumnVector)4 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 MapColumnVector (org.apache.hadoop.hive.ql.exec.vector.MapColumnVector)3 BinarySortableSerDe (org.apache.hadoop.hive.serde2.binarysortable.BinarySortableSerDe)3 BinarySortableDeserializeRead (org.apache.hadoop.hive.serde2.binarysortable.fast.BinarySortableDeserializeRead)3 LazyBinaryDeserializeRead (org.apache.hadoop.hive.serde2.lazybinary.fast.LazyBinaryDeserializeRead)3 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)3 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)3