Search in sources :

Example 26 with DecimalColumnVector

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

the class VectorPTFEvaluatorDecimalAvg method evaluateGroupBatch.

@Override
public void evaluateGroupBatch(VectorizedRowBatch batch) throws HiveException {
    evaluateInputExpr(batch);
    // Sum all non-null decimal column values for avg; maintain isGroupResultNull; after last row of
    // last group batch compute the group avg when sum is non-null.
    // We do not filter when PTF is in reducer.
    Preconditions.checkState(!batch.selectedInUse);
    final int size = batch.size;
    if (size == 0) {
        return;
    }
    DecimalColumnVector decimalColVector = ((DecimalColumnVector) batch.cols[inputColumnNum]);
    if (decimalColVector.isRepeating) {
        if (decimalColVector.noNulls || !decimalColVector.isNull[0]) {
            // We have a repeated value.  The sum increases by value * batch.size.
            temp.setFromLong(batch.size);
            if (isGroupResultNull) {
                // First aggregation calculation for group.
                sum.set(decimalColVector.vector[0]);
                sum.mutateMultiply(temp);
                isGroupResultNull = false;
            } else {
                temp.mutateMultiply(decimalColVector.vector[0]);
                sum.mutateAdd(temp);
            }
            nonNullGroupCount += size;
        }
    } else if (decimalColVector.noNulls) {
        HiveDecimalWritable[] vector = decimalColVector.vector;
        if (isGroupResultNull) {
            // First aggregation calculation for group.
            sum.set(vector[0]);
            isGroupResultNull = false;
        } else {
            sum.mutateAdd(vector[0]);
        }
        for (int i = 1; i < size; i++) {
            sum.mutateAdd(vector[i]);
        }
        nonNullGroupCount += size;
    } else {
        boolean[] batchIsNull = decimalColVector.isNull;
        int i = 0;
        while (batchIsNull[i]) {
            if (++i >= size) {
                return;
            }
        }
        HiveDecimalWritable[] vector = decimalColVector.vector;
        if (isGroupResultNull) {
            // First aggregation calculation for group.
            sum.set(vector[i++]);
            isGroupResultNull = false;
        } else {
            sum.mutateAdd(vector[i++]);
        }
        nonNullGroupCount++;
        for (; i < size; i++) {
            if (!batchIsNull[i]) {
                sum.mutateAdd(vector[i]);
                nonNullGroupCount++;
            }
        }
    }
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)

Example 27 with DecimalColumnVector

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

the class VectorPTFEvaluatorDecimalFirstValue method evaluateGroupBatch.

@Override
public void evaluateGroupBatch(VectorizedRowBatch batch) throws HiveException {
    evaluateInputExpr(batch);
    // First row determines isGroupResultNull and decimal firstValue; stream fill result as repeated.
    // We do not filter when PTF is in reducer.
    Preconditions.checkState(!batch.selectedInUse);
    if (!haveFirstValue) {
        final int size = batch.size;
        if (size == 0) {
            return;
        }
        DecimalColumnVector decimalColVector = ((DecimalColumnVector) batch.cols[inputColumnNum]);
        if (decimalColVector.isRepeating) {
            if (decimalColVector.noNulls || !decimalColVector.isNull[0]) {
                firstValue.set(decimalColVector.vector[0]);
                isGroupResultNull = false;
            }
        } else if (decimalColVector.noNulls) {
            firstValue.set(decimalColVector.vector[0]);
            isGroupResultNull = false;
        } else {
            if (!decimalColVector.isNull[0]) {
                firstValue.set(decimalColVector.vector[0]);
                isGroupResultNull = false;
            }
        }
        haveFirstValue = true;
    }
    /*
     * Do careful maintenance of the outputColVector.noNulls flag.
     */
    // First value is repeated for all batches.
    DecimalColumnVector outputColVector = (DecimalColumnVector) batch.cols[outputColumnNum];
    outputColVector.isRepeating = true;
    if (isGroupResultNull) {
        outputColVector.noNulls = false;
        outputColVector.isNull[0] = true;
    } else {
        outputColVector.isNull[0] = false;
        outputColVector.set(0, firstValue);
    }
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)

Example 28 with DecimalColumnVector

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

the class VectorPTFEvaluatorDecimalSum method evaluateGroupBatch.

