Class VectorContainer

java.lang.Object
org.apache.drill.exec.record.VectorContainer
All Implemented Interfaces:
Iterable<VectorWrapper<?>>, VectorAccessible
Direct Known Subclasses:
ExpandableHyperContainer

public class VectorContainer extends Object implements VectorAccessible
  • Field Details

  • Constructor Details

    • VectorContainer

      public VectorContainer()
    • VectorContainer

      public VectorContainer(OperatorContext oContext)
    • VectorContainer

      public VectorContainer(BufferAllocator allocator)
    • VectorContainer

      public VectorContainer(BufferAllocator allocator, BatchSchema schema)
      Create a new vector container given a pre-defined schema. Creates the corresponding vectors, but does not allocate memory for them. Call allocateNew() or allocateNewSafe() to allocate memory.

      Note that this method does the equivalent of buildSchema(SelectionVectorMode) using the schema provided.

      Parameters:
      allocator - allocator to be used to allocate memory later
      schema - the schema that defines the vectors to create
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getAllocator

      public BufferAllocator getAllocator()
    • isSchemaChanged

      public boolean isSchemaChanged()
    • schemaChanged

      public void schemaChanged()
      Indicate the schema changed. Normally set by mutating this container. If schemas are built externally, call this if the schema contained here is different than the one provided in a previous batch. (Some operators don't trust OK_NEW_SCHEMA, and use the schema changed flag for the "real" truth.
    • addHyperList

      public void addHyperList(List<ValueVector> vectors)
    • addHyperList

      public void addHyperList(List<ValueVector> vectors, boolean releasable)
    • transferIn

      public void transferIn(VectorContainer containerIn)
      Transfer vectors from containerIn to this.
    • rawTransferIn

      public void rawTransferIn(VectorContainer containerIn)
    • transferOut

      public void transferOut(VectorContainer containerOut)
      Transfer vectors from this to containerOut
    • addOrGet

      public <T extends ValueVector> T addOrGet(MaterializedField field)
    • addOrGet

      public <T extends ValueVector> T addOrGet(MaterializedField field, SchemaChangeCallBack callBack)
      This method should be called with MaterializedField which also has correct children field list specially when the field type is MAP. Otherwise after calling this method if caller is not creating TransferPair on the ValueVector, then the new ValueVector will not have information about it's list of children MaterializedField.
      Type Parameters:
      T -
      Parameters:
      field -
      callBack -
      Returns:
    • addOrGet

      public <T extends ValueVector> T addOrGet(String name, TypeProtos.MajorType type, Class<T> clazz)
    • getTransferClone

      public static VectorContainer getTransferClone(VectorAccessible incoming, OperatorContext oContext)
      Get a set of transferred clones of this container. Note that this guarantees that the vectors in the cloned container have the same TypedFieldIds as the existing container, allowing interchangeability in generated code. In the case of hyper vectors, this container actually doesn't do a full transfer, rather creating a clone vector wrapper only.
      Parameters:
      incoming - The RecordBatch iterator the contains the batch we should take over.
      Returns:
      A cloned vector container.
    • getTransferClone

      public static VectorContainer getTransferClone(VectorAccessible incoming, BufferAllocator allocator)
    • getTransferClone

      public static VectorContainer getTransferClone(VectorAccessible incoming, VectorWrapper<?>[] ignoreWrappers, OperatorContext oContext)
    • addCollection

      public void addCollection(Iterable<ValueVector> vectors)
    • appendRow

      public int appendRow(VectorContainer srcContainer, int srcIndex)
      This works with non-hyper VectorContainers which have no selection vectors. Appends a row taken from a source VectorContainer to this VectorContainer.
      Parameters:
      srcContainer - The VectorContainer to copy a row from.
      srcIndex - The index of the row to copy from the source VectorContainer.
      Returns:
      Position one above where the row was appended
    • add

      public TypedFieldId add(ValueVector vv)
    • getLast

      public ValueVector getLast()
    • add

      public void add(ValueVector[] hyperVector)
    • add

      public void add(ValueVector[] hyperVector, boolean releasable)
    • remove

      public void remove(ValueVector v)
    • getValueVectorId

      public TypedFieldId getValueVectorId(SchemaPath path)
      Description copied from interface: VectorAccessible
      Get the value vector type and id for the given schema path. The TypedFieldId should store a fieldId which is the same as the ordinal position of the field within the Iterator provided this classes implementation of Iterable<ValueVector>.
      Specified by:
      getValueVectorId in interface VectorAccessible
      Parameters:
      path - the path where the vector should be located.
      Returns:
      the local field id associated with this vector. If no field matches this path, this will return a null TypedFieldId
    • getValueVector

      public VectorWrapper<?> getValueVector(int index)
    • getValueAccessorById

      public VectorWrapper<?> getValueAccessorById(Class<?> clazz, int... fieldIds)
      Specified by:
      getValueAccessorById in interface VectorAccessible
    • hasSchema

      public boolean hasSchema()
    • getSchema

      public BatchSchema getSchema()
      Description copied from interface: VectorAccessible
      Get the schema of the current RecordBatch. This changes if and only if a *_NEW_SCHEMA IterOutcome is provided.
      Specified by:
      getSchema in interface VectorAccessible
      Returns:
      schema of the current batch
    • buildSchema

      public void buildSchema(BatchSchema.SelectionVectorMode mode)
    • iterator

      public Iterator<VectorWrapper<?>> iterator()
      Specified by:
      iterator in interface Iterable<VectorWrapper<?>>
    • clear

      public void clear()
    • removeAll

      public void removeAll()
    • setRecordCount

      public void setRecordCount(int recordCount)
    • incRecordCount

      public int incRecordCount()
      Increment the record count
      Returns:
      the new record count
    • getRecordCount

      public int getRecordCount()
      Description copied from interface: VectorAccessible
      Get the number of records.
      Specified by:
      getRecordCount in interface VectorAccessible
      Returns:
      number of records
    • hasRecordCount

      public boolean hasRecordCount()
    • getSelectionVector2

      public SelectionVector2 getSelectionVector2()
      Specified by:
      getSelectionVector2 in interface VectorAccessible
    • getSelectionVector4

      public SelectionVector4 getSelectionVector4()
      Specified by:
      getSelectionVector4 in interface VectorAccessible
    • zeroVectors

      public void zeroVectors()
      Clears the contained vectors. (See ValueVector.clear()). Note that the name zeroVector() in a value vector is used for the action to set all vectors to zero. Here it means to free the vector's memory. Sigh...
    • getNumberOfColumns

      public int getNumberOfColumns()
    • allocate

      public void allocate(int recordCount)
    • allocateNew

      public void allocateNew()
    • allocateNewSafe

      public boolean allocateNewSafe()
    • setValueCount

      public void setValueCount(int valueCount)
    • merge

      public VectorContainer merge(VectorContainer otherContainer)
      Merge two batches to create a single, combined, batch. Vectors appear in the order defined by BatchSchema.merge(BatchSchema). The two batches must have identical row counts. The pattern is that this container is the main part of the record batch, the other represents new columns to merge.

      Reference counts on the underlying buffers are unchanged. The client code is assumed to abandon the two input containers in favor of the merged container.

      Parameters:
      otherContainer - the container to merge with this one
      Returns:
      a new, merged, container
    • exchange

      public void exchange(VectorContainer other)
      Exchange buffers between two identical vector containers. The schemas must be identical in both column schemas and order. That is, after this call, data is exchanged between the containers. Requires that both containers be owned by the same allocator.
      Parameters:
      other - the target container with buffers to swap
    • prettyPrintRecord

      public String prettyPrintRecord(int index)
      This method create a pretty string for a record in the VectorContainer.
      Parameters:
      index - The index of the record of interest.
      Returns:
      The string representation of a record.
    • setEmpty

      public void setEmpty()
      Safely set this container to an empty batch. An empty batch is not fully empty: offset vectors must contain a single 0 entry in their first position.
    • copySchemaFrom

      public void copySchemaFrom(VectorAccessible other)
    • buildFrom

      public void buildFrom(BatchSchema sourceSchema)
    • allocatePrecomputedChildCount

      public void allocatePrecomputedChildCount(int valueCount, int bytesPerValue, int childValCount)