Search in sources :

Example 11 with SerializedField

use of org.apache.drill.exec.proto.UserBitShared.SerializedField in project drill by axbaretto.

the class VectorAccessibleSerializable method readFromStreamWithContainer.

// Like above, only preserve the original container and list of value-vectors
@SuppressWarnings("resource")
public void readFromStreamWithContainer(VectorContainer myContainer, InputStream input) throws IOException {
    final VectorContainer container = new VectorContainer();
    final UserBitShared.RecordBatchDef batchDef = UserBitShared.RecordBatchDef.parseDelimitedFrom(input);
    recordCount = batchDef.getRecordCount();
    if (batchDef.hasCarriesTwoByteSelectionVector() && batchDef.getCarriesTwoByteSelectionVector()) {
        if (sv2 == null) {
            sv2 = new SelectionVector2(allocator);
        }
        sv2.allocateNew(recordCount * SelectionVector2.RECORD_SIZE);
        sv2.getBuffer().setBytes(0, input, recordCount * SelectionVector2.RECORD_SIZE);
        svMode = BatchSchema.SelectionVectorMode.TWO_BYTE;
    }
    final List<ValueVector> vectorList = Lists.newArrayList();
    final List<SerializedField> fieldList = batchDef.getFieldList();
    for (SerializedField metaData : fieldList) {
        final int dataLength = metaData.getBufferLength();
        final MaterializedField field = MaterializedField.create(metaData);
        final DrillBuf buf = allocator.buffer(dataLength);
        final ValueVector vector;
        try {
            buf.writeBytes(input, dataLength);
            vector = TypeHelper.getNewVector(field, allocator);
            vector.load(metaData, buf);
        } finally {
            buf.release();
        }
        vectorList.add(vector);
    }
    container.addCollection(vectorList);
    container.setRecordCount(recordCount);
    // transfer the vectors
    myContainer.transferIn(container);
    myContainer.buildSchema(svMode);
    myContainer.setRecordCount(recordCount);
    /*
    // for debugging -- show values from the first row
    Object tmp0 = (myContainer).getValueAccessorById(NullableVarCharVector.class, 0).getValueVector();
    Object tmp1 = (myContainer).getValueAccessorById(NullableVarCharVector.class, 1).getValueVector();
    Object tmp2 = (myContainer).getValueAccessorById(NullableBigIntVector.class, 2).getValueVector();
    if (tmp0 != null && tmp1 != null && tmp2 != null) {
      NullableVarCharVector vv0 = ((NullableVarCharVector) tmp0);
      NullableVarCharVector vv1 = ((NullableVarCharVector) tmp1);
      NullableBigIntVector vv2 = ((NullableBigIntVector) tmp2);

      try {
        logger.info("HASH AGG: Got a row = {} , {} , {}", vv0.getAccessor().get(0), vv1.getAccessor().get(0), vv2.getAccessor().get(0));
      } catch (Exception e) { logger.info("HASH AGG: Got an exception = {}",e); }
    }
    else { logger.info("HASH AGG: got nulls !!!"); }
    */
    va = myContainer;
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) SerializedField(org.apache.drill.exec.proto.UserBitShared.SerializedField) RecordBatchDef(org.apache.drill.exec.proto.UserBitShared.RecordBatchDef) SelectionVector2(org.apache.drill.exec.record.selection.SelectionVector2) MaterializedField(org.apache.drill.exec.record.MaterializedField) UserBitShared(org.apache.drill.exec.proto.UserBitShared) VectorContainer(org.apache.drill.exec.record.VectorContainer) DrillBuf(io.netty.buffer.DrillBuf)

Example 12 with SerializedField

use of org.apache.drill.exec.proto.UserBitShared.SerializedField in project drill by axbaretto.

the class VectorAccessibleSerializable method readVectors.

@SuppressWarnings("resource")
private void readVectors(InputStream input, RecordBatchDef batchDef) throws IOException {
    final VectorContainer container = new VectorContainer();
    final List<ValueVector> vectorList = Lists.newArrayList();
    final List<SerializedField> fieldList = batchDef.getFieldList();
    for (SerializedField metaData : fieldList) {
        final int dataLength = metaData.getBufferLength();
        final MaterializedField field = MaterializedField.create(metaData);
        final DrillBuf buf = allocator.read(dataLength, input);
        final ValueVector vector = TypeHelper.getNewVector(field, allocator);
        vector.load(metaData, buf);
        // Vector now owns the buffer
        buf.release();
        vectorList.add(vector);
    }
    container.addCollection(vectorList);
    container.buildSchema(svMode);
    container.setRecordCount(recordCount);
    va = container;
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) SerializedField(org.apache.drill.exec.proto.UserBitShared.SerializedField) MaterializedField(org.apache.drill.exec.record.MaterializedField) VectorContainer(org.apache.drill.exec.record.VectorContainer) DrillBuf(io.netty.buffer.DrillBuf)

Example 13 with SerializedField

use of org.apache.drill.exec.proto.UserBitShared.SerializedField in project drill by axbaretto.

the class MergingRecordBatch method buildSchema.

