Package org.apache.cassandra.db
Class DecoratedKey
java.lang.Object
org.apache.cassandra.db.DecoratedKey
- All Implemented Interfaces:
Comparable<PartitionPosition>,PartitionPosition,RingPosition<PartitionPosition>,ByteComparable,IFilter.FilterKey
- Direct Known Subclasses:
BufferDecoratedKey,NativeDecoratedKey
Represents a decorated key, handy for certain operations
where just working with strings gets slow.
We do a lot of sorting of DecoratedKeys, so for speed, we assume that tokens correspond one-to-one with keys.
This is not quite correct in the case of RandomPartitioner (which uses MD5 to hash keys to tokens);
if this matters, you can subclass RP to use a stronger hash, or use a non-lossy tokenization scheme (as in the
OrderPreservingPartitioner classes).
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.cassandra.utils.bytecomparable.ByteComparable
ByteComparable.VersionNested classes/interfaces inherited from interface org.apache.cassandra.db.PartitionPosition
PartitionPosition.ForKey, PartitionPosition.Kind, PartitionPosition.RowPositionSerializer -
Field Summary
FieldsFields inherited from interface org.apache.cassandra.utils.bytecomparable.ByteComparable
EMPTYFields inherited from interface org.apache.cassandra.db.PartitionPosition
serializer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasComparableBound(boolean before) Produce a byte-comparable representation for the position before or after the key.asComparableBytes(ByteComparable.Version version) Produce a prefix-free byte-comparable representation of the key, i.e.intstatic intcompareTo(IPartitioner partitioner, ByteBuffer key, PartitionPosition position) booleanvoidfilterHash(long[] dest) Places the murmur3 hash of the key in the given long array of size at least two.abstract ByteBuffergetKey()abstract intgetToken()inthashCode()booleanprotected ByteSourcekeyComparableBytes(ByteComparable.Version version) static byte[]keyFromByteSource(ByteSource.Peekable peekableByteSource, ByteComparable.Version version, IPartitioner partitioner) kind()minValue()If this key occupies only part of a larger buffer, allocate a new buffer that is only as large as necessary.toCQLString(TableMetadata metadata) Returns a CQL representation of this key.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.cassandra.utils.bytecomparable.ByteComparable
byteComparableAsStringMethods inherited from interface org.apache.cassandra.utils.IFilter.FilterKey
filterHashLowerBits
-
Field Details
-
comparator
-
-
Constructor Details
-
DecoratedKey
-
-
Method Details
-
hashCode
public int hashCode() -
equals
-
compareTo
- Specified by:
compareToin interfaceComparable<PartitionPosition>
-
compareTo
-
asComparableBytes
Description copied from interface:PartitionPositionProduce a prefix-free byte-comparable representation of the key, i.e. such a sequence of bytes that any pair x, y of valid positions (with the same key column types and partitioner), x.compareTo(y) == compareLexicographicallyUnsigned(x.asComparableBytes(), y.asComparableBytes()) and x.asComparableBytes() is not a prefix of y.asComparableBytes() We use a two-component tuple for decorated keys, and a one-component tuple for key bounds, where the terminator byte is chosen to yield the correct comparison result. No decorated key can be a prefix of another (per the tuple encoding), and no key bound can be a prefix of one because it uses a terminator byte that is different from the tuple separator.- Specified by:
asComparableBytesin interfaceByteComparable- Specified by:
asComparableBytesin interfacePartitionPosition
-
asComparableBound
Description copied from interface:PartitionPositionProduce a byte-comparable representation for the position before or after the key. This does nothing for token boundaries (which are already at a position between valid keys), and changes the terminator byte for keys.- Specified by:
asComparableBoundin interfacePartitionPosition
-
keyComparableBytes
-
getPartitioner
- Specified by:
getPartitionerin interfaceRingPosition<PartitionPosition>
-
minValue
- Specified by:
minValuein interfaceRingPosition<PartitionPosition>
-
isMinimum
public boolean isMinimum()- Specified by:
isMinimumin interfacePartitionPosition- Specified by:
isMinimumin interfaceRingPosition<PartitionPosition>
-
kind
- Specified by:
kindin interfacePartitionPosition
-
toString
-
toCQLString
Returns a CQL representation of this key.- Parameters:
metadata- the metadata of the table that this key belogs to- Returns:
- a CQL representation of this key
-
getToken
- Specified by:
getTokenin interfaceRingPosition<PartitionPosition>
-
getKey
-
getKeyLength
public abstract int getKeyLength() -
retainable
If this key occupies only part of a larger buffer, allocate a new buffer that is only as large as necessary. Otherwise, it returns this key. -
filterHash
public void filterHash(long[] dest) Description copied from interface:IFilter.FilterKeyPlaces the murmur3 hash of the key in the given long array of size at least two.- Specified by:
filterHashin interfaceIFilter.FilterKey
-
keyFromByteSource
public static byte[] keyFromByteSource(ByteSource.Peekable peekableByteSource, ByteComparable.Version version, IPartitioner partitioner)
-