Search in sources :

Example 1 with VarDecimalVector

use of org.apache.drill.exec.vector.VarDecimalVector in project drill by apache.

the class BatchSizingMemoryUtil method getMemoryUsage.

/**
 * Load memory usage information for a variable length value vector
 *
 * @param sourceVector source value vector
 * @param currValueCount current value count
 * @param vectorMemoryUsage result object which contains source vector memory usage information
 */
public static void getMemoryUsage(ValueVector sourceVector, int currValueCount, VectorMemoryUsageInfo vectorMemoryUsage) {
    assert sourceVector instanceof VariableWidthVector;
    // reset result container
    vectorMemoryUsage.reset();
    final MajorType type = sourceVector.getField().getType();
    switch(type.getMinorType()) {
        case VARCHAR:
            {
                switch(type.getMode()) {
                    case REQUIRED:
                        {
                            VarCharVector vector = (VarCharVector) sourceVector;
                            vectorMemoryUsage.offsetsByteCapacity = vector.getOffsetVector().getValueCapacity() * INT_VALUE_WIDTH;
                            vectorMemoryUsage.dataByteCapacity = vector.getByteCapacity();
                            vectorMemoryUsage.offsetsBytesUsed = vector.getOffsetVector().getPayloadByteCount(currValueCount);
                            vectorMemoryUsage.dataBytesUsed = vector.getPayloadByteCount(currValueCount) - vectorMemoryUsage.offsetsBytesUsed;
                            break;
                        }
                    case OPTIONAL:
                        {
                            NullableVarCharVector vector = (NullableVarCharVector) sourceVector;
                            VarCharVector values = vector.getValuesVector();
                            vectorMemoryUsage.bitsBytesCapacity = vector.getBitsValueCapacity();
                            vectorMemoryUsage.offsetsByteCapacity = values.getOffsetVector().getValueCapacity() * INT_VALUE_WIDTH;
                            vectorMemoryUsage.dataByteCapacity = values.getByteCapacity();
                            vectorMemoryUsage.bitsBytesUsed = currValueCount * BYTE_VALUE_WIDTH;
                            vectorMemoryUsage.offsetsBytesUsed = values.getOffsetVector().getPayloadByteCount(currValueCount);
                            vectorMemoryUsage.dataBytesUsed = values.getPayloadByteCount(currValueCount) - vectorMemoryUsage.offsetsBytesUsed;
                            break;
                        }
                    default:
                        throw new IllegalArgumentException("Mode [" + type.getMode().name() + "] not supported..");
                }
                break;
            }
        case VARBINARY:
            {
                switch(type.getMode()) {
                    case REQUIRED:
                        {
                            VarBinaryVector vector = (VarBinaryVector) sourceVector;
                            vectorMemoryUsage.offsetsByteCapacity = vector.getOffsetVector().getValueCapacity() * INT_VALUE_WIDTH;
                            vectorMemoryUsage.dataByteCapacity = vector.getByteCapacity();
                            vectorMemoryUsage.offsetsBytesUsed = vector.getOffsetVector().getPayloadByteCount(currValueCount);
                            vectorMemoryUsage.dataBytesUsed = vector.getPayloadByteCount(currValueCount) - vectorMemoryUsage.offsetsBytesUsed;
                            break;
                        }
                    case OPTIONAL:
                        {
                            NullableVarBinaryVector vector = (NullableVarBinaryVector) sourceVector;
                            VarBinaryVector values = vector.getValuesVector();
                            vectorMemoryUsage.bitsBytesCapacity = vector.getBitsValueCapacity();
                            vectorMemoryUsage.offsetsByteCapacity = values.getOffsetVector().getValueCapacity() * INT_VALUE_WIDTH;
                            vectorMemoryUsage.dataByteCapacity = values.getByteCapacity();
                            vectorMemoryUsage.bitsBytesUsed = currValueCount * BYTE_VALUE_WIDTH;
                            vectorMemoryUsage.offsetsBytesUsed = values.getOffsetVector().getPayloadByteCount(currValueCount);
                            vectorMemoryUsage.dataBytesUsed = values.getPayloadByteCount(currValueCount) - vectorMemoryUsage.offsetsBytesUsed;
                            break;
                        }
                    default:
                        throw new IllegalArgumentException("Mode [" + type.getMode().name() + "] not supported..");
                }
                break;
            }
        case VARDECIMAL:
            {
                switch(type.getMode()) {
                    case REQUIRED:
                        {
                            VarDecimalVector vector = (VarDecimalVector) sourceVector;
                            vectorMemoryUsage.offsetsByteCapacity = vector.getOffsetVector().getValueCapacity() * INT_VALUE_WIDTH;
                            vectorMemoryUsage.dataByteCapacity = vector.getByteCapacity();
                            vectorMemoryUsage.offsetsBytesUsed = vector.getOffsetVector().getPayloadByteCount(currValueCount);
                            vectorMemoryUsage.dataBytesUsed = vector.getPayloadByteCount(currValueCount) - vectorMemoryUsage.offsetsBytesUsed;
                            break;
                        }
                    case OPTIONAL:
                        {
                            NullableVarDecimalVector vector = (NullableVarDecimalVector) sourceVector;
                            VarDecimalVector values = vector.getValuesVector();
                            vectorMemoryUsage.bitsBytesCapacity = vector.getBitsValueCapacity();
                            vectorMemoryUsage.offsetsByteCapacity = values.getOffsetVector().getValueCapacity() * INT_VALUE_WIDTH;
                            vectorMemoryUsage.dataByteCapacity = values.getByteCapacity();
                            vectorMemoryUsage.bitsBytesUsed = currValueCount * BYTE_VALUE_WIDTH;
                            vectorMemoryUsage.offsetsBytesUsed = values.getOffsetVector().getPayloadByteCount(currValueCount);
                            vectorMemoryUsage.dataBytesUsed = values.getPayloadByteCount(currValueCount) - vectorMemoryUsage.offsetsBytesUsed;
                            break;
                        }
                    default:
                        throw new IllegalArgumentException("Mode [" + type.getMode().name() + "] not supported..");
                }
                break;
            }
        default:
            throw new IllegalArgumentException("Type [" + type.getMinorType().name() + "] not supported..");
    }
    assert vectorMemoryUsage.bitsBytesCapacity >= 0;
    assert vectorMemoryUsage.bitsBytesUsed >= 0;
    assert vectorMemoryUsage.offsetsByteCapacity >= 0;
    assert vectorMemoryUsage.offsetsBytesUsed >= 0;
    assert vectorMemoryUsage.dataByteCapacity >= 0;
    assert vectorMemoryUsage.dataBytesUsed >= 0;
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) NullableVarBinaryVector(org.apache.drill.exec.vector.NullableVarBinaryVector) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) VariableWidthVector(org.apache.drill.exec.vector.VariableWidthVector) NullableVarDecimalVector(org.apache.drill.exec.vector.NullableVarDecimalVector) VarDecimalVector(org.apache.drill.exec.vector.VarDecimalVector) NullableVarDecimalVector(org.apache.drill.exec.vector.NullableVarDecimalVector) VarBinaryVector(org.apache.drill.exec.vector.VarBinaryVector) NullableVarBinaryVector(org.apache.drill.exec.vector.NullableVarBinaryVector)

Aggregations

MajorType (org.apache.drill.common.types.TypeProtos.MajorType)1 NullableVarBinaryVector (org.apache.drill.exec.vector.NullableVarBinaryVector)1 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)1 NullableVarDecimalVector (org.apache.drill.exec.vector.NullableVarDecimalVector)1 VarBinaryVector (org.apache.drill.exec.vector.VarBinaryVector)1 VarCharVector (org.apache.drill.exec.vector.VarCharVector)1 VarDecimalVector (org.apache.drill.exec.vector.VarDecimalVector)1 VariableWidthVector (org.apache.drill.exec.vector.VariableWidthVector)1