Package org.apache.cassandra.db
Class DataRange
- java.lang.Object
-
- org.apache.cassandra.db.DataRange
-
- Direct Known Subclasses:
DataRange.Paging
public class DataRange extends java.lang.Object
Groups both the range of partitions to query, and the clustering index filter to apply for each partition (for a (partition) range query).The main "trick" is that the clustering index filter can only be obtained by providing the partition key on which the filter will be applied. This is necessary when paging range queries, as we might need a different filter for the starting key than for other keys (because the previous page we had queried may have ended in the middle of a partition).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataRange.Paging
SpecializedDataRange
used for the paging case.static class
DataRange.Serializer
-
Field Summary
Fields Modifier and Type Field Description protected ClusteringIndexFilter
clusteringIndexFilter
protected AbstractBounds<PartitionPosition>
keyRange
static DataRange.Serializer
serializer
-
Constructor Summary
Constructors Constructor Description DataRange(AbstractBounds<PartitionPosition> range, ClusteringIndexFilter clusteringIndexFilter)
Creates aDataRange
given a range of partition keys and a clustering index filter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DataRange
allData(IPartitioner partitioner)
Creates aDataRange
to query all data (over the whole ring).static DataRange
allData(IPartitioner partitioner, ClusteringIndexFilter filter)
Creates aDataRange
to query all partitions of the ring using the provided clustering index filter.static void
appendKeyString(java.lang.StringBuilder sb, AbstractType<?> type, java.nio.ByteBuffer key)
ClusteringIndexFilter
clusteringIndexFilter(DecoratedKey key)
The clustering index filter to use for the provided key.boolean
contains(PartitionPosition pos)
Whether the provided ring position is covered by thisDataRange
.static DataRange
forKeyRange(Range<PartitionPosition> keyRange)
Creates aDataRange
to query all rows over the provided key range.DataRange
forPaging(AbstractBounds<PartitionPosition> range, ClusteringComparator comparator, Clustering<?> lastReturned, boolean inclusive)
Returns a newDataRange
for use when pagingthis
range.DataRange
forSubRange(AbstractBounds<PartitionPosition> range)
Returns a newDataRange
equivalent tothis
one but restricted to the provided sub-range.static DataRange
forTokenRange(Range<Token> tokenRange)
Creates aDataRange
to query all rows over the provided token range.boolean
isNamesQuery()
Whether the underlying clustering index filter is a names filter or not.boolean
isPaging()
Whether the data range is for a paged request or not.boolean
isReversed()
Whether the underlyingClusteringIndexFilter
is reversed or not.boolean
isUnrestricted(TableMetadata metadata)
Whether thisDataRange
queries everything (has no restriction neither on the partition queried, nor within the queried partition).boolean
isWrapAround()
Whether the range queried by thisDataRange
actually wraps around.AbstractBounds<PartitionPosition>
keyRange()
The range of partition key queried by thisDataRange
.boolean
selectsAllPartition()
ByteComparable
startAsByteComparable()
The start of the partition key range queried by thisDataRange
.PartitionPosition
startKey()
The start of the partition key range queried by thisDataRange
.ByteComparable
stopAsByteComparable()
The end of the partition key range queried by thisDataRange
.PartitionPosition
stopKey()
The end of the partition key range queried by thisDataRange
.java.lang.String
toCQLString(TableMetadata metadata, RowFilter rowFilter)
java.lang.String
toString(TableMetadata metadata)
-
-
-
Field Detail
-
serializer
public static final DataRange.Serializer serializer
-
keyRange
protected final AbstractBounds<PartitionPosition> keyRange
-
clusteringIndexFilter
protected final ClusteringIndexFilter clusteringIndexFilter
-
-
Constructor Detail
-
DataRange
public DataRange(AbstractBounds<PartitionPosition> range, ClusteringIndexFilter clusteringIndexFilter)
Creates aDataRange
given a range of partition keys and a clustering index filter. The returnDataRange
will return the same filter for all keys.- Parameters:
range
- the range over partition keys to use.clusteringIndexFilter
- the clustering index filter to use.
-
-
Method Detail
-
allData
public static DataRange allData(IPartitioner partitioner)
Creates aDataRange
to query all data (over the whole ring).- Parameters:
partitioner
- the partitioner in use for the table.- Returns:
- the newly create
DataRange
.
-
forTokenRange
public static DataRange forTokenRange(Range<Token> tokenRange)
Creates aDataRange
to query all rows over the provided token range.- Parameters:
tokenRange
- the (partition key) token range to query.- Returns:
- the newly create
DataRange
.
-
forKeyRange
public static DataRange forKeyRange(Range<PartitionPosition> keyRange)
Creates aDataRange
to query all rows over the provided key range.- Parameters:
keyRange
- the (partition key) range to query.- Returns:
- the newly create
DataRange
.
-
allData
public static DataRange allData(IPartitioner partitioner, ClusteringIndexFilter filter)
Creates aDataRange
to query all partitions of the ring using the provided clustering index filter.- Parameters:
partitioner
- the partitioner in use for the table queried.filter
- the clustering index filter to use.- Returns:
- the newly create
DataRange
.
-
keyRange
public AbstractBounds<PartitionPosition> keyRange()
The range of partition key queried by thisDataRange
.- Returns:
- the range of partition key queried by this
DataRange
.
-
startKey
public PartitionPosition startKey()
The start of the partition key range queried by thisDataRange
.- Returns:
- the start of the partition key range queried by this
DataRange
.
-
stopKey
public PartitionPosition stopKey()
The end of the partition key range queried by thisDataRange
.- Returns:
- the end of the partition key range queried by this
DataRange
.
-
startAsByteComparable
public ByteComparable startAsByteComparable()
The start of the partition key range queried by thisDataRange
.- Returns:
- the start of the partition key range expressed as a ByteComparable.
-
stopAsByteComparable
public ByteComparable stopAsByteComparable()
The end of the partition key range queried by thisDataRange
.- Returns:
- the end of the partition key range expressed as a ByteComparable.
-
isNamesQuery
public boolean isNamesQuery()
Whether the underlying clustering index filter is a names filter or not.- Returns:
- Whether the underlying clustering index filter is a names filter or not.
-
isPaging
public boolean isPaging()
Whether the data range is for a paged request or not.- Returns:
- true if for paging, false otherwise
-
isWrapAround
public boolean isWrapAround()
Whether the range queried by thisDataRange
actually wraps around.- Returns:
- whether the range queried by this
DataRange
actually wraps around.
-
contains
public boolean contains(PartitionPosition pos)
Whether the provided ring position is covered by thisDataRange
.- Returns:
- whether the provided ring position is covered by this
DataRange
.
-
isUnrestricted
public boolean isUnrestricted(TableMetadata metadata)
Whether thisDataRange
queries everything (has no restriction neither on the partition queried, nor within the queried partition).- Returns:
- Whether this
DataRange
queries everything.
-
selectsAllPartition
public boolean selectsAllPartition()
-
isReversed
public boolean isReversed()
Whether the underlyingClusteringIndexFilter
is reversed or not.- Returns:
- whether the underlying
ClusteringIndexFilter
is reversed or not.
-
clusteringIndexFilter
public ClusteringIndexFilter clusteringIndexFilter(DecoratedKey key)
The clustering index filter to use for the provided key.This may or may not be the same filter for all keys (that is, paging range use a different filter for their start key).
- Parameters:
key
- the partition key for which we want the clustering index filter.- Returns:
- the clustering filter to use for
key
.
-
forPaging
public DataRange forPaging(AbstractBounds<PartitionPosition> range, ClusteringComparator comparator, Clustering<?> lastReturned, boolean inclusive)
Returns a newDataRange
for use when pagingthis
range.- Parameters:
range
- the range of partition keys to query.comparator
- the comparator for the table queried.lastReturned
- the clustering for the last result returned by the previous page, i.e. the result we want to start our new page from. This last returned must correspond to left bound ofrange
(in other words,range.left
must be the partition key for thatlastReturned
result).inclusive
- whether or not we want to include thelastReturned
in the newly returned page of results.- Returns:
- a new
DataRange
suitable for pagingthis
range given thelastRetuned
result of the previous page.
-
forSubRange
public DataRange forSubRange(AbstractBounds<PartitionPosition> range)
Returns a newDataRange
equivalent tothis
one but restricted to the provided sub-range.- Parameters:
range
- the sub-range to use for the newly returned data range. Note that assumes thatrange
is a proper sub-range of the initial range but doesn't validate it. You should make sure to only provided sub-ranges however or this might throw off the paging case (see Paging.forSubRange()).- Returns:
- a new
DataRange
usingrange
as partition key range and the clustering index filter filter fromthis
.
-
toString
public java.lang.String toString(TableMetadata metadata)
-
toCQLString
public java.lang.String toCQLString(TableMetadata metadata, RowFilter rowFilter)
-
appendKeyString
public static void appendKeyString(java.lang.StringBuilder sb, AbstractType<?> type, java.nio.ByteBuffer key)
-
-