Search in sources :

Example 6 with IntervalDayTimeColumnVector

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

the class IfExprIntervalDayTimeScalarColumn method evaluate.

@Override
public void evaluate(VectorizedRowBatch batch) {
    if (childExpressions != null) {
        super.evaluateChildren(batch);
    }
    LongColumnVector arg1ColVector = (LongColumnVector) batch.cols[arg1Column];
    IntervalDayTimeColumnVector arg3ColVector = (IntervalDayTimeColumnVector) batch.cols[arg3Column];
    IntervalDayTimeColumnVector outputColVector = (IntervalDayTimeColumnVector) batch.cols[outputColumnNum];
    int[] sel = batch.selected;
    boolean[] outputIsNull = outputColVector.isNull;
    // We do not need to do a column reset since we are carefully changing the output.
    outputColVector.isRepeating = false;
    int n = batch.size;
    long[] vector1 = arg1ColVector.vector;
    // return immediately if batch is empty
    if (n == 0) {
        return;
    }
    if (arg1ColVector.isRepeating) {
        if ((arg1ColVector.noNulls || !arg1ColVector.isNull[0]) && vector1[0] == 1) {
            outputColVector.fill(arg2Scalar);
        } else {
            arg3ColVector.copySelected(batch.selectedInUse, sel, n, outputColVector);
        }
        return;
    }
    // Extend any repeating values and noNulls indicator in the inputs to
    // reduce the number of code paths needed below.
    // This could be optimized in the future by having separate paths
    // for when arg3ColVector is repeating or has no nulls.
    arg3ColVector.flatten(batch.selectedInUse, sel, n);
    if (arg1ColVector.noNulls) {
        if (batch.selectedInUse) {
            if (!outputColVector.noNulls) {
                for (int j = 0; j != n; j++) {
                    final int i = sel[j];
                    // Set isNull before call in case it changes it mind.
                    outputIsNull[i] = false;
                    outputColVector.set(i, vector1[i] == 1 ? arg2Scalar : arg3ColVector.asScratchIntervalDayTime(i));
                }
            } else {
                for (int j = 0; j != n; j++) {
                    final int i = sel[j];
                    outputColVector.set(i, vector1[i] == 1 ? arg2Scalar : arg3ColVector.asScratchIntervalDayTime(i));
                }
            }
        } else {
            if (!outputColVector.noNulls) {
                // Assume it is almost always a performance win to fill all of isNull so we can
                // safely reset noNulls.
                Arrays.fill(outputIsNull, false);
                outputColVector.noNulls = true;
            }
            for (int i = 0; i != n; i++) {
                outputColVector.set(i, vector1[i] == 1 ? arg2Scalar : arg3ColVector.asScratchIntervalDayTime(i));
            }
        }
    } else /* there are nulls */
    {
        // Carefully handle NULLs...
        /*
       * For better performance on LONG/DOUBLE we don't want the conditional
       * statements inside the for loop.
       */
        outputColVector.noNulls = false;
        if (batch.selectedInUse) {
            for (int j = 0; j != n; j++) {
                int i = sel[j];
                outputColVector.set(i, !arg1ColVector.isNull[i] && vector1[i] == 1 ? arg2Scalar : arg3ColVector.asScratchIntervalDayTime(i));
                outputIsNull[i] = (!arg1ColVector.isNull[i] && vector1[i] == 1 ? false : arg3ColVector.isNull[i]);
            }
        } else {
            for (int i = 0; i != n; i++) {
                outputColVector.set(i, !arg1ColVector.isNull[i] && vector1[i] == 1 ? arg2Scalar : arg3ColVector.asScratchIntervalDayTime(i));
                outputIsNull[i] = (!arg1ColVector.isNull[i] && vector1[i] == 1 ? false : arg3ColVector.isNull[i]);
            }
        }
    }
    // restore repeating and no nulls indicators
    arg3ColVector.unFlatten();
}
Also used : IntervalDayTimeColumnVector(org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 7 with IntervalDayTimeColumnVector

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

the class CastStringToIntervalDayTime method evaluate.

@Override
public void evaluate(VectorizedRowBatch batch) throws HiveException {
    if (childExpressions != null) {
        super.evaluateChildren(batch);
    }
    BytesColumnVector inputColVector = (BytesColumnVector) batch.cols[inputColumnNum[0]];
    int[] sel = batch.selected;
    int n = batch.size;
    IntervalDayTimeColumnVector outputColVector = (IntervalDayTimeColumnVector) batch.cols[outputColumnNum];
    boolean[] inputIsNull = inputColVector.isNull;
    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.isRepeating) {
        if (inputColVector.noNulls || !inputIsNull[0]) {
            // Set isNull before call in case it changes it mind.
            outputIsNull[0] = false;
            evaluate(outputColVector, inputColVector, 0);
        } else {
            outputIsNull[0] = true;
            outputColVector.noNulls = false;
        }
        outputColVector.isRepeating = true;
        return;
    }
    if (inputColVector.noNulls) {
        if (batch.selectedInUse) {
            if (!outputColVector.noNulls) {
                for (int j = 0; j != n; j++) {
                    final int i = sel[j];
                    // Set isNull before call in case it changes it mind.
                    outputIsNull[i] = false;
                    evaluate(outputColVector, inputColVector, i);
                }
            } else {
                for (int j = 0; j != n; j++) {
                    final int i = sel[j];
                    evaluate(outputColVector, inputColVector, i);
                }
            }
        } else {
            if (!outputColVector.noNulls) {
                // Assume it is almost always a performance win to fill all of isNull so we can
                // safely reset noNulls.
                Arrays.fill(outputIsNull, false);
                outputColVector.noNulls = true;
            }
            for (int i = 0; i != n; i++) {
                evaluate(outputColVector, inputColVector, i);
            }
        }
    } else /* there are NULLs in the inputColVector */
    {
        // Carefully handle NULLs...
        outputColVector.noNulls = false;
        if (batch.selectedInUse) {
            for (int j = 0; j != n; j++) {
                int i = sel[j];
                // Set isNull before call in case it changes it mind.
                outputColVector.isNull[i] = inputColVector.isNull[i];
                if (!inputColVector.isNull[i]) {
                    evaluate(outputColVector, inputColVector, i);
                }
            }
        } else {
            // Set isNull before calls in case they change their mind.
            System.arraycopy(inputColVector.isNull, 0, outputColVector.isNull, 0, n);
            for (int i = 0; i != n; i++) {
                if (!inputColVector.isNull[i]) {
                    evaluate(outputColVector, inputColVector, i);
                }
            }
        }
    }
}
Also used : IntervalDayTimeColumnVector(org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)

