java.lang.Object
org.elasticsearch.compute.aggregation.blockhash.BlockHash
org.elasticsearch.compute.aggregation.blockhash.TimeSeriesBlockHash
All Implemented Interfaces:
Closeable, AutoCloseable, SeenGroupIds, org.elasticsearch.core.Releasable

public final class TimeSeriesBlockHash extends BlockHash
An optimized block hash that receives two blocks: tsid and timestamp, which are sorted. Since the incoming data is sorted, this block hash checks tsid ordinals to avoid redundant hash lookups for consecutive positions with the same tsid and timestamp. Delegates to a BytesRefLongBlockHash for the actual hashing.
  • Constructor Details

    • TimeSeriesBlockHash

      public TimeSeriesBlockHash(int tsidChannel, int timestampChannel, boolean reverseOutput, boolean trackTimestamp, BlockFactory blockFactory)
  • Method Details

    • close

      public void close()
    • add

      public void add(Page page, GroupingAggregatorFunction.AddInput addInput)
      Description copied from class: BlockHash
      Add all values for the "group by" columns in the page to the hash and pass the ordinals to the provided GroupingAggregatorFunction.AddInput.

      This call will not Releasable.close() addInput.

      Specified by:
      add in class BlockHash
    • lookup

      public org.elasticsearch.core.ReleasableIterator<IntBlock> lookup(Page page, ByteSizeValue targetBlockSize)
      Description copied from class: BlockHash
      Lookup all values for the "group by" columns in the page to the hash and return an Iterator of the values. The sum of Block.getPositionCount() for all blocks returned by the iterator will equal Page.getPositionCount() but will "target" a size of targetBlockSize.

      The returned ReleasableIterator may retain a reference to Blocks inside the Page. Close it to release those references.

      Specified by:
      lookup in class BlockHash
    • getKeys

      public Block[] getKeys(IntVector selected)
      Description copied from class: BlockHash
      Returns an array of Blocks containing keys.
      Specified by:
      getKeys in class BlockHash
      Parameters:
      selected - The groupIds to include in the results. These are the same groupIds returned by BlockHash.nonEmpty() and fed into aggregations as part of BlockHash.add(org.elasticsearch.compute.data.Page, org.elasticsearch.compute.aggregation.GroupingAggregatorFunction.AddInput).
    • nonEmpty

      public IntVector nonEmpty()
      Description copied from class: BlockHash
      The grouping ids that are not empty. We use this because some block hashes reserve space for grouping ids and then don't end up using them. For example, BooleanBlockHash does this by always assigning false to 0 and true to 1. It's only after collection when we know if there actually were any true or false values received.
      Specified by:
      nonEmpty in class BlockHash
    • numKeys

      public int numKeys()
      Description copied from class: BlockHash
      The number of unique keys in the hash.
      Specified by:
      numKeys in class BlockHash
    • seenGroupIds

      public BitArray seenGroupIds(BigArrays bigArrays)
      Description copied from interface: SeenGroupIds
      The grouping ids that have been seen already. This BitArray is kept and mutated by the caller so make a copy if it's something you need your own copy of it.
      Specified by:
      seenGroupIds in interface SeenGroupIds
      Specified by:
      seenGroupIds in class BlockHash
    • tsidForGroup

      public int tsidForGroup(long groupId)
    • timestampForGroup

      public long timestampForGroup(long groupId)
    • getGroupId

      public long getGroupId(long tsid, long timestamp)
    • addExtraGroup

      public long addExtraGroup(int tsid, long timestamp)
    • numGroups

      public long numGroups()
    • minTimestamp

      public long minTimestamp()
    • maxTimestamp

      public long maxTimestamp()
    • toString

      public String toString()
      Overrides:
      toString in class Object