Class ArrayBackedColumnSource<T>

java.lang.Object
com.illumon.iris.db.v2.sources.AbstractColumnSource<T>
com.illumon.iris.db.v2.sources.ArrayBackedColumnSource<T>
All Implemented Interfaces:
ChunkSource<Attributes.Values>, ChunkSource.WithPrev<Attributes.Values>, DefaultChunkSource<Attributes.Values>, DefaultChunkSource.WithPrev<Attributes.Values>, FillContextMaker, GetContextMaker, ColumnSource<T>, ElementSource<T>, FillUnordered, Releasable, WritableChunkSink<Attributes.Values>, WritableSource<T>, TupleExporter<T>, TupleSource<T>, ShiftData.ShiftCallback, Serializable
Direct Known Subclasses:
BooleanArraySource, ByteArraySource, CharacterArraySource, DoubleArraySource, FloatArraySource, IntegerArraySource, LongArraySource, NanosBasedTimeArraySource, ObjectArraySource, ShortArraySource

public abstract class ArrayBackedColumnSource<T> extends AbstractColumnSource<T> implements FillUnordered, ShiftData.ShiftCallback, WritableSource<T>, Serializable
A ColumnSource backed by in-memory arrays of data. The column source is dense with keys from 0 to capacity, there can be no holes. Arrays are divided into blocks so that the column source can be incrementally expanded without copying data from one array to another.
See Also:
  • Field Details

  • Method Details

    • set

      public void set(long key, byte value)
      Specified by:
      set in interface WritableSource<T>
    • set

      public void set(long key, char value)
      Specified by:
      set in interface WritableSource<T>
    • set

      public void set(long key, double value)
      Specified by:
      set in interface WritableSource<T>
    • set

      public void set(long key, float value)
      Specified by:
      set in interface WritableSource<T>
    • set

      public void set(long key, int value)
      Specified by:
      set in interface WritableSource<T>
    • set

      public void set(long key, long value)
      Specified by:
      set in interface WritableSource<T>
    • set

      public void set(long key, short value)
      Specified by:
      set in interface WritableSource<T>
    • getMemoryColumnSource

      public static <T> ArrayBackedColumnSource<T> getMemoryColumnSource(Collection<T> data, Class<T> type)
      Produces an ArrayBackedColumnSource with the given data.
      Parameters:
      data - a collection containing the data to insert into the ColumnSource.
      type - the type of the resulting column source
      Returns:
      an in-memory column source with the requested data
    • getMemoryColumnSource

      public static <T> ArrayBackedColumnSource<T> getMemoryColumnSource(T[] data, Class<T> type)
      Produces an ArrayBackedColumnSource with the given data.
      Parameters:
      data - an array containing the data to insert into the ColumnSource.
      type - the type of the resulting column source
      Returns:
      an in-memory column source with the requested data
    • getMemoryColumnSource

      public static ArrayBackedColumnSource<Byte> getMemoryColumnSource(byte[] data)
      Produces an ByteArraySource with the given data.
      Parameters:
      data - an array containing the data to insert into the ColumnSource.
      Returns:
      an in-memory column source with the requested data
    • getMemoryColumnSource

      public static ArrayBackedColumnSource<Character> getMemoryColumnSource(char[] data)
      Produces an CharacterArraySource with the given data.
      Parameters:
      data - an array containing the data to insert into the ColumnSource.
      Returns:
      an in-memory column source with the requested data
    • getMemoryColumnSource

      public static ArrayBackedColumnSource<Double> getMemoryColumnSource(double[] data)
      Produces an DoubleArraySource with the given data.
      Parameters:
      data - an array containing the data to insert into the ColumnSource.
      Returns:
      an in-memory column source with the requested data
    • getMemoryColumnSource

      public static ArrayBackedColumnSource<Float> getMemoryColumnSource(float[] data)
      Produces an FloatArraySource with the given data.
      Parameters:
      data - an array containing the data to insert into the ColumnSource.
      Returns:
      an in-memory column source with the requested data
    • getMemoryColumnSource

      public static ArrayBackedColumnSource<Integer> getMemoryColumnSource(int[] data)
      Produces an IntegerArraySource with the given data.
      Parameters:
      data - an array containing the data to insert into the ColumnSource.
      Returns:
      an in-memory column source with the requested data
    • getMemoryColumnSource

      public static ArrayBackedColumnSource<Long> getMemoryColumnSource(long[] data)
      Produces an LongArraySource with the given data.
      Parameters:
      data - an array containing the data to insert into the ColumnSource.
      Returns:
      an in-memory column source with the requested data
    • getDateTimeMemoryColumnSource

      public static ArrayBackedColumnSource<DBDateTime> getDateTimeMemoryColumnSource(long[] data)
      Produces an DateTimeArraySource with the given data.
      Parameters:
      data - an array containing the data to insert into the ColumnSource, represented as long nanoseconds since the epoch
      Returns:
      an in-memory column source with the requested data
    • getDateTimeMemoryColumnSource

      public static ArrayBackedColumnSource<DBDateTime> getDateTimeMemoryColumnSource(LongChunk<Attributes.Values> data)
      Produces an DateTimeArraySource with the given data.
      Parameters:
      data - an array containing the data to insert into the ColumnSource, represented as long nanoseconds since the epoch
      Returns:
      an in-memory column source with the requested data
    • getMemoryColumnSource

      public static ArrayBackedColumnSource<Short> getMemoryColumnSource(short[] data)
      Produces an ShortArraySource with the given data.
      Parameters:
      data - an array containing the data to insert into the ColumnSource.
      Returns:
      an in-memory column source with the requested data
    • getMemoryColumnSource

      public static <T> ArrayBackedColumnSource<T> getMemoryColumnSource(long size, Class<T> type)
      Produces an empty ArrayBackedColumnSource with the given type and capacity.
      Type Parameters:
      T - the type parameter for the ColumnSource's type
      Parameters:
      size - the capacity of the returned column source
      type - the type of the resultant column source
      Returns:
      an in-memory column source of the requested type
    • getMemoryColumnSource

      public static <T> ArrayBackedColumnSource<T> getMemoryColumnSource(Class<T> type, @Nullable Class componentType)
    • getMemoryColumnSource

      public static <T> ArrayBackedColumnSource<T> getMemoryColumnSource(long size, Class<T> type, @Nullable Class componentType)
      Produces an empty ArrayBackedColumnSource with the given type and capacity.
      Type Parameters:
      T - the type parameter for the ColumnSource's type
      Parameters:
      size - the capacity of the returned column source
      type - the type of the resultant column source
      componentType - the component type for column sources of arrays or DbArrays
      Returns:
      an in-memory column source of the requested type
    • ensureCapacity

      public abstract void ensureCapacity(long size, boolean nullFill)
    • shift

      public void shift(long start, long end, long offset)
      Specified by:
      shift in interface ShiftData.ShiftCallback
    • getMemoryColumnSource

      public static WritableSource getMemoryColumnSource(Object dataArray)
      Creates an in-memory ColumnSource from the supplied dataArray, using instanceof checks to determine the appropriate type of column source to produce.
      Parameters:
      dataArray - the data to insert into the new column source
      Returns:
      a ColumnSource with the supplied data.
    • getImmutableMemoryColumnSource

      public static ColumnSource getImmutableMemoryColumnSource(@NotNull Object dataArray)
      Wrap the input array in an immutable ColumnSource. This method will unbox any boxed values, and directly use the result array.
      Parameters:
      dataArray - The array to turn into a ColumnSource
      Returns:
      An Immutable ColumnSource that directly wraps the input array.
    • getImmutableMemoryColumnSource

      public static ColumnSource getImmutableMemoryColumnSource(Object dataArray, Class<?> type)
      Wrap the input array in an immutable ColumnSource. This method will unbox any boxed values, and directly use the result array. This version allows the user to specify the column type. It will automatically map column type Boolean/boolean with input array types byte[] to ImmutableBooleanArraySource and columnType DBDateTime / array type long[] to ImmutableDateTimeArraySource
      Parameters:
      dataArray - The array to turn into a ColumnSource
      Returns:
      An Immutable ColumnSource that directly wraps the input array.
    • isImmutable

      public boolean isImmutable()
      Description copied from interface: ColumnSource
      Determine if this column source is immutable, meaning that the values at a given index key never change.
      Specified by:
      isImmutable in interface ColumnSource<T>
      Returns:
      true if the values at a given index of the column source never change, false otherwise
    • fillChunk

      public void fillChunk(@NotNull ChunkSource.FillContext context, @NotNull WritableChunk<? super Attributes.Values> destination, @NotNull OrderedKeys orderedKeys)
      Description copied from interface: ChunkSource
      Populates the given destination chunk with data corresponding to the keys from the given OrderedKeys.
      Specified by:
      fillChunk in interface ChunkSource<T>
      Overrides:
      fillChunk in class AbstractColumnSource<T>
      Parameters:
      context - A context containing all mutable/state related data used in retrieving the Chunk.
      destination - The chunk to be populated according to orderedKeys. No assumptions shall be made about the size of the chunk shall be made. The chunk will be populated from position [0,orderedKeys.size()).
      orderedKeys - An OrderedKeys representing the keys to be fetched
    • fillChunkUnordered

      public void fillChunkUnordered(@NotNull ChunkSource.FillContext context, @NotNull WritableChunk<? super Attributes.Values> destination, @NotNull LongChunk<? extends Attributes.KeyIndices> keyIndices)
      Description copied from interface: FillUnordered
      Populates a contiguous portion of the given destination chunk with data corresponding to the keys from the given LongChunk.
      Specified by:
      fillChunkUnordered in interface FillUnordered
      Parameters:
      context - A context containing all mutable/state related data used in retrieving the Chunk.
      destination - The chunk to be populated according to keys
      keyIndices - A chunk of individual, not assumed to be ordered keys to be fetched
    • fillPrevChunkUnordered

      public void fillPrevChunkUnordered(@NotNull ChunkSource.FillContext context, @NotNull WritableChunk<? super Attributes.Values> destination, @NotNull LongChunk<? extends Attributes.KeyIndices> keyIndices)
      Description copied from interface: FillUnordered
      Populates a contiguous portion of the given destination chunk with prev data corresponding to the keys from the given LongChunk.
      Specified by:
      fillPrevChunkUnordered in interface FillUnordered
      Parameters:
      context - A context containing all mutable/state related data used in retrieving the Chunk.
      destination - The chunk to be populated according to keys
      keyIndices - A chunk of individual, not assumed to be ordered keys to be fetched
    • resetWritableChunkToBackingStore

      public abstract long resetWritableChunkToBackingStore(@NotNull ResettableWritableChunk chunk, long position)
      Resets the given chunk to provide a write-through reference to our backing array. Note: This is unsafe to use if previous tracking has been enabled!
      Parameters:
      chunk - the writable chunk to reset to our backing array.
      position - position that we require
      Returns:
      the first position addressable by the chunk
    • fillSparseChunk

      protected abstract void fillSparseChunk(@NotNull WritableChunk<? super Attributes.Values> destination, @NotNull OrderedKeys indices)
    • fillSparsePrevChunk

      protected abstract void fillSparsePrevChunk(@NotNull WritableChunk<? super Attributes.Values> destination, @NotNull OrderedKeys indices)
    • fillSparseChunkUnordered

      protected abstract void fillSparseChunkUnordered(@NotNull WritableChunk<? super Attributes.Values> destination, @NotNull LongChunk<? extends Attributes.KeyIndices> indices)
    • fillSparsePrevChunkUnordered

      protected abstract void fillSparsePrevChunkUnordered(@NotNull WritableChunk<? super Attributes.Values> destination, @NotNull LongChunk<? extends Attributes.KeyIndices> indices)
    • getChunk

      public Chunk<Attributes.Values> getChunk(@NotNull ChunkSource.GetContext context, @NotNull OrderedKeys orderedKeys)
      Description copied from interface: ChunkSource
      Returns a chunk of data corresponding to the keys from the given OrderedKeys.
      Specified by:
      getChunk in interface ChunkSource<T>
      Specified by:
      getChunk in interface DefaultChunkSource<T>
      Parameters:
      context - A context containing all mutable/state related data used in retrieving the Chunk. In particular, the Context may be used to provide a Chunk data pool
      orderedKeys - An OrderedKeys representing the keys to be fetched
      Returns:
      A chunk of data corresponding to the keys from the given OrderedKeys