Package org.apache.cassandra.db
Class ClusteringComparator
- java.lang.Object
-
- org.apache.cassandra.db.ClusteringComparator
-
- All Implemented Interfaces:
java.util.Comparator<Clusterable>
public class ClusteringComparator extends java.lang.Object implements java.util.Comparator<Clusterable>
A comparator of clustering prefixes (or more generally ofClusterable
}.This is essentially just a composite comparator that the clustering values of the provided clustering prefixes in lexicographical order, with each component being compared based on the type of the clustering column this is a value of.
-
-
Constructor Summary
Constructors Constructor Description ClusteringComparator(java.lang.Iterable<AbstractType<?>> clusteringTypes)
ClusteringComparator(AbstractType<?>... clusteringTypes)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <V> ByteComparable
asByteComparable(ClusteringPrefix<V> clustering)
Produce a prefix-free byte-comparable representation of the given value, i.e.<V> ClusteringBoundary<V>
boundaryFromByteComparable(ValueAccessor<V> accessor, ByteComparable comparable)
Produces a clustering boundary from the given byte-comparable value.<V> ClusteringBound<V>
boundFromByteComparable(ValueAccessor<V> accessor, ByteComparable comparable, boolean isEnd)
Produces a clustering bound from the given byte-comparable value.<V> Clustering<V>
clusteringFromByteComparable(ValueAccessor<V> accessor, ByteComparable comparable)
Produces a clustering from the given byte-comparable value.int
compare(Clusterable c1, Clusterable c2)
<V1,V2>
intcompare(Clustering<V1> c1, Clustering<V2> c2)
<V1,V2>
intcompare(Clustering<V1> c1, Clustering<V2> c2, int size)
Compares the specified part of the specified clusterings.<V1,V2>
intcompare(ClusteringPrefix<V1> c1, ClusteringPrefix<V2> c2)
<V1,V2>
intcompareComponent(int i, ClusteringPrefix<V1> v1, ClusteringPrefix<V2> v2)
<V1,V2>
intcompareComponent(int i, V1 v1, ValueAccessor<V1> accessor1, V2 v2, ValueAccessor<V2> accessor2)
boolean
equals(java.lang.Object o)
int
hashCode()
java.util.Comparator<IndexInfo>
indexComparator(boolean reversed)
boolean
isCompatibleWith(ClusteringComparator previous)
Returns whether this clustering comparator is compatible with the provided one, that is if the provided one can be safely replaced by this new one.Clustering<?>
make(java.lang.Object... values)
Creates a row clustering based on the clustering values.java.util.Comparator<Clusterable>
reversed()
java.util.Comparator<Row>
rowComparator()
A comparator for rows.int
size()
The number of clustering columns for the table this is the comparator of.AbstractType<?>
subtype(int i)
Returns the type of the ith clustering column of the table.java.util.List<AbstractType<?>>
subtypes()
The "subtypes" of this clustering comparator, that is the types of the clustering columns for the table this is a comparator of.java.lang.String
toString()
<T> void
validate(ClusteringPrefix<T> clustering)
Validates the provided prefix for corrupted data.
-
-
-
Constructor Detail
-
ClusteringComparator
public ClusteringComparator(AbstractType<?>... clusteringTypes)
-
ClusteringComparator
public ClusteringComparator(java.lang.Iterable<AbstractType<?>> clusteringTypes)
-
-
Method Detail
-
size
public int size()
The number of clustering columns for the table this is the comparator of.
-
subtypes
public java.util.List<AbstractType<?>> subtypes()
The "subtypes" of this clustering comparator, that is the types of the clustering columns for the table this is a comparator of.
-
subtype
public AbstractType<?> subtype(int i)
Returns the type of the ith clustering column of the table.
-
make
public Clustering<?> make(java.lang.Object... values)
Creates a row clustering based on the clustering values.Every argument can either be a
ByteBuffer
, in which case it is used as-is, or a object corresponding to the type of the corresponding clustering column, in which case it will be converted to a byte buffer using the column type.- Parameters:
values
- the values to use for the created clustering. There should be exactlysize()
values which must be either byte buffers or of the type the column expect.- Returns:
- the newly created clustering.
-
compare
public int compare(Clusterable c1, Clusterable c2)
- Specified by:
compare
in interfacejava.util.Comparator<Clusterable>
-
compare
public <V1,V2> int compare(ClusteringPrefix<V1> c1, ClusteringPrefix<V2> c2)
-
compare
public <V1,V2> int compare(Clustering<V1> c1, Clustering<V2> c2)
-
compare
public <V1,V2> int compare(Clustering<V1> c1, Clustering<V2> c2, int size)
Compares the specified part of the specified clusterings.- Parameters:
c1
- the first clusteringc2
- the second clusteringsize
- the number of components to compare- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
-
compareComponent
public <V1,V2> int compareComponent(int i, V1 v1, ValueAccessor<V1> accessor1, V2 v2, ValueAccessor<V2> accessor2)
-
compareComponent
public <V1,V2> int compareComponent(int i, ClusteringPrefix<V1> v1, ClusteringPrefix<V2> v2)
-
isCompatibleWith
public boolean isCompatibleWith(ClusteringComparator previous)
Returns whether this clustering comparator is compatible with the provided one, that is if the provided one can be safely replaced by this new one.- Parameters:
previous
- the previous comparator that we want to replace and test compatibility with.- Returns:
- whether
previous
can be safely replaced by this comparator.
-
validate
public <T> void validate(ClusteringPrefix<T> clustering)
Validates the provided prefix for corrupted data.- Parameters:
clustering
- the clustering prefix to validate.- Throws:
MarshalException
- ifclustering
contains some invalid data.
-
asByteComparable
public <V> ByteComparable asByteComparable(ClusteringPrefix<V> clustering)
Produce a prefix-free byte-comparable representation of the given value, i.e. such a sequence of bytes that any pair x, y of valid values of this type compare(x, y) == compareLexicographicallyUnsigned(asByteComparable(x), asByteComparable(y)) and asByteComparable(x) is not a prefix of asByteComparable(y)
-
clusteringFromByteComparable
public <V> Clustering<V> clusteringFromByteComparable(ValueAccessor<V> accessor, ByteComparable comparable)
Produces a clustering from the given byte-comparable value. The method will throw an exception if the value does not correctly encode a clustering of this type, including if it encodes a position before or after a clustering (i.e. a bound/boundary).- Parameters:
accessor
- Accessor to use to construct components.comparable
- The clustering encoded as a byte-comparable sequence.
-
boundFromByteComparable
public <V> ClusteringBound<V> boundFromByteComparable(ValueAccessor<V> accessor, ByteComparable comparable, boolean isEnd)
Produces a clustering bound from the given byte-comparable value. The method will throw an exception if the value does not correctly encode a bound position of this type, including if it encodes an exact clustering. Note that the encoded clustering position cannot specify the type of bound (i.e. start/end/boundary) because to correctly compare clustering positions the encoding must be the same for the different types (e.g. the position for a exclusive end and an inclusive start is the same, before the exact clustering). The type must be supplied separately (in the bound... vs boundary... call and isEnd argument).- Parameters:
accessor
- Accessor to use to construct components.comparable
- The clustering position encoded as a byte-comparable sequence.isEnd
- true if the bound marks the end of a range, false is it marks the start.
-
boundaryFromByteComparable
public <V> ClusteringBoundary<V> boundaryFromByteComparable(ValueAccessor<V> accessor, ByteComparable comparable)
Produces a clustering boundary from the given byte-comparable value. The method will throw an exception if the value does not correctly encode a bound position of this type, including if it encodes an exact clustering. Note that the encoded clustering position cannot specify the type of bound (i.e. start/end/boundary) because to correctly compare clustering positions the encoding must be the same for the different types (e.g. the position for a exclusive end and an inclusive start is the same, before the exact clustering). The type must be supplied separately (in the bound... vs boundary... call and isEnd argument).- Parameters:
accessor
- Accessor to use to construct components.comparable
- The clustering position encoded as a byte-comparable sequence.
-
rowComparator
public java.util.Comparator<Row> rowComparator()
A comparator for rows. ARow
is aClusterable
soClusteringComparator
can be used to compare rows directly, but when we know we deal with rows (and notClusterable
in general), this is a little faster because by knowing we compareClustering
objects, we know that 1) they all have the same size and 2) they all have the same kind.
-
indexComparator
public java.util.Comparator<IndexInfo> indexComparator(boolean reversed)
-
reversed
public java.util.Comparator<Clusterable> reversed()
- Specified by:
reversed
in interfacejava.util.Comparator<Clusterable>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equals
in interfacejava.util.Comparator<Clusterable>
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-