Class SinglePartitionReadCommand
- java.lang.Object
-
- org.apache.cassandra.db.monitoring.MonitorableImpl
-
- org.apache.cassandra.db.ReadCommand
-
- org.apache.cassandra.db.SinglePartitionReadCommand
-
- All Implemented Interfaces:
Monitorable
,ReadQuery
,SinglePartitionReadQuery
- Direct Known Subclasses:
SinglePartitionReadCommand.VirtualTableSinglePartitionReadCommand
public class SinglePartitionReadCommand extends ReadCommand implements SinglePartitionReadQuery
A read command that selects a (part of a) single partition.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SinglePartitionReadCommand.Group
Groups multiple single partition read commands.static class
SinglePartitionReadCommand.VirtualTableGroup
static class
SinglePartitionReadCommand.VirtualTableSinglePartitionReadCommand
-
Nested classes/interfaces inherited from class org.apache.cassandra.db.ReadCommand
ReadCommand.Kind, ReadCommand.SelectionDeserializer, ReadCommand.Serializer
-
-
Field Summary
Fields Modifier and Type Field Description protected ClusteringIndexFilter
clusteringIndexFilter
protected DecoratedKey
partitionKey
protected static ReadCommand.SelectionDeserializer
selectionDeserializer
-
Fields inherited from class org.apache.cassandra.db.ReadCommand
logger, serializer
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SinglePartitionReadCommand(boolean isDigest, int digestVersion, boolean acceptsTransient, TableMetadata metadata, long nowInSec, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits, DecoratedKey partitionKey, ClusteringIndexFilter clusteringIndexFilter, Index.QueryPlan indexQueryPlan, boolean trackWarnings)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
appendCQLWhereClause(java.lang.StringBuilder sb)
ClusteringIndexFilter
clusteringIndexFilter()
ClusteringIndexFilter
clusteringIndexFilter(DecoratedKey key)
The clustering index filter this command to use for the provided key.ColumnFilter
columnFilter()
A filter on which (non-PK) columns must be returned by the query.SinglePartitionReadCommand
copy()
Returns a copy of this command.protected SinglePartitionReadCommand
copyAsDigestQuery()
protected SinglePartitionReadCommand
copyAsTransientQuery()
static SinglePartitionReadCommand
create(TableMetadata metadata, long nowInSec, java.nio.ByteBuffer key, Slices slices)
Creates a new single partition slice command for the provided slices.static SinglePartitionReadCommand
create(TableMetadata metadata, long nowInSec, DecoratedKey key, java.util.NavigableSet<Clustering<?>> names)
Creates a new single partition name command for the provided rows.static SinglePartitionReadCommand
create(TableMetadata metadata, long nowInSec, DecoratedKey key, Clustering<?> name)
Creates a new single partition name command for the provided row.static SinglePartitionReadCommand
create(TableMetadata metadata, long nowInSec, DecoratedKey key, ColumnFilter columnFilter, ClusteringIndexFilter filter)
Creates a new read command on a single partition.static SinglePartitionReadCommand
create(TableMetadata metadata, long nowInSec, DecoratedKey key, Slice slice)
Creates a new single partition slice command for the provided single slice.static SinglePartitionReadCommand
create(TableMetadata metadata, long nowInSec, DecoratedKey key, Slices slices)
Creates a new single partition slice command for the provided slices.static SinglePartitionReadCommand
create(TableMetadata metadata, long nowInSec, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits, DecoratedKey partitionKey, ClusteringIndexFilter clusteringIndexFilter)
Creates a new read command on a single partition.static SinglePartitionReadCommand
create(TableMetadata metadata, long nowInSec, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits, DecoratedKey partitionKey, ClusteringIndexFilter clusteringIndexFilter, Index.QueryPlan indexQueryPlan)
Creates a new read command on a single partition.PartitionIterator
execute(ConsistencyLevel consistency, ClientState state, Dispatcher.RequestTime requestTime)
Executes the query at the provided consistency level.PartitionIterator
executeInternal(ReadExecutionController controller)
Execute the query for internal queries (that is, it basically executes the query locally).SinglePartitionReadCommand
forPaging(Clustering<?> lastReturned, DataLimits limits)
Returns a newSinglePartitionReadQuery
suitable to paging from the last returned row.static SinglePartitionReadCommand
fullPartitionRead(TableMetadata metadata, long nowInSec, java.nio.ByteBuffer key)
Creates a new read command that queries a single partition in its entirety.static SinglePartitionReadCommand
fullPartitionRead(TableMetadata metadata, long nowInSec, DecoratedKey key)
Creates a new read command that queries a single partition in its entirety.long
getTimeout(java.util.concurrent.TimeUnit unit)
The configured timeout for this command.protected boolean
intersects(SSTableReader sstable)
boolean
isLimitedToOnePartition()
boolean
isRangeRequest()
boolean
isReversed()
Whether the underlyingClusteringIndexFilter
is reversed or not.DataLimits
limits()
The limits for the query.java.lang.String
loggableTokens()
Return the queried token(s) for loggingTableMetadata
metadata()
The metadata for the table this is a query on.long
nowInSec()
The time in seconds to use as "now" for this query.DecoratedKey
partitionKey()
Returns the key of the partition queried by thisReadQuery
UnfilteredRowIterator
queryMemtableAndDisk(ColumnFamilyStore cfs, ReadExecutionController executionController)
Queries both memtable and sstables to fetch the result of this query.protected UnfilteredPartitionIterator
queryStorage(ColumnFamilyStore cfs, ReadExecutionController executionController)
protected void
recordLatency(TableMetrics metric, long latencyNanos)
RowFilter
rowFilter()
Filters/Resrictions on CQL rows.protected long
selectionSerializedSize(int version)
boolean
selectsFullPartition()
Checks if thisReadQuery
selects full partitions, that is it has no filtering on clustering or regular columns.protected void
serializeSelection(DataOutputPlus out, int version)
java.lang.String
toCQLString()
Recreate the CQL string corresponding to this query.java.lang.String
toString()
Verb
verb()
SinglePartitionReadCommand
withUpdatedLimit(DataLimits newLimits)
Creates a newReadCommand
instance with new limits.-
Methods inherited from class org.apache.cassandra.db.ReadCommand
acceptsTransient, copyAsDigestQuery, copyAsDigestQuery, copyAsTransientQuery, copyAsTransientQuery, createEmptyResponse, createMessage, createResponse, digestVersion, executeLocally, executionController, executionController, getCommand, hasPartitionLevelDeletions, hasRequiredStatics, indexQueryPlan, indexSearcher, isDigestQuery, isSinglePartitionRead, isTopK, isTrackingWarnings, maybeValidateIndex, name, setDigestVersion, trackWarnings, withoutPurgeableTombstones
-
Methods inherited from class org.apache.cassandra.db.monitoring.MonitorableImpl
abort, complete, creationTimeNanos, isAborted, isCompleted, isCrossNode, isInProgress, isSlow, setMonitoringTime, slowTimeoutNanos, timeoutNanos
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.db.ReadQuery
columnFilter, executeInternal, executeLocally, executionController, isEmpty, isTopK, limits, maybeValidateIndex, metadata, nowInSec, rowFilter, trackWarnings
-
Methods inherited from interface org.apache.cassandra.db.SinglePartitionReadQuery
getPager, selectsClustering, selectsKey
-
-
-
-
Field Detail
-
selectionDeserializer
protected static final ReadCommand.SelectionDeserializer selectionDeserializer
-
partitionKey
protected final DecoratedKey partitionKey
-
clusteringIndexFilter
protected final ClusteringIndexFilter clusteringIndexFilter
-
-
Constructor Detail
-
SinglePartitionReadCommand
protected SinglePartitionReadCommand(boolean isDigest, int digestVersion, boolean acceptsTransient, TableMetadata metadata, long nowInSec, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits, DecoratedKey partitionKey, ClusteringIndexFilter clusteringIndexFilter, Index.QueryPlan indexQueryPlan, boolean trackWarnings)
-
-
Method Detail
-
create
public static SinglePartitionReadCommand create(TableMetadata metadata, long nowInSec, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits, DecoratedKey partitionKey, ClusteringIndexFilter clusteringIndexFilter, Index.QueryPlan indexQueryPlan)
Creates a new read command on a single partition.- Parameters:
metadata
- the table to query.nowInSec
- the time in seconds to use are "now" for this query.columnFilter
- the column filter to use for the query.rowFilter
- the row filter to use for the query.limits
- the limits to use for the query.partitionKey
- the partition key for the partition to query.clusteringIndexFilter
- the clustering index filter to use for the query.indexQueryPlan
- explicitly specified index to use for the query- Returns:
- a newly created read command.
-
create
public static SinglePartitionReadCommand create(TableMetadata metadata, long nowInSec, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits, DecoratedKey partitionKey, ClusteringIndexFilter clusteringIndexFilter)
Creates a new read command on a single partition.- Parameters:
metadata
- the table to query.nowInSec
- the time in seconds to use are "now" for this query.columnFilter
- the column filter to use for the query.rowFilter
- the row filter to use for the query.limits
- the limits to use for the query.partitionKey
- the partition key for the partition to query.clusteringIndexFilter
- the clustering index filter to use for the query.- Returns:
- a newly created read command.
-
create
public static SinglePartitionReadCommand create(TableMetadata metadata, long nowInSec, DecoratedKey key, ColumnFilter columnFilter, ClusteringIndexFilter filter)
Creates a new read command on a single partition.- Parameters:
metadata
- the table to query.nowInSec
- the time in seconds to use are "now" for this query.key
- the partition key for the partition to query.columnFilter
- the column filter to use for the query.filter
- the clustering index filter to use for the query.- Returns:
- a newly created read command. The returned command will use no row filter and have no limits.
-
fullPartitionRead
public static SinglePartitionReadCommand fullPartitionRead(TableMetadata metadata, long nowInSec, DecoratedKey key)
Creates a new read command that queries a single partition in its entirety.- Parameters:
metadata
- the table to query.nowInSec
- the time in seconds to use are "now" for this query.key
- the partition key for the partition to query.- Returns:
- a newly created read command that queries all the rows of
key
.
-
fullPartitionRead
public static SinglePartitionReadCommand fullPartitionRead(TableMetadata metadata, long nowInSec, java.nio.ByteBuffer key)
Creates a new read command that queries a single partition in its entirety.- Parameters:
metadata
- the table to query.nowInSec
- the time in seconds to use are "now" for this query.key
- the partition key for the partition to query.- Returns:
- a newly created read command that queries all the rows of
key
.
-
create
public static SinglePartitionReadCommand create(TableMetadata metadata, long nowInSec, DecoratedKey key, Slice slice)
Creates a new single partition slice command for the provided single slice.- Parameters:
metadata
- the table to query.nowInSec
- the time in seconds to use are "now" for this query.key
- the partition key for the partition to query.slice
- the slice of rows to query.- Returns:
- a newly created read command that queries
slice
inkey
. The returned query will query every columns for the table (without limit or row filtering) and be in forward order.
-
create
public static SinglePartitionReadCommand create(TableMetadata metadata, long nowInSec, DecoratedKey key, Slices slices)
Creates a new single partition slice command for the provided slices.- Parameters:
metadata
- the table to query.nowInSec
- the time in seconds to use are "now" for this query.key
- the partition key for the partition to query.slices
- the slices of rows to query.- Returns:
- a newly created read command that queries the
slices
inkey
. The returned query will query every columns for the table (without limit or row filtering) and be in forward order.
-
create
public static SinglePartitionReadCommand create(TableMetadata metadata, long nowInSec, java.nio.ByteBuffer key, Slices slices)
Creates a new single partition slice command for the provided slices.- Parameters:
metadata
- the table to query.nowInSec
- the time in seconds to use are "now" for this query.key
- the partition key for the partition to query.slices
- the slices of rows to query.- Returns:
- a newly created read command that queries the
slices
inkey
. The returned query will query every columns for the table (without limit or row filtering) and be in forward order.
-
create
public static SinglePartitionReadCommand create(TableMetadata metadata, long nowInSec, DecoratedKey key, java.util.NavigableSet<Clustering<?>> names)
Creates a new single partition name command for the provided rows.- Parameters:
metadata
- the table to query.nowInSec
- the time in seconds to use are "now" for this query.key
- the partition key for the partition to query.names
- the clustering for the rows to query.- Returns:
- a newly created read command that queries the
names
inkey
. The returned query will query every columns (without limit or row filtering) and be in forward order.
-
create
public static SinglePartitionReadCommand create(TableMetadata metadata, long nowInSec, DecoratedKey key, Clustering<?> name)
Creates a new single partition name command for the provided row.- Parameters:
metadata
- the table to query.nowInSec
- the time in seconds to use are "now" for this query.key
- the partition key for the partition to query.name
- the clustering for the row to query.- Returns:
- a newly created read command that queries
name
inkey
. The returned query will query every columns (without limit or row filtering).
-
copy
public SinglePartitionReadCommand copy()
Description copied from class:ReadCommand
Returns a copy of this command.- Specified by:
copy
in classReadCommand
- Returns:
- a copy of this command.
-
copyAsDigestQuery
protected SinglePartitionReadCommand copyAsDigestQuery()
- Specified by:
copyAsDigestQuery
in classReadCommand
-
copyAsTransientQuery
protected SinglePartitionReadCommand copyAsTransientQuery()
- Specified by:
copyAsTransientQuery
in classReadCommand
-
withUpdatedLimit
public SinglePartitionReadCommand withUpdatedLimit(DataLimits newLimits)
Description copied from class:ReadCommand
Creates a newReadCommand
instance with new limits.- Specified by:
withUpdatedLimit
in interfaceSinglePartitionReadQuery
- Specified by:
withUpdatedLimit
in classReadCommand
- Parameters:
newLimits
- the new limits- Returns:
- a new
ReadCommand
with the updated limits
-
partitionKey
public DecoratedKey partitionKey()
Description copied from interface:SinglePartitionReadQuery
Returns the key of the partition queried by thisReadQuery
- Specified by:
partitionKey
in interfaceSinglePartitionReadQuery
- Returns:
- the key of the partition queried
-
clusteringIndexFilter
public ClusteringIndexFilter clusteringIndexFilter()
- Specified by:
clusteringIndexFilter
in interfaceSinglePartitionReadQuery
-
clusteringIndexFilter
public ClusteringIndexFilter clusteringIndexFilter(DecoratedKey key)
Description copied from class:ReadCommand
The clustering index filter this command to use for the provided key.Note that that method should only be called on a key actually queried by this command and in practice, this will almost always return the same filter, but for the sake of paging, the filter on the first key of a range command might be slightly different.
- Specified by:
clusteringIndexFilter
in classReadCommand
- Parameters:
key
- a partition key queried by this command.- Returns:
- the
ClusteringIndexFilter
to use for the partition of keykey
.
-
getTimeout
public long getTimeout(java.util.concurrent.TimeUnit unit)
Description copied from class:ReadCommand
The configured timeout for this command.- Specified by:
getTimeout
in classReadCommand
- Returns:
- the configured timeout for this command.
-
isReversed
public boolean isReversed()
Description copied from class:ReadCommand
Whether the underlyingClusteringIndexFilter
is reversed or not.- Specified by:
isReversed
in classReadCommand
- Returns:
- whether the underlying
ClusteringIndexFilter
is reversed or not.
-
forPaging
public SinglePartitionReadCommand forPaging(Clustering<?> lastReturned, DataLimits limits)
Description copied from interface:SinglePartitionReadQuery
Returns a newSinglePartitionReadQuery
suitable to paging from the last returned row.- Specified by:
forPaging
in interfaceSinglePartitionReadQuery
- Parameters:
lastReturned
- the last row returned by the previous page. The newly created query will only query row that comes after this (in query order). This can benull
if this is the first page.limits
- the limits to use for the page to query.- Returns:
- the newly create query.
-
execute
public PartitionIterator execute(ConsistencyLevel consistency, ClientState state, Dispatcher.RequestTime requestTime) throws RequestExecutionException
Description copied from interface:ReadQuery
Executes the query at the provided consistency level.- Specified by:
execute
in interfaceReadQuery
- Parameters:
consistency
- the consistency level to achieve for the query.state
- client state- Returns:
- the result of the query.
- Throws:
RequestExecutionException
-
recordLatency
protected void recordLatency(TableMetrics metric, long latencyNanos)
- Specified by:
recordLatency
in classReadCommand
-
queryStorage
protected UnfilteredPartitionIterator queryStorage(ColumnFamilyStore cfs, ReadExecutionController executionController)
- Specified by:
queryStorage
in classReadCommand
-
queryMemtableAndDisk
public UnfilteredRowIterator queryMemtableAndDisk(ColumnFamilyStore cfs, ReadExecutionController executionController)
Queries both memtable and sstables to fetch the result of this query.Please note that this method: 1) does not check the row cache. 2) does not apply the query limit, nor the row filter (and so ignore 2ndary indexes). Those are applied in
ReadCommand.executeLocally(org.apache.cassandra.db.ReadExecutionController)
. 3) does not record some of the read metrics (latency, scanned cells histograms) nor throws TombstoneOverwhelmingException. It is publicly exposed because there is a few places where that is exactly what we want, but it should be used only where you know you don't need thoses things.Also note that one must have created a
ReadExecutionController
on the queried table and we require it as a parameter to enforce that fact, even though it's not explicitlly used by the method.
-
intersects
protected boolean intersects(SSTableReader sstable)
- Specified by:
intersects
in classReadCommand
-
selectsFullPartition
public boolean selectsFullPartition()
Description copied from interface:ReadQuery
Checks if thisReadQuery
selects full partitions, that is it has no filtering on clustering or regular columns.- Specified by:
selectsFullPartition
in interfaceReadQuery
- Returns:
true
if thisReadQuery
selects full partitions,false
otherwise.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
verb
public Verb verb()
- Specified by:
verb
in classReadCommand
-
appendCQLWhereClause
protected void appendCQLWhereClause(java.lang.StringBuilder sb)
- Specified by:
appendCQLWhereClause
in classReadCommand
-
loggableTokens
public java.lang.String loggableTokens()
Description copied from class:ReadCommand
Return the queried token(s) for logging- Specified by:
loggableTokens
in classReadCommand
-
serializeSelection
protected void serializeSelection(DataOutputPlus out, int version) throws java.io.IOException
- Specified by:
serializeSelection
in classReadCommand
- Throws:
java.io.IOException
-
selectionSerializedSize
protected long selectionSerializedSize(int version)
- Specified by:
selectionSerializedSize
in classReadCommand
-
isLimitedToOnePartition
public boolean isLimitedToOnePartition()
- Specified by:
isLimitedToOnePartition
in classReadCommand
-
isRangeRequest
public boolean isRangeRequest()
- Specified by:
isRangeRequest
in classReadCommand
-
metadata
public TableMetadata metadata()
Description copied from interface:ReadQuery
The metadata for the table this is a query on.
-
executeInternal
public PartitionIterator executeInternal(ReadExecutionController controller)
Description copied from interface:ReadQuery
Execute the query for internal queries (that is, it basically executes the query locally).- Specified by:
executeInternal
in interfaceReadQuery
- Parameters:
controller
- theReadExecutionController
protecting the read.- Returns:
- the result of the query.
-
limits
public DataLimits limits()
Description copied from interface:ReadQuery
The limits for the query.
-
nowInSec
public long nowInSec()
Description copied from interface:ReadQuery
The time in seconds to use as "now" for this query.We use the same time as "now" for the whole query to avoid considering different values as expired during the query, which would be buggy (would throw of counting amongst other things).
-
rowFilter
public RowFilter rowFilter()
Description copied from interface:ReadQuery
Filters/Resrictions on CQL rows.This contains the restrictions that are not directly handled by the
ClusteringIndexFilter
. More specifically, this includes any non-PK column restrictions and can include some PK columns restrictions when those can't be satisfied entirely by the clustering index filter (because not all clustering columns have been restricted for instance). If there is 2ndary indexes on the table, one of this restriction might be handled by a 2ndary index.
-
columnFilter
public ColumnFilter columnFilter()
Description copied from interface:ReadQuery
A filter on which (non-PK) columns must be returned by the query.- Specified by:
columnFilter
in interfaceReadQuery
- Returns:
- which columns must be fetched by this query.
-
toCQLString
public java.lang.String toCQLString()
Recreate the CQL string corresponding to this query.Note that in general the returned string will not be exactly the original user string, first because there isn't always a single syntax for a given query, but also because we don't have all the information needed (we know the non-PK columns queried but not the PK ones as internally we query them all). So this shouldn't be relied too strongly, but this should be good enough for debugging purpose which is what this is for.
-
-