@Override
public void buildSchema() throws SchemaChangeException {
    // find frag provider that has data to use to build schema, and put in tempBatchHolder for later use
    tempBatchHolder = new RawFragmentBatch[fragProviders.length];
    int i = 0;
    try {
        while (true) {
            if (i >= fragProviders.length) {
                state = BatchState.DONE;
                return;
            }
            final RawFragmentBatch batch = getNext(i);
            if (batch == null) {
                if (!context.getExecutorState().shouldContinue()) {
                    state = BatchState.STOP;
                } else {
                    state = BatchState.DONE;
                }
                break;
            }
            if (batch.getHeader().getDef().getFieldCount() == 0) {
                i++;
                continue;
            }
            tempBatchHolder[i] = batch;
            for (final SerializedField field : batch.getHeader().getDef().getFieldList()) {
                @SuppressWarnings("resource") final ValueVector v = outgoingContainer.addOrGet(MaterializedField.create(field));
                v.allocateNew();
            }
            break;
        }
    } catch (final IOException e) {
        throw new DrillRuntimeException(e);
    }
    outgoingContainer.buildSchema(SelectionVectorMode.NONE);
}
Also used : RawFragmentBatch(org.apache.drill.exec.record.RawFragmentBatch) ValueVector(org.apache.drill.exec.vector.ValueVector) SerializedField(org.apache.drill.exec.proto.UserBitShared.SerializedField) IOException(java.io.IOException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) MinorFragmentEndpoint(org.apache.drill.exec.physical.MinorFragmentEndpoint)

Example 14 with SerializedField

use of org.apache.drill.exec.proto.UserBitShared.SerializedField in project drill by axbaretto.

the class MapVector method load.

@Override
public void load(SerializedField metadata, DrillBuf buf) {
    final List<SerializedField> fields = metadata.getChildList();
    valueCount = metadata.getValueCount();
    int bufOffset = 0;
    for (final SerializedField child : fields) {
        final MaterializedField fieldDef = MaterializedField.create(child);
        ValueVector vector = getChild(fieldDef.getName());
        if (vector == null) {
            // if we arrive here, we didn't have a matching vector.
            vector = BasicTypeHelper.getNewVector(fieldDef, allocator);
            putChild(fieldDef.getName(), vector);
        }
        if (child.getValueCount() == 0) {
            vector.clear();
        } else {
            vector.load(child, buf.slice(bufOffset, child.getBufferLength()));
        }
        bufOffset += child.getBufferLength();
    }
    assert bufOffset == buf.writerIndex();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) BaseValueVector(org.apache.drill.exec.vector.BaseValueVector) SerializedField(org.apache.drill.exec.proto.UserBitShared.SerializedField) MaterializedField(org.apache.drill.exec.record.MaterializedField)

Example 15 with SerializedField

use of org.apache.drill.exec.proto.UserBitShared.SerializedField in project drill by axbaretto.

the class RepeatedMapVector method load.

@Override
public void load(SerializedField metadata, DrillBuf buffer) {
    final List<SerializedField> children = metadata.getChildList();
    final SerializedField offsetField = children.get(0);
    offsets.load(offsetField, buffer);
    int bufOffset = offsetField.getBufferLength();
    for (int i = 1; i < children.size(); i++) {
        final SerializedField child = children.get(i);
        final MaterializedField fieldDef = MaterializedField.create(child);
        ValueVector vector = getChild(fieldDef.getName());
        if (vector == null) {
            // if we arrive here, we didn't have a matching vector.
            vector = BasicTypeHelper.getNewVector(fieldDef, allocator);
            putChild(fieldDef.getName(), vector);
        }
        final int vectorLength = child.getBufferLength();
        vector.load(child, buffer.slice(bufOffset, vectorLength));
        bufOffset += vectorLength;
    }
    assert bufOffset == buffer.writerIndex();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) SerializedField(org.apache.drill.exec.proto.UserBitShared.SerializedField) MaterializedField(org.apache.drill.exec.record.MaterializedField)

Aggregations

SerializedField (org.apache.drill.exec.proto.UserBitShared.SerializedField)20 ValueVector (org.apache.drill.exec.vector.ValueVector)20 MaterializedField (org.apache.drill.exec.record.MaterializedField)9 DrillBuf (io.netty.buffer.DrillBuf)8 RecordBatchDef (org.apache.drill.exec.proto.UserBitShared.RecordBatchDef)4 VectorContainer (org.apache.drill.exec.record.VectorContainer)4 StackTrace (org.apache.drill.common.StackTrace)2 MinorFragmentEndpoint (org.apache.drill.exec.physical.MinorFragmentEndpoint)2 UserBitShared (org.apache.drill.exec.proto.UserBitShared)2 SelectionVectorMode (org.apache.drill.exec.record.BatchSchema.SelectionVectorMode)2 RawFragmentBatch (org.apache.drill.exec.record.RawFragmentBatch)2 SelectionVector2 (org.apache.drill.exec.record.selection.SelectionVector2)2 BaseValueVector (org.apache.drill.exec.vector.BaseValueVector)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)1 UntypedNullVector (org.apache.drill.exec.vector.UntypedNullVector)1