Class ObjectStrategyComplexTypeStrategy<T>
- java.lang.Object
-
- org.apache.druid.segment.column.ObjectStrategyComplexTypeStrategy<T>
-
- All Implemented Interfaces:
it.unimi.dsi.fastutil.Hash.Strategy<T>,Comparator<Object>,TypeStrategy<T>
public class ObjectStrategyComplexTypeStrategy<T> extends Object implements TypeStrategy<T>
Default implementation ofTypeStrategyfor allComplexMetricSerdeimplementations that just wraps theObjectStrategythey are required to implement.This is not likely to be the most efficient way to do things, especially since writing must first produce a byte array before it can be written to the buffer, but it is cheap and should work correctly, which is important.
-
-
Constructor Summary
Constructors Constructor Description ObjectStrategyComplexTypeStrategy(ObjectStrategy<T> objectStrategy, TypeSignature<?> signature)ObjectStrategyComplexTypeStrategy(ObjectStrategy<T> objectStrategy, TypeSignature<?> signature, it.unimi.dsi.fastutil.Hash.Strategy<T> hashStrategy)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompare(Object o1, Object o2)booleanequals(T a, T b)intestimateSizeBytes(T value)Estimate the size in bytes that writing this value to memory would require.TfromBytes(byte[] value)Translate raw byte array into a value.booleangroupable()Whether the type is groupable or not.inthashCode(T o)Tread(ByteBuffer buffer)Read a non-null value from theByteBufferat the currentBuffer.position().booleanreadRetainsBufferReference()Whether theTypeStrategy.read(java.nio.ByteBuffer)methods return an object that may retain a reference to the providedByteBuffer.intwrite(ByteBuffer buffer, T value, int maxSizeBytes)Write a non-null value to theByteBufferat positionBuffer.position().-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Methods inherited from interface org.apache.druid.segment.column.TypeStrategy
read, write
-
-
-
-
Constructor Detail
-
ObjectStrategyComplexTypeStrategy
public ObjectStrategyComplexTypeStrategy(ObjectStrategy<T> objectStrategy, TypeSignature<?> signature)
-
ObjectStrategyComplexTypeStrategy
public ObjectStrategyComplexTypeStrategy(ObjectStrategy<T> objectStrategy, TypeSignature<?> signature, @Nullable it.unimi.dsi.fastutil.Hash.Strategy<T> hashStrategy)
-
-
Method Detail
-
estimateSizeBytes
public int estimateSizeBytes(@Nullable T value)
Description copied from interface:TypeStrategyEstimate the size in bytes that writing this value to memory would require. This method is not required to be exactly correct, but many implementations might be. Implementations should err on the side of over-estimating if exact sizing is not efficient. Example usage of this method is estimating heap memory usage for an aggregator or the amount of buffer which might need allocated to thenTypeStrategy.write(java.nio.ByteBuffer, T, int)a value- Specified by:
estimateSizeBytesin interfaceTypeStrategy<T>
-
read
public T read(ByteBuffer buffer)
Description copied from interface:TypeStrategyRead a non-null value from theByteBufferat the currentBuffer.position(). This will move the underlying position by the size of the value read. The value returned from this method may retain a reference to the providedByteBuffer. If it does, thenTypeStrategy.readRetainsBufferReference()returns true.- Specified by:
readin interfaceTypeStrategy<T>
-
readRetainsBufferReference
public boolean readRetainsBufferReference()
Description copied from interface:TypeStrategyWhether theTypeStrategy.read(java.nio.ByteBuffer)methods return an object that may retain a reference to the providedByteBuffer. If a reference is sometimes retained, this method returns true. It returns false if, and only if, a reference is *never* retained.- Specified by:
readRetainsBufferReferencein interfaceTypeStrategy<T>
-
write
public int write(ByteBuffer buffer, T value, int maxSizeBytes)
Description copied from interface:TypeStrategyWrite a non-null value to theByteBufferat positionBuffer.position(). This will move the underlying position by the size of the value written. This method returns the number of bytes written. If writing the value would take more than 'maxSizeBytes', this method will return a negative value indicating the number of additional bytes that would be required to fully write the value. Partial results may be written to the buffer when in this state, and the position may be left at whatever point the implementation ran out of space while writing the value. Callers should save the starting position if it is necessary to 'rewind' after a partial write. Callers MUST check that the return value is positive which indicates a successful write, while a negative response a partial write.- Specified by:
writein interfaceTypeStrategy<T>- Returns:
- number of bytes written
-
compare
public int compare(Object o1, Object o2)
- Specified by:
comparein interfaceComparator<T>
-
fromBytes
public T fromBytes(byte[] value)
Description copied from interface:TypeStrategyTranslate raw byte array into a value. This is primarily useful for transforming self contained values that are serialized into byte arrays, such as happens with 'COMPLEX' types which serialize to base64 strings in JSON responses. 'COMPLEX' types should implement this method to participate in the expression systems built-in function to deserialize base64 encoded values,BuiltInExprMacros.ComplexDecodeBase64ExprMacro.- Specified by:
fromBytesin interfaceTypeStrategy<T>
-
groupable
public boolean groupable()
Description copied from interface:TypeStrategyWhether the type is groupable or not. This is always true for all the primitive types, arrays, and nested arrays therefore the SQL and the native layer might ignore this flag for those types. For complex types, this flag can be true or false, depending on whether the semantics and implementation of the type naturally leads to groupability or not. For example, it makes sense for JSON columns to be groupable, however there is little sense in grouping sketches (before finalizing).If a type is groupable, following statements MUST hold:
a.
TypeStrategy.equals(Object, Object)must be implemented. It should return true if and only if two objects are equal and can be grouped together.b.
TypeStrategy.hashCode(Object)must be implemented, and must be consistent with equals. It should return a hashCode for the given object. For two objects that are equal, it must return the same hash value. For two objects that are not equal, it can return the same hash value (or not). A conscious effort must be made to minimise collisions between the hash values of two non-equal objects for faster grouping.c.
Comparator.compare(Object, Object)must be consistent with equals. Apart from abiding by the definition ofComparator.compare(T, T), it must not return 0 for two objects that are not equals, and converse must also hold, i.e. if the value returned by compare is not zero, then the arguments must not be equal.- Specified by:
groupablein interfaceTypeStrategy<T>
-
hashCode
public int hashCode(T o)
- Specified by:
hashCodein interfaceit.unimi.dsi.fastutil.Hash.Strategy<T>- Specified by:
hashCodein interfaceTypeStrategy<T>- See Also:
TypeStrategy.groupable()
-
equals
public boolean equals(T a, T b)
- Specified by:
equalsin interfaceit.unimi.dsi.fastutil.Hash.Strategy<T>- Specified by:
equalsin interfaceTypeStrategy<T>- See Also:
TypeStrategy.groupable()
-
-