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;
}
Aggregations