Search in sources :

Example 1 with NullableVarDecimalVector

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

the class ParquetPartitionDescriptor method populatePruningVector.

private void populatePruningVector(ValueVector v, int index, SchemaPath column, Path file) {
    Path path = Path.getPathWithoutSchemeAndAuthority(file);
    TypeProtos.MajorType majorType = getVectorType(column, null);
    TypeProtos.MinorType type = majorType.getMinorType();
    switch(type) {
        case BIT:
            {
                NullableBitVector bitVector = (NullableBitVector) v;
                Boolean value = groupScan.getPartitionValue(path, column, Boolean.class);
                if (value == null) {
                    bitVector.getMutator().setNull(index);
                } else {
                    bitVector.getMutator().setSafe(index, value ? 1 : 0);
                }
                return;
            }
        case INT:
            {
                NullableIntVector intVector = (NullableIntVector) v;
                Integer value = groupScan.getPartitionValue(path, column, Integer.class);
                if (value == null) {
                    intVector.getMutator().setNull(index);
                } else {
                    intVector.getMutator().setSafe(index, value);
                }
                return;
            }
        case SMALLINT:
            {
                NullableSmallIntVector smallIntVector = (NullableSmallIntVector) v;
                Integer value = groupScan.getPartitionValue(path, column, Integer.class);
                if (value == null) {
                    smallIntVector.getMutator().setNull(index);
                } else {
                    smallIntVector.getMutator().setSafe(index, value.shortValue());
                }
                return;
            }
        case TINYINT:
            {
                NullableTinyIntVector tinyIntVector = (NullableTinyIntVector) v;
                Integer value = groupScan.getPartitionValue(path, column, Integer.class);
                if (value == null) {
                    tinyIntVector.getMutator().setNull(index);
                } else {
                    tinyIntVector.getMutator().setSafe(index, value.byteValue());
                }
                return;
            }
        case UINT1:
            {
                NullableUInt1Vector intVector = (NullableUInt1Vector) v;
                Integer value = groupScan.getPartitionValue(path, column, Integer.class);
                if (value == null) {
                    intVector.getMutator().setNull(index);
                } else {
                    intVector.getMutator().setSafe(index, value.byteValue());
                }
                return;
            }
        case UINT2:
            {
                NullableUInt2Vector intVector = (NullableUInt2Vector) v;
                Integer value = groupScan.getPartitionValue(path, column, Integer.class);
                if (value == null) {
                    intVector.getMutator().setNull(index);
                } else {
                    intVector.getMutator().setSafe(index, (char) value.shortValue());
                }
                return;
            }
        case UINT4:
            {
                NullableUInt4Vector intVector = (NullableUInt4Vector) v;
                Integer value = groupScan.getPartitionValue(path, column, Integer.class);
                if (value == null) {
                    intVector.getMutator().setNull(index);
                } else {
                    intVector.getMutator().setSafe(index, value);
                }
                return;
            }
        case BIGINT:
            {
                NullableBigIntVector bigIntVector = (NullableBigIntVector) v;
                Long value = groupScan.getPartitionValue(path, column, Long.class);
                if (value == null) {
                    bigIntVector.getMutator().setNull(index);
                } else {
                    bigIntVector.getMutator().setSafe(index, value);
                }
                return;
            }
        case FLOAT4:
            {
                NullableFloat4Vector float4Vector = (NullableFloat4Vector) v;
                Float value = groupScan.getPartitionValue(path, column, Float.class);
                if (value == null) {
                    float4Vector.getMutator().setNull(index);
                } else {
                    float4Vector.getMutator().setSafe(index, value);
                }
                return;
            }
        case FLOAT8:
            {
                NullableFloat8Vector float8Vector = (NullableFloat8Vector) v;
                Double value = groupScan.getPartitionValue(path, column, Double.class);
                if (value == null) {
                    float8Vector.getMutator().setNull(index);
                } else {
                    float8Vector.getMutator().setSafe(index, value);
                }
                return;
            }
        case VARBINARY:
            {
                NullableVarBinaryVector varBinaryVector = (NullableVarBinaryVector) v;
                Object s = groupScan.getPartitionValue(path, column, Object.class);
                byte[] bytes;
                if (s == null) {
                    varBinaryVector.getMutator().setNull(index);
                    return;
                } else {
                    bytes = getBytes(type, s);
                }
                varBinaryVector.getMutator().setSafe(index, bytes, 0, bytes.length);
                return;
            }
        case VARDECIMAL:
            {
                NullableVarDecimalVector decimalVector = (NullableVarDecimalVector) v;
                Object s = groupScan.getPartitionValue(path, column, Object.class);
                byte[] bytes;
                if (s == null) {
                    decimalVector.getMutator().setNull(index);
                    return;
                } else if (s instanceof Integer) {
                    bytes = Ints.toByteArray((int) s);
                } else if (s instanceof Long) {
                    bytes = Longs.toByteArray((long) s);
                } else {
                    bytes = getBytes(type, s);
                }
                decimalVector.getMutator().setSafe(index, bytes, 0, bytes.length);
                return;
            }
        case DATE:
            {
                NullableDateVector dateVector = (NullableDateVector) v;
                Long value = groupScan.getPartitionValue(path, column, Long.class);
                if (value == null) {
                    dateVector.getMutator().setNull(index);
                } else {
                    dateVector.getMutator().setSafe(index, value);
                }
                return;
            }
        case TIME:
            {
                NullableTimeVector timeVector = (NullableTimeVector) v;
                Integer value = groupScan.getPartitionValue(path, column, Integer.class);
                if (value == null) {
                    timeVector.getMutator().setNull(index);
                } else {
                    timeVector.getMutator().setSafe(index, value);
                }
                return;
            }
        case TIMESTAMP:
            {
                NullableTimeStampVector timeStampVector = (NullableTimeStampVector) v;
                Long value = groupScan.getPartitionValue(path, column, Long.class);
                if (value == null) {
                    timeStampVector.getMutator().setNull(index);
                } else {
                    timeStampVector.getMutator().setSafe(index, value);
                }
                return;
            }
        case VARCHAR:
            {
                NullableVarCharVector varCharVector = (NullableVarCharVector) v;
                Object s = groupScan.getPartitionValue(path, column, Object.class);
                byte[] bytes;
                if (s == null) {
                    varCharVector.getMutator().setNull(index);
                    return;
                } else {
                    bytes = getBytes(type, s);
                }
                varCharVector.getMutator().setSafe(index, bytes, 0, bytes.length);
                return;
            }
        case INTERVAL:
            {
                NullableIntervalVector intervalVector = (NullableIntervalVector) v;
                Object s = groupScan.getPartitionValue(path, column, Object.class);
                byte[] bytes;
                if (s == null) {
                    intervalVector.getMutator().setNull(index);
                    return;
                } else {
                    bytes = getBytes(type, s);
                }
                intervalVector.getMutator().setSafe(index, 1, ParquetReaderUtility.getIntFromLEBytes(bytes, 0), ParquetReaderUtility.getIntFromLEBytes(bytes, 4), ParquetReaderUtility.getIntFromLEBytes(bytes, 8));
                return;
            }
        default:
            throw new UnsupportedOperationException("Unsupported type: " + type);
    }
}
Also used : NullableTinyIntVector(org.apache.drill.exec.vector.NullableTinyIntVector) NullableFloat8Vector(org.apache.drill.exec.vector.NullableFloat8Vector) NullableVarBinaryVector(org.apache.drill.exec.vector.NullableVarBinaryVector) NullableUInt1Vector(org.apache.drill.exec.vector.NullableUInt1Vector) TypeProtos(org.apache.drill.common.types.TypeProtos) NullableVarDecimalVector(org.apache.drill.exec.vector.NullableVarDecimalVector) NullableIntVector(org.apache.drill.exec.vector.NullableIntVector) NullableBitVector(org.apache.drill.exec.vector.NullableBitVector) NullableFloat4Vector(org.apache.drill.exec.vector.NullableFloat4Vector) NullableUInt4Vector(org.apache.drill.exec.vector.NullableUInt4Vector) Path(org.apache.hadoop.fs.Path) SchemaPath(org.apache.drill.common.expression.SchemaPath) NullableIntervalVector(org.apache.drill.exec.vector.NullableIntervalVector) NullableDateVector(org.apache.drill.exec.vector.NullableDateVector) NullableTimeStampVector(org.apache.drill.exec.vector.NullableTimeStampVector) NullableSmallIntVector(org.apache.drill.exec.vector.NullableSmallIntVector) NullableUInt2Vector(org.apache.drill.exec.vector.NullableUInt2Vector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) NullableBigIntVector(org.apache.drill.exec.vector.NullableBigIntVector) NullableTimeVector(org.apache.drill.exec.vector.NullableTimeVector)