Example 8 with IntervalDayTimeColumnVector

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

the class VectorPTFGroupBatches method setRepeatingColumn.

private void setRepeatingColumn(Object partitionKey, VectorizedRowBatch targetBatch, int targetColumnNum) {
    ColumnVector targetColVector = targetBatch.cols[targetColumnNum];
    targetColVector.isRepeating = true;
    if (partitionKey == null) {
        targetColVector.noNulls = false;
        targetColVector.isNull[0] = true;
        return;
    }
    switch(targetColVector.type) {
        case LONG:
            ((LongColumnVector) targetColVector).vector[0] = (long) partitionKey;
            break;
        case DOUBLE:
            ((DoubleColumnVector) targetColVector).vector[0] = (double) partitionKey;
            break;
        case BYTES:
            ((BytesColumnVector) targetColVector).setRef(0, (byte[]) partitionKey, 0, ((byte[]) partitionKey).length);
            break;
        case DECIMAL:
            ((DecimalColumnVector) targetColVector).set(0, (HiveDecimalWritable) partitionKey);
            break;
        case TIMESTAMP:
            ((TimestampColumnVector) targetColVector).set(0, (Timestamp) partitionKey);
            break;
        case INTERVAL_DAY_TIME:
            ((IntervalDayTimeColumnVector) targetColVector).set(0, (HiveIntervalDayTime) partitionKey);
            break;
        case STRUCT:
        case LIST:
        case MAP:
        case UNION:
        // No complex type support for now.
        default:
            throw new RuntimeException("Unexpected column vector type " + targetColVector.type);
    }
}
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) IntervalDayTimeColumnVector(org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector) 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 9 with IntervalDayTimeColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector 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 10 with IntervalDayTimeColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector 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

IntervalDayTimeColumnVector (org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector)11 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)10 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)7 DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)6 DoubleColumnVector (org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)6 TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)6 ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)4 Timestamp (java.sql.Timestamp)1 HiveIntervalDayTime (org.apache.hadoop.hive.common.type.HiveIntervalDayTime)1 Type (org.apache.hadoop.hive.ql.exec.vector.ColumnVector.Type)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)1