org.apache.cassandra.db

## 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

      public class SinglePartitionReadCommand
      extends ReadCommand

  A read command that selects a (part of a) single partition.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `SinglePartitionReadCommand.Group` Groups multiple single partition read commands.

    - ### Nested classes/interfaces inherited from class org.apache.cassandra.db.ReadCommand

      `ReadCommand.CheckForAbort, ReadCommand.Kind, ReadCommand.SelectionDeserializer`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static ReadCommand.SelectionDeserializer` | `selectionDeserializer`

    - ### Fields inherited from class org.apache.cassandra.db.ReadCommand

      `legacyPagedRangeCommandSerializer, legacyRangeSliceCommandSerializer, legacyReadCommandSerializer, logger, pagedRangeSerializer, rangeSliceSerializer, readSerializer, serializer`

    - ### Fields inherited from interface org.apache.cassandra.db.ReadQuery

      `EMPTY`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and 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.
    `SinglePartitionReadCommand` | `copy()` Returns a copy of this command.
    `SinglePartitionReadCommand` | `copyAsDigestQuery()` Returns a copy of this command with isDigestQuery set to true.
    `static SinglePartitionReadCommand` | `create(boolean isForThrift, CFMetaData metadata, int nowInSec, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits, DecoratedKey partitionKey, ClusteringIndexFilter clusteringIndexFilter)` Creates a new read command on a single partition.
    `static SinglePartitionReadCommand` | `create(boolean isForThrift, CFMetaData metadata, int nowInSec, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits, DecoratedKey partitionKey, ClusteringIndexFilter clusteringIndexFilter, IndexMetadata indexMetadata)` Creates a new read command on a single partition.
    `static SinglePartitionReadCommand` | `create(CFMetaData metadata, int nowInSec, java.nio.ByteBuffer key, Slices slices)` Creates a new single partition slice command for the provided slices.
    `static SinglePartitionReadCommand` | `create(CFMetaData metadata, int nowInSec, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits, DecoratedKey partitionKey, ClusteringIndexFilter clusteringIndexFilter)` Creates a new read command on a single partition.
    `static SinglePartitionReadCommand` | `create(CFMetaData metadata, int nowInSec, DecoratedKey key, Clustering name)` Creates a new single partition name command for the provided row.
    `static SinglePartitionReadCommand` | `create(CFMetaData metadata, int nowInSec, DecoratedKey key, ColumnFilter columnFilter, ClusteringIndexFilter filter)` Creates a new read command on a single partition.
    `static SinglePartitionReadCommand` | `create(CFMetaData metadata, int nowInSec, DecoratedKey key, java.util.NavigableSet<Clustering> names)` Creates a new single partition name command for the provided rows.
    `static SinglePartitionReadCommand` | `create(CFMetaData metadata, int nowInSec, DecoratedKey key, Slice slice)` Creates a new single partition slice command for the provided single slice.
    `static SinglePartitionReadCommand` | `create(CFMetaData metadata, int nowInSec, DecoratedKey key, Slices slices)` Creates a new single partition slice command for the provided slices.
    `MessageOut<ReadCommand>` | `createMessage(int version)` Creates a message for this command.
    `PartitionIterator` | `execute(ConsistencyLevel consistency, ClientState clientState, long queryStartNanoTime)` Executes the query at the provided consistency level.
    `SinglePartitionReadCommand` | `forPaging(Clustering lastReturned, DataLimits limits)` Returns a new command suitable to paging from the last returned row.
    `static SinglePartitionReadCommand` | `fullPartitionRead(CFMetaData metadata, int nowInSec, java.nio.ByteBuffer key)` Creates a new read command that queries a single partition in its entirety.
    `static SinglePartitionReadCommand` | `fullPartitionRead(CFMetaData metadata, int nowInSec, DecoratedKey key)` Creates a new read command that queries a single partition in its entirety.
    `SinglePartitionPager` | `getPager(PagingState pagingState, ProtocolVersion protocolVersion)` Returns a pager for the query.
    `long` | `getTimeout()` The configured timeout for this command.
    `boolean` | `isLimitedToOnePartition()`
    `protected int` | `oldestUnrepairedTombstone()`
    `DecoratedKey` | `partitionKey()`
    `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)`
    `protected long` | `selectionSerializedSize(int version)`
    `boolean` | `selectsClustering(DecoratedKey key, Clustering clustering)`
    `boolean` | `selectsFullPartition()` Checks if this `ReadQuery` selects full partitions, that is it has no filtering on clustering or regular columns.
    `boolean` | `selectsKey(DecoratedKey key)`
    `protected void` | `serializeSelection(DataOutputPlus out, int version)`
    `java.lang.String` | `toString()`
    `SinglePartitionReadCommand` | `withUpdatedClusteringIndexFilter(ClusteringIndexFilter filter)`
    `SinglePartitionReadCommand` | `withUpdatedLimit(DataLimits newLimits)` Creates a new `ReadCommand` instance with new limits.

    - ### Methods inherited from class org.apache.cassandra.db.ReadCommand

      `columnFilter, createResponse, digestVersion, executeInternal, executeLocally, executionController, getIndex, indexMetadata, isDigestQuery, isForThrift, limits, maybeValidateIndex, metadata, name, nowInSec, rowFilter, setDigestVersion, toCQLString, withoutPurgeableTombstones, withStateTracking`

    - ### Methods inherited from class org.apache.cassandra.db.monitoring.MonitorableImpl

      `abort, complete, constructionTime, isAborted, isCompleted, isCrossNode, isInProgress, isSlow, setMonitoringTime, slowTimeout, timeout`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### selectionDeserializer

          protected static final ReadCommand.SelectionDeserializer selectionDeserializer

  - ### Method Detail

    - #### create

          public static SinglePartitionReadCommand create(boolean isForThrift,
                                                          CFMetaData metadata,
                                                          int nowInSec,
                                                          ColumnFilter columnFilter,
                                                          RowFilter rowFilter,
                                                          DataLimits limits,
                                                          DecoratedKey partitionKey,
                                                          ClusteringIndexFilter clusteringIndexFilter,
                                                          IndexMetadata indexMetadata)

      Creates a new read command on a single partition.
      Parameters:
        `isForThrift` - whether the query is for thrift or not.
        `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.
        `indexMetadata` - explicitly specified index to use for the query
      Returns:
        a newly created read command.

    - #### create

          public static SinglePartitionReadCommand create(CFMetaData metadata,
                                                          int 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(boolean isForThrift,
                                                          CFMetaData metadata,
                                                          int nowInSec,
                                                          ColumnFilter columnFilter,
                                                          RowFilter rowFilter,
                                                          DataLimits limits,
                                                          DecoratedKey partitionKey,
                                                          ClusteringIndexFilter clusteringIndexFilter)

      Creates a new read command on a single partition.
      Parameters:
        `isForThrift` - whether the query is for thrift or not.
        `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(CFMetaData metadata,
                                                          int 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(CFMetaData metadata,
                                                                     int 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(CFMetaData metadata,
                                                                     int 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(CFMetaData metadata,
                                                          int 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` in `key`. 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(CFMetaData metadata,
                                                          int 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` in `key`. 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(CFMetaData metadata,
                                                          int 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` in `key`. 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(CFMetaData metadata,
                                                          int 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` in `key`. The returned query will query every columns (without limit or row filtering) and be in forward order.

    - #### create

          public static SinglePartitionReadCommand create(CFMetaData metadata,
                                                          int 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` in `key`. 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 class `ReadCommand`
      Returns:
        a copy of this command.

    - #### copyAsDigestQuery

          public SinglePartitionReadCommand copyAsDigestQuery()

      Description copied from class: `ReadCommand`
      Returns a copy of this command with isDigestQuery set to true.
      Specified by:
        `copyAsDigestQuery` in class `ReadCommand`

    - #### withUpdatedLimit

          public SinglePartitionReadCommand withUpdatedLimit(DataLimits newLimits)

      Description copied from class: `ReadCommand`
      Creates a new `ReadCommand` instance with new limits.
      Specified by:
        `withUpdatedLimit` in class `ReadCommand`
      Parameters:
        `newLimits` - the new limits
      Returns:
        a new `ReadCommand` with the updated limits

    - #### withUpdatedClusteringIndexFilter

          public SinglePartitionReadCommand withUpdatedClusteringIndexFilter(ClusteringIndexFilter filter)

    - #### partitionKey

          public DecoratedKey partitionKey()

    - #### clusteringIndexFilter

          public ClusteringIndexFilter clusteringIndexFilter()

    - #### 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 class `ReadCommand`
      Parameters:
        `key` - a partition key queried by this command.
      Returns:
        the `ClusteringIndexFilter` to use for the partition of key `key`.

    - #### getTimeout

          public long getTimeout()

      Description copied from class: `ReadCommand`
      The configured timeout for this command.
      Specified by:
        `getTimeout` in class `ReadCommand`
      Returns:
        the configured timeout for this command.

    - #### selectsKey

          public boolean selectsKey(DecoratedKey key)

      Returns:
        true if the read query would select the given key, including checks against the row filter, if checkRowFilter is true

    - #### selectsClustering

          public boolean selectsClustering(DecoratedKey key,
                                           Clustering clustering)

      Returns:
        true if the read query would select the given clustering, including checks against the row filter, if checkRowFilter is true

    - #### forPaging

          public SinglePartitionReadCommand forPaging(Clustering lastReturned,
                                                      DataLimits limits)

      Returns a new command suitable to paging from the last returned row.
      Parameters:
        `lastReturned` - the last row returned by the previous page. The newly created command will only query row that comes after this (in query order). This can be `null` if this is the first page.
        `limits` - the limits to use for the page to query.
      Returns:
        the newly create command.

    - #### execute

          public PartitionIterator execute(ConsistencyLevel consistency,
                                           ClientState clientState,
                                           long queryStartNanoTime)
                                    throws RequestExecutionException

      Description copied from interface: `ReadQuery`
      Executes the query at the provided consistency level.
      Parameters:
        `consistency` - the consistency level to achieve for the query.
        `clientState` - the `ClientState` for the query. In practice, this can be null unless `consistency` is a serial consistency.
      Returns:
        the result of the query.
      Throws:
        `RequestExecutionException`

    - #### getPager

          public SinglePartitionPager getPager(PagingState pagingState,
                                               ProtocolVersion protocolVersion)

      Description copied from interface: `ReadQuery`
      Returns a pager for the query.
      Parameters:
        `pagingState` - the `PagingState` to start from if this is a paging continuation. This can be `null` if this is the start of paging.
        `protocolVersion` - the protocol version to use for the paging state of that pager.
      Returns:
        a pager for the query.

    - #### recordLatency

          protected void recordLatency(TableMetrics metric,
                                       long latencyNanos)

      Specified by:
        `recordLatency` in class `ReadCommand`

    - #### queryStorage

          protected UnfilteredPartitionIterator queryStorage(ColumnFamilyStore cfs,
                                                             ReadExecutionController executionController)

      Specified by:
        `queryStorage` in class `ReadCommand`

    - #### 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.

    - #### oldestUnrepairedTombstone

          protected int oldestUnrepairedTombstone()

      Specified by:
        `oldestUnrepairedTombstone` in class `ReadCommand`

    - #### selectsFullPartition

          public boolean selectsFullPartition()

      Description copied from interface: `ReadQuery`
      Checks if this `ReadQuery` selects full partitions, that is it has no filtering on clustering or regular columns.
      Returns:
        `true` if this `ReadQuery` selects full partitions, `false` otherwise.

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### createMessage

          public MessageOut<ReadCommand> createMessage(int version)

      Description copied from class: `ReadCommand`
      Creates a message for this command.
      Specified by:
        `createMessage` in class `ReadCommand`

    - #### appendCQLWhereClause

          protected void appendCQLWhereClause(java.lang.StringBuilder sb)

      Specified by:
        `appendCQLWhereClause` in class `ReadCommand`

    - #### serializeSelection

          protected void serializeSelection(DataOutputPlus out,
                                            int version)
                                     throws java.io.IOException

      Specified by:
        `serializeSelection` in class `ReadCommand`
      Throws:
        `java.io.IOException`

    - #### selectionSerializedSize

          protected long selectionSerializedSize(int version)

      Specified by:
        `selectionSerializedSize` in class `ReadCommand`

    - #### isLimitedToOnePartition

          public boolean isLimitedToOnePartition()

      Specified by:
        `isLimitedToOnePartition` in class `ReadCommand`

Copyright © 2018 The Apache Software Foundation