Interface Grouper.KeySerde<T>

Enclosing interface:
Grouper<KeyType>

public static interface Grouper.KeySerde<T>
Possibly-stateful object responsible for serde and comparison of keys. Does not need to be thread-safe.
  • Method Details

    • keySize

      int keySize()
      Size of the keys returned by toByteBuffer(Object) (which must be a fixed size)
    • keyClazz

      Class<T> keyClazz()
      Class of the keys.
    • getDictionary

      List<String> getDictionary()
      Return the dictionary of this KeySerde. The return value should not be null.
    • getDictionarySize

      Long getDictionarySize()
      Return the estimated size of the dictionary of this KeySerde.
    • toByteBuffer

      @Nullable ByteBuffer toByteBuffer(T key)
      Serialize a key. This will be called by the Grouper.aggregate(Object) method. The buffer will not be retained after the aggregate method returns, so reusing buffers is OK.

      This method may return null, which indicates that some internal resource limit has been reached and no more keys can be generated. In this situation you can call reset() and try again, although beware the caveats on that method.

      Parameters:
      key - key object
      Returns:
      serialized key, or null if we are unable to serialize more keys due to resource limits
    • createKey

      T createKey()
      Create a reusable key that can be passed to readFromByteBuffer(T, java.nio.ByteBuffer, int).
    • readFromByteBuffer

      void readFromByteBuffer(T key, ByteBuffer buffer, int position)
      Deserialize a key from a buffer. Will be called by the Grouper.iterator(boolean) method.
      Parameters:
      key - object from createKey()
      buffer - buffer containing the key
      position - key start position in the buffer
    • bufferComparator

      Grouper.BufferComparator bufferComparator()
      Return an object that knows how to compare two serialized keys. Will be called by the Grouper.iterator(boolean) method if sorting is enabled.
      Returns:
      comparator for keys
    • bufferComparatorWithAggregators

      Grouper.BufferComparator bufferComparatorWithAggregators(AggregatorFactory[] aggregatorFactories, int[] aggregatorOffsets)
      When pushing down limits, it may also be necessary to compare aggregated values along with the key using the bufferComparator.
      Parameters:
      aggregatorFactories - Array of aggregators from a GroupByQuery
      aggregatorOffsets - Offsets for each aggregator in aggregatorFactories pointing to their location within the grouping key + aggs buffer.
      Returns:
      comparator for keys + aggs
    • decorateObjectMapper

      default com.fasterxml.jackson.databind.ObjectMapper decorateObjectMapper(com.fasterxml.jackson.databind.ObjectMapper spillMapper)
      Decorates the object mapper enabling it to read and write query results' grouping keys. It is used by the SpillingGrouper to preserve the types of the dimensions after serializing and deserializing them on the spilled files.
    • reset

      void reset()
      Reset the keySerde to its initial state. After this method is called, readFromByteBuffer(T, java.nio.ByteBuffer, int) and bufferComparator() may no longer work properly on previously-serialized keys.