Interface Grouper.KeySerde<T>
public static interface Grouper.KeySerde<T>
Possibly-stateful object responsible for serde and comparison of keys. Does not need to be thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionReturn an object that knows how to compare two serialized keys.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.Create a reusable key that can be passed toreadFromByteBuffer(T, java.nio.ByteBuffer, int).default com.fasterxml.jackson.databind.ObjectMapperdecorateObjectMapper(com.fasterxml.jackson.databind.ObjectMapper spillMapper) Decorates the object mapper enabling it to read and write query results' grouping keys.Return the dictionary of this KeySerde.Return the estimated size of the dictionary of this KeySerde.keyClazz()Class of the keys.intkeySize()Size of the keys returned bytoByteBuffer(Object)(which must be a fixed size)voidreadFromByteBuffer(T key, ByteBuffer buffer, int position) Deserialize a key from a buffer.voidreset()Reset the keySerde to its initial state.toByteBuffer(T key) Serialize a key.
-
Method Details
-
keySize
int keySize()Size of the keys returned bytoByteBuffer(Object)(which must be a fixed size) -
keyClazz
Class of the keys. -
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
Serialize a key. This will be called by theGrouper.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 toreadFromByteBuffer(T, java.nio.ByteBuffer, int). -
readFromByteBuffer
Deserialize a key from a buffer. Will be called by theGrouper.iterator(boolean)method.- Parameters:
key- object fromcreateKey()buffer- buffer containing the keyposition- 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 theGrouper.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 GroupByQueryaggregatorOffsets- 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 theSpillingGrouperto 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)andbufferComparator()may no longer work properly on previously-serialized keys.
-