@Override
public void evaluateGroupBatch(VectorizedRowBatch batch) throws HiveException {
    evaluateInputExpr(batch);
    // Sum all non-null decimal column values; maintain isGroupResultNull.
    // We do not filter when PTF is in reducer.
    Preconditions.checkState(!batch.selectedInUse);
    final int size = batch.size;
    if (size == 0) {
        return;
    }
    DecimalColumnVector decimalColVector = ((DecimalColumnVector) batch.cols[inputColumnNum]);
    if (decimalColVector.isRepeating) {
        if (decimalColVector.noNulls || !decimalColVector.isNull[0]) {
            temp.setFromLong(batch.size);
            if (isGroupResultNull) {
                // First aggregation calculation for group.
                sum.set(decimalColVector.vector[0]);
                sum.mutateMultiply(temp);
                isGroupResultNull = false;
            } else {
                temp.mutateMultiply(decimalColVector.vector[0]);
                sum.mutateAdd(temp);
            }
        }
    } else if (decimalColVector.noNulls) {
        HiveDecimalWritable[] vector = decimalColVector.vector;
        if (isGroupResultNull) {
            // First aggregation calculation for group.
            sum.set(vector[0]);
            isGroupResultNull = false;
        } else {
            sum.mutateAdd(vector[0]);
        }
        for (int i = 1; i < size; i++) {
            sum.mutateAdd(vector[i]);
        }
    } else {
        boolean[] batchIsNull = decimalColVector.isNull;
        int i = 0;
        while (batchIsNull[i]) {
            if (++i >= size) {
                return;
            }
        }
        HiveDecimalWritable[] vector = decimalColVector.vector;
        if (isGroupResultNull) {
            // First aggregation calculation for group.
            sum.set(vector[i++]);
            isGroupResultNull = false;
        } else {
            sum.mutateAdd(vector[i++]);
        }
        for (; i < size; i++) {
            if (!batchIsNull[i]) {
                sum.mutateAdd(vector[i]);
            }
        }
    }
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)

Example 29 with DecimalColumnVector

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

the class RecordReaderImpl method nextDecimal.

static HiveDecimalWritable nextDecimal(ColumnVector vector, int row, Object previous) {
    if (vector.isRepeating) {
        row = 0;
    }
    if (vector.noNulls || !vector.isNull[row]) {
        HiveDecimalWritable result;
        if (previous == null || previous.getClass() != HiveDecimalWritable.class) {
            result = new HiveDecimalWritable();
        } else {
            result = (HiveDecimalWritable) previous;
        }
        if (vector instanceof Decimal64ColumnVector) {
            long value = ((Decimal64ColumnVector) vector).vector[row];
            result.deserialize64(value, ((Decimal64ColumnVector) vector).scale);
        } else {
            result.set(((DecimalColumnVector) vector).vector[row]);
        }
        return result;
    } else {
        return null;
    }
}
Also used : Decimal64ColumnVector(org.apache.hadoop.hive.ql.exec.vector.Decimal64ColumnVector) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)

Example 30 with DecimalColumnVector

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

the class TestVectorTypeCasts method getBatchDecimalString.

private VectorizedRowBatch getBatchDecimalString() {
    VectorizedRowBatch b = new VectorizedRowBatch(2);
    DecimalColumnVector dv;
    short scale = 2;
    b.cols[0] = dv = new DecimalColumnVector(18, scale);
    b.cols[1] = new BytesColumnVector();
    b.size = 3;
    dv.vector[0].set(HiveDecimal.create("1.1"));
    dv.vector[1].set(HiveDecimal.create("-2.2"));
    dv.vector[2].set(HiveDecimal.create("9999999999999999.00"));
    return b;
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)

Aggregations

DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)108 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)38 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)28 Test (org.junit.Test)28 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)27 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)25 DoubleColumnVector (org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)25 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)23 TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)18 TestVectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch)16 ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)14 IntervalDayTimeColumnVector (org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector)7 Timestamp (java.sql.Timestamp)5 Random (java.util.Random)4 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)4 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)3 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)3 IOException (java.io.IOException)2 DateColumnVector (org.apache.hadoop.hive.ql.exec.vector.DateColumnVector)2 Decimal64ColumnVector (org.apache.hadoop.hive.ql.exec.vector.Decimal64ColumnVector)2