Class Var16CharVector.Mutator

java.lang.Object
org.apache.drill.exec.vector.BaseValueVector.BaseMutator
org.apache.drill.exec.vector.Var16CharVector.Mutator
All Implemented Interfaces:
ValueVector.Mutator, VariableWidthVector.VariableWidthMutator
Enclosing class:
Var16CharVector

public final class Var16CharVector.Mutator extends BaseValueVector.BaseMutator implements VariableWidthVector.VariableWidthMutator

Overview

MutableVar16Char implements a vector of variable width values. Elements in the vector are accessed by position from the logical start of the vector. A fixed width offsetVector is used to convert an element's position to it's offset from the start of the (0-based) DrillBuf. Size is inferred by adjacent elements. The width of each element is 4 byte(s) The equivalent Java primitive is 'int' NB: this class is automatically generated from ValueVectorTypes.tdd using FreeMarker.

Contract

  1. Supported Writes: VariableWidthVectors do not support random writes. In contrast FixedWidthVectors do allow random writes but special care is needed.
  2. Writing Values: All set methods must be called with a consecutive sequence of indices. With a few exceptions:
    1. You can update the last index you just set.
    2. You can reset a previous index (call it Idx), but you must assume all the data after Idx is corrupt. Also note that the memory consumed by data that came after Idx is not released.
  3. Setting Value Count: Vectors aren't explicitly aware of how many values they contain. So you must keep track of the number of values you've written to the vector and once you are done writing to the vector you must call setValueCount(int). It is possible to trim the vector by setting the value count to be less than the number of values currently contained in the vector. Note the extra memory consumed in the data buffer is not freed when this is done.
  4. Memory Allocation: When setting a value at an index you must do one of the following to ensure you do not get an IndexOutOfBoundsException.
    1. Allocate the exact amount of memory you need when using the set(int, byte[]) methods. If you do not manually allocate sufficient memory an IndexOutOfBoundsException can be thrown when the data buffer runs out of space.
    2. Or you can use the setSafe(int, byte[]) methods, which will automatically grow your data buffer to fit your data.
  5. Immutability: Once a vector has been populated with data and setValueCount(int) has been called, it should be considered immutable.

  • Constructor Details

    • Mutator

      public Mutator()
  • Method Details

    • set

      protected void set(int index, byte[] bytes)
      Set the variable length element at the specified index to the supplied byte array.
      Parameters:
      index - position of the bit to set
      bytes - array of bytes to write
    • setSafe

      public void setSafe(int index, byte[] bytes)
    • setSafe

      public <T extends VarLenBulkEntry> void setSafe(VarLenBulkInput<T> input)
      Copies the bulk input into this value vector and extends its capacity if necessary.
      Parameters:
      input - bulk input
    • setSafe

      public <T extends VarLenBulkEntry> void setSafe(VarLenBulkInput<T> input, VarLenBulkInput.BulkInputCallback<T> callback)
      Copies the bulk input into this value vector and extends its capacity if necessary. The callback mechanism allows decoration as caller is invoked for each bulk entry.
      Parameters:
      input - bulk input
      callback - a bulk input callback object (optional)
    • set

      protected void set(int index, byte[] bytes, int start, int length)
      Set the variable length element at the specified index to the supplied byte array.
      Parameters:
      index - position of the bit to set
      bytes - array of bytes to write
      start - start index of bytes to write
      length - length of bytes to write
    • setSafe

      public void setSafe(int index, ByteBuffer bytes, int start, int length)
    • setSafe

      public void setSafe(int index, byte[] bytes, int start, int length)
    • setValueLengthSafe

      public void setValueLengthSafe(int index, int length)
      Specified by:
      setValueLengthSafe in interface VariableWidthVector.VariableWidthMutator
    • setSafe

      public void setSafe(int index, int start, int end, DrillBuf buffer)
    • setSafe

      public void setSafe(int index, NullableVar16CharHolder holder)
    • setSafe

      public void setSafe(int index, Var16CharHolder holder)
    • fillEmpties

      public void fillEmpties(int lastWrite, int index)
      Backfill missing offsets from the given last written position up to, but not including the given current write position. Used by nullable vectors to allow skipping values. The set() and setSafe() do not fill empties. See DRILL-5529.
      Parameters:
      lastWrite - the position of the last valid write: the offset to be copied forward
      index - the current write position filling occurs up to, but not including, this position
    • set

      protected void set(int index, int start, int length, DrillBuf buffer)
    • set

      protected void set(int index, NullableVar16CharHolder holder)
    • set

      protected void set(int index, Var16CharHolder holder)
    • setValueCount

      public void setValueCount(int valueCount)

      Notes on Usage

      For VariableWidthVectors this method can be used in the following cases:

      • Setting the actual number of elements currently contained in the vector.
      • Trimming the vector to have fewer elements than it current does.

      Caveats

      It is important to note that for FixedWidthVectors this method can also be used to expand the vector. However, VariableWidthVector do not support this usage and this method will throw an IndexOutOfBoundsException if you attempt to use it in this way. Expansion of valueCounts is not supported mainly because there is no benefit, since you would still have to rely on the setSafe methods to appropriately expand the data buffer and populate the vector anyway (since by definition we do not know the width of elements). See DRILL-6234 for details.

      Method Documentation

      Sets the number of values that is stored in this vector to the given value count. WARNING! Once the valueCount is set, the vector should be considered immutable.
      Specified by:
      setValueCount in interface ValueVector.Mutator
      Parameters:
      valueCount - value count to set.
    • generateTestData

      public void generateTestData(int size)
      Specified by:
      generateTestData in interface ValueVector.Mutator
      Overrides:
      generateTestData in class BaseValueVector.BaseMutator