Example 2 with NullableVarDecimalVector

use of org.apache.drill.exec.vector.NullableVarDecimalVector 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

NullableVarBinaryVector (org.apache.drill.exec.vector.NullableVarBinaryVector)2 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)2 NullableVarDecimalVector (org.apache.drill.exec.vector.NullableVarDecimalVector)2 SchemaPath (org.apache.drill.common.expression.SchemaPath)1 TypeProtos (org.apache.drill.common.types.TypeProtos)1 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)1 NullableBigIntVector (org.apache.drill.exec.vector.NullableBigIntVector)1 NullableBitVector (org.apache.drill.exec.vector.NullableBitVector)1 NullableDateVector (org.apache.drill.exec.vector.NullableDateVector)1 NullableFloat4Vector (org.apache.drill.exec.vector.NullableFloat4Vector)1 NullableFloat8Vector (org.apache.drill.exec.vector.NullableFloat8Vector)1 NullableIntVector (org.apache.drill.exec.vector.NullableIntVector)1 NullableIntervalVector (org.apache.drill.exec.vector.NullableIntervalVector)1 NullableSmallIntVector (org.apache.drill.exec.vector.NullableSmallIntVector)1 NullableTimeStampVector (org.apache.drill.exec.vector.NullableTimeStampVector)1 NullableTimeVector (org.apache.drill.exec.vector.NullableTimeVector)1 NullableTinyIntVector (org.apache.drill.exec.vector.NullableTinyIntVector)1 NullableUInt1Vector (org.apache.drill.exec.vector.NullableUInt1Vector)1 NullableUInt2Vector (org.apache.drill.exec.vector.NullableUInt2Vector)1 NullableUInt4Vector (org.apache.drill.exec.vector.NullableUInt4Vector)1