Package org.apache.cassandra.db
Class DecoratedKey
- java.lang.Object
-
- org.apache.cassandra.db.DecoratedKey
-
- All Implemented Interfaces:
java.lang.Comparable<PartitionPosition>
,PartitionPosition
,RingPosition<PartitionPosition>
,ByteComparable
,IFilter.FilterKey
- Direct Known Subclasses:
BufferDecoratedKey
,NativeDecoratedKey
public abstract class DecoratedKey extends java.lang.Object implements PartitionPosition, IFilter.FilterKey
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.Version
-
Nested classes/interfaces inherited from interface org.apache.cassandra.db.PartitionPosition
PartitionPosition.ForKey, PartitionPosition.Kind, PartitionPosition.RowPositionSerializer
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Comparator<DecoratedKey>
comparator
-
Fields inherited from interface org.apache.cassandra.utils.bytecomparable.ByteComparable
EMPTY
-
Fields inherited from interface org.apache.cassandra.db.PartitionPosition
serializer
-
-
Constructor Summary
Constructors Constructor Description DecoratedKey(Token token)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ByteComparable
asComparableBound(boolean before)
Produce a byte-comparable representation for the position before or after the key.ByteSource
asComparableBytes(ByteComparable.Version version)
Produce a prefix-free byte-comparable representation of the key, i.e.int
compareTo(PartitionPosition pos)
static int
compareTo(IPartitioner partitioner, java.nio.ByteBuffer key, PartitionPosition position)
boolean
equals(java.lang.Object obj)
void
filterHash(long[] dest)
Places the murmur3 hash of the key in the given long array of size at least two.abstract java.nio.ByteBuffer
getKey()
abstract int
getKeyLength()
IPartitioner
getPartitioner()
Token
getToken()
int
hashCode()
boolean
isMinimum()
protected ByteSource
keyComparableBytes(ByteComparable.Version version)
static byte[]
keyFromByteSource(ByteSource.Peekable peekableByteSource, ByteComparable.Version version, IPartitioner partitioner)
PartitionPosition.Kind
kind()
Token.KeyBound
minValue()
DecoratedKey
retainable()
If this key occupies only part of a larger buffer, allocate a new buffer that is only as large as necessary.java.lang.String
toCQLString(TableMetadata metadata)
Returns a CQL representation of this key.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.utils.bytecomparable.ByteComparable
byteComparableAsString
-
Methods inherited from interface org.apache.cassandra.utils.IFilter.FilterKey
filterHashLowerBits
-
-
-
-
Field Detail
-
comparator
public static final java.util.Comparator<DecoratedKey> comparator
-
-
Constructor Detail
-
DecoratedKey
public DecoratedKey(Token token)
-
-
Method Detail
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
compareTo
public int compareTo(PartitionPosition pos)
- Specified by:
compareTo
in interfacejava.lang.Comparable<PartitionPosition>
-
compareTo
public static int compareTo(IPartitioner partitioner, java.nio.ByteBuffer key, PartitionPosition position)
-
asComparableBytes
public ByteSource asComparableBytes(ByteComparable.Version version)
Description copied from interface:PartitionPosition
Produce 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:
asComparableBytes
in interfaceByteComparable
- Specified by:
asComparableBytes
in interfacePartitionPosition
-
asComparableBound
public ByteComparable asComparableBound(boolean before)
Description copied from interface:PartitionPosition
Produce 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:
asComparableBound
in interfacePartitionPosition
-
keyComparableBytes
protected ByteSource keyComparableBytes(ByteComparable.Version version)
-
getPartitioner
public IPartitioner getPartitioner()
- Specified by:
getPartitioner
in interfaceRingPosition<PartitionPosition>
-
minValue
public Token.KeyBound minValue()
- Specified by:
minValue
in interfaceRingPosition<PartitionPosition>
-
isMinimum
public boolean isMinimum()
- Specified by:
isMinimum
in interfacePartitionPosition
- Specified by:
isMinimum
in interfaceRingPosition<PartitionPosition>
-
kind
public PartitionPosition.Kind kind()
- Specified by:
kind
in interfacePartitionPosition
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toCQLString
public java.lang.String toCQLString(TableMetadata metadata)
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
public Token getToken()
- Specified by:
getToken
in interfaceRingPosition<PartitionPosition>
-
getKey
public abstract java.nio.ByteBuffer getKey()
-
getKeyLength
public abstract int getKeyLength()
-
retainable
public DecoratedKey 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.FilterKey
Places the murmur3 hash of the key in the given long array of size at least two.- Specified by:
filterHash
in interfaceIFilter.FilterKey
-
keyFromByteSource
public static byte[] keyFromByteSource(ByteSource.Peekable peekableByteSource, ByteComparable.Version version, IPartitioner partitioner)
-
-