Package org.apache.druid.segment.column
Class TypeStrategies.LongTypeStrategy
- java.lang.Object
-
- org.apache.druid.segment.column.TypeStrategies.LongTypeStrategy
-
- All Implemented Interfaces:
Comparator<Object>
,TypeStrategy<Long>
- Enclosing class:
- TypeStrategies
public static final class TypeStrategies.LongTypeStrategy extends Object implements TypeStrategy<Long>
Read and write non-null LONG values. If reading non-null values, consider just usingByteBuffer.getLong()
directly, or if reading values written withNullableTypeStrategy
, usingTypeStrategies.isNullableNull(java.nio.ByteBuffer, int)
andTypeStrategies.readNotNullNullableLong(java.nio.ByteBuffer, int)
, both of which allow dealing in primitive long values instead of objects.
-
-
Constructor Summary
Constructors Constructor Description LongTypeStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(Object o1, Object o2)
int
estimateSizeBytes(Long value)
Estimate the size in bytes that writing this value to memory would require.Long
read(ByteBuffer buffer)
Read a non-null value from theByteBuffer
at the currentBuffer.position()
.Long
read(ByteBuffer buffer, int offset)
Read a non-null value from theByteBuffer
at the requested position.boolean
readRetainsBufferReference()
Whether theTypeStrategy.read(java.nio.ByteBuffer)
methods return an object that may retain a reference to the providedByteBuffer
.int
write(ByteBuffer buffer, Long value, int maxSizeBytes)
Write a non-null value to theByteBuffer
at 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
fromBytes, write
-
-
-
-
Method Detail
-
estimateSizeBytes
public int estimateSizeBytes(Long value)
Description copied from interface:TypeStrategy
Estimate 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:
estimateSizeBytes
in interfaceTypeStrategy<Long>
-
read
public Long read(ByteBuffer buffer)
Description copied from interface:TypeStrategy
Read a non-null value from theByteBuffer
at 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:
read
in interfaceTypeStrategy<Long>
-
read
public Long read(ByteBuffer buffer, int offset)
Description copied from interface:TypeStrategy
Read a non-null value from theByteBuffer
at the requested position. This will not permanently move the underlyingBuffer.position()
, but may temporarily modify the buffer position during reading so cannot be considered thread safe usage of the buffer. The contract of this method is that any value returned from this method MUST be completely detached from the underlyingByteBuffer
, since it might outlive the memory location being allocated to hold the object. In other words, if an object is memory mapped, it must be copied on heap, or relocated to another memory location that is owned by the caller withTypeStrategy.write(java.nio.ByteBuffer, T, int)
.- Specified by:
read
in interfaceTypeStrategy<Long>
-
readRetainsBufferReference
public boolean readRetainsBufferReference()
Description copied from interface:TypeStrategy
Whether 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:
readRetainsBufferReference
in interfaceTypeStrategy<Long>
-
write
public int write(ByteBuffer buffer, Long value, int maxSizeBytes)
Description copied from interface:TypeStrategy
Write a non-null value to theByteBuffer
at 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:
write
in interfaceTypeStrategy<Long>
- Returns:
- number of bytes written
-
compare
public int compare(Object o1, Object o2)
- Specified by:
compare
in interfaceComparator<Object>
-
-