Search in sources :

Example 61 with DecimalColumnVector

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

the class ColumnVectorGenUtil method generateDecimalColumnVector.

public static DecimalColumnVector generateDecimalColumnVector(DecimalTypeInfo typeInfo, boolean nulls, boolean repeating, int size, Random rand) {
    DecimalColumnVector dcv = new DecimalColumnVector(size, typeInfo.precision(), typeInfo.scale());
    dcv.noNulls = !nulls;
    dcv.isRepeating = repeating;
    HiveDecimalWritable repeatingValue = new HiveDecimalWritable();
    do {
        repeatingValue.set(HiveDecimal.create(((Double) rand.nextDouble()).toString()).setScale((short) typeInfo.scale(), HiveDecimal.ROUND_HALF_UP));
    } while (repeatingValue.getHiveDecimal().doubleValue() == 0);
    int nullFrequency = generateNullFrequency(rand);
    for (int i = 0; i < size; i++) {
        if (nulls && (repeating || i % nullFrequency == 0)) {
            dcv.isNull[i] = true;
            dcv.vector[i] = null;
        } else {
            dcv.isNull[i] = false;
            if (repeating) {
                dcv.vector[i].set(repeatingValue);
            } else {
                dcv.vector[i].set(HiveDecimal.create(((Double) rand.nextDouble()).toString()).setScale((short) typeInfo.scale(), HiveDecimal.ROUND_HALF_UP));
            }
            if (dcv.vector[i].getHiveDecimal().doubleValue() == 0) {
                i--;
            }
        }
    }
    return dcv;
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)

Example 62 with DecimalColumnVector

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

the class VectorizedListColumnReader method getChildData.

/**
 * Get the child ColumnVector of ListColumnVector
 */
private ColumnVector getChildData(ListColumnVector lcv, int index) {
    if (lcv.offsets[index] > Integer.MAX_VALUE || lcv.lengths[index] > Integer.MAX_VALUE) {
        throw new RuntimeException("The element number in list is out of scope.");
    }
    if (lcv.isNull[index]) {
        return null;
    }
    int start = (int) lcv.offsets[index];
    int length = (int) lcv.lengths[index];
    ColumnVector child = lcv.child;
    ColumnVector resultCV = null;
    if (child instanceof LongColumnVector) {
        resultCV = new LongColumnVector(length);
        try {
            System.arraycopy(((LongColumnVector) lcv.child).vector, start, ((LongColumnVector) resultCV).vector, 0, length);
        } catch (Exception e) {
            throw new RuntimeException("Fail to copy at index:" + index + ", start:" + start + ",length:" + length + ",vec " + "len:" + ((LongColumnVector) lcv.child).vector.length + ", offset len:" + lcv.offsets.length + ", len len:" + lcv.lengths.length, e);
        }
    }
    if (child instanceof DoubleColumnVector) {
        resultCV = new DoubleColumnVector(length);
        System.arraycopy(((DoubleColumnVector) lcv.child).vector, start, ((DoubleColumnVector) resultCV).vector, 0, length);
    }
    if (child instanceof BytesColumnVector) {
        resultCV = new BytesColumnVector(length);
        System.arraycopy(((BytesColumnVector) lcv.child).vector, start, ((BytesColumnVector) resultCV).vector, 0, length);
    }
    if (child instanceof DecimalColumnVector) {
        resultCV = new DecimalColumnVector(length, ((DecimalColumnVector) child).precision, ((DecimalColumnVector) child).scale);
        System.arraycopy(((DecimalColumnVector) lcv.child).vector, start, ((DecimalColumnVector) resultCV).vector, 0, length);
    }
    return resultCV;
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) IOException(java.io.IOException) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) ListColumnVector(org.apache.hadoop.hive.ql.exec.vector.ListColumnVector) ColumnVector(org.apache.hadoop.hive.ql.exec.vector.ColumnVector) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)

Example 63 with DecimalColumnVector

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

the class VectorPTFGroupBatches method fillGroupResults.

private void fillGroupResults(VectorizedRowBatch batch) {
    for (VectorPTFEvaluatorBase evaluator : evaluators) {
        final int outputColumnNum = evaluator.getOutputColumnNum();
        if (evaluator.streamsResult()) {
            continue;
        }
        final ColumnVector outputColVector = batch.cols[outputColumnNum];
        outputColVector.isRepeating = true;
        final boolean isGroupResultNull = evaluator.isGroupResultNull();
        outputColVector.isNull[0] = isGroupResultNull;
        if (isGroupResultNull) {
            outputColVector.noNulls = false;
        } else {
            switch(evaluator.getResultColumnVectorType()) {
                case LONG:
                    ((LongColumnVector) outputColVector).vector[0] = evaluator.getLongGroupResult();
                    break;
                case DOUBLE:
                    ((DoubleColumnVector) outputColVector).vector[0] = evaluator.getDoubleGroupResult();
                    break;
                case DECIMAL:
                    ((DecimalColumnVector) outputColVector).vector[0].set(evaluator.getDecimalGroupResult());
                    break;
                default:
                    throw new RuntimeException("Unexpected column vector type " + evaluator.getResultColumnVectorType());
            }
        }
    }
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) ColumnVector(org.apache.hadoop.hive.ql.exec.vector.ColumnVector) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)

Example 64 with DecimalColumnVector

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

the class VectorPTFOperator method isPartitionChanged.

private boolean isPartitionChanged(VectorizedRowBatch batch) {
    final int count = partitionColumnMap.length;
    for (int i = 0; i < count; i++) {
        ColumnVector colVector = batch.cols[partitionColumnMap[i]];
        // Vector reduce key (i.e. partition) columns are repeated -- so we test element 0.
        final boolean isNull = !colVector.noNulls && colVector.isNull[0];
        final boolean currentIsNull = currentPartitionIsNull[i];
        if (isNull != currentIsNull) {
            return true;
        }
        if (isNull) {
            // NULL does equal NULL here.
            continue;
        }
        switch(partitionColumnVectorTypes[i]) {
            case LONG:
                if (currentPartitionLongs[i] != ((LongColumnVector) colVector).vector[0]) {
                    return true;
                }
                break;
            case DOUBLE:
                if (currentPartitionDoubles[i] != ((DoubleColumnVector) colVector).vector[0]) {
                    return true;
                }
                break;
            case BYTES:
                {
                    BytesColumnVector byteColVector = (BytesColumnVector) colVector;
                    byte[] bytes = byteColVector.vector[0];
                    final int start = byteColVector.start[0];
                    final int length = byteColVector.length[0];
                    if (!StringExpr.equal(bytes, start, length, currentPartitionByteArrays[i], 0, currentPartitionByteLengths[i])) {
                        return true;
                    }
                }
                break;
            case DECIMAL:
                if (!currentPartitionDecimals[i].equals(((DecimalColumnVector) colVector).vector[0])) {
                    return true;
                }
                break;
            case TIMESTAMP:
                if (((TimestampColumnVector) colVector).compareTo(0, currentPartitionTimestamps[i]) != 0) {
                    return true;
                }
                break;
            case INTERVAL_DAY_TIME:
                if (((IntervalDayTimeColumnVector) colVector).compareTo(0, currentPartitionIntervalDayTimes[i]) != 0) {
                    return true;
                }
                break;
            default:
                throw new RuntimeException("Unexpected column vector type " + partitionColumnVectorTypes[i]);
        }
    }
    return false;
}
Also used : DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) ColumnVector(org.apache.hadoop.hive.ql.exec.vector.ColumnVector) TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) IntervalDayTimeColumnVector(org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)

Example 65 with DecimalColumnVector

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

the class VectorPTFOperator method setCurrentPartition.

private void setCurrentPartition(VectorizedRowBatch batch) {
    final int count = partitionColumnMap.length;
    for (int i = 0; i < count; i++) {
        ColumnVector colVector = batch.cols[partitionColumnMap[i]];
        // Partition columns are repeated -- so we test element 0.
        final boolean isNull = !colVector.noNulls && colVector.isNull[0];
        currentPartitionIsNull[i] = isNull;
        if (isNull) {
            continue;
        }
        switch(partitionColumnVectorTypes[i]) {
            case LONG:
                currentPartitionLongs[i] = ((LongColumnVector) colVector).vector[0];
                break;
            case DOUBLE:
                currentPartitionDoubles[i] = ((DoubleColumnVector) colVector).vector[0];
                break;
            case BYTES:
                {
                    BytesColumnVector byteColVector = (BytesColumnVector) colVector;
                    byte[] bytes = byteColVector.vector[0];
                    final int start = byteColVector.start[0];
                    final int length = byteColVector.length[0];
                    if (currentPartitionByteArrays[i] == null || currentPartitionByteLengths[i] < length) {
                        currentPartitionByteArrays[i] = Arrays.copyOfRange(bytes, start, start + length);
                    } else {
                        System.arraycopy(bytes, start, currentPartitionByteArrays[i], 0, length);
                    }
                    currentPartitionByteLengths[i] = length;
                }
                break;
            case DECIMAL:
                if (currentPartitionDecimals[i] == null) {
                    currentPartitionDecimals[i] = new HiveDecimalWritable();
                }
                currentPartitionDecimals[i].set(((DecimalColumnVector) colVector).vector[0]);
                break;
            case TIMESTAMP:
                if (currentPartitionTimestamps[i] == null) {
                    currentPartitionTimestamps[i] = new Timestamp(0);
                }
                ((TimestampColumnVector) colVector).timestampUpdate(currentPartitionTimestamps[i], 0);
                break;
            case INTERVAL_DAY_TIME:
                if (currentPartitionIntervalDayTimes[i] == null) {
                    currentPartitionIntervalDayTimes[i] = new HiveIntervalDayTime();
                }
                ((IntervalDayTimeColumnVector) colVector).intervalDayTimeUpdate(currentPartitionIntervalDayTimes[i], 0);
                break;
            default:
                throw new RuntimeException("Unexpected column vector type " + partitionColumnVectorTypes[i]);
        }
    }
}
Also used : TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) IntervalDayTimeColumnVector(org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector) Timestamp(java.sql.Timestamp) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) ColumnVector(org.apache.hadoop.hive.ql.exec.vector.ColumnVector) TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) IntervalDayTimeColumnVector(org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) HiveIntervalDayTime(org.apache.hadoop.hive.common.type.HiveIntervalDayTime)

Aggregations

DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)84 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)38 Test (org.junit.Test)28 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)22 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)20 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)17 DoubleColumnVector (org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)16 TestVectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch)16 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)15 TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)11 ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)7 TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)5 Timestamp (java.sql.Timestamp)4 Random (java.util.Random)4 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)3 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)3 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)3 BooleanWritable (org.apache.hadoop.io.BooleanWritable)3 IntWritable (org.apache.hadoop.io.IntWritable)3 LongWritable (org.apache.hadoop.io.LongWritable)3