org.apache.cassandra.cql3.statements

## Class SelectStatement

- java.lang.Object
- - org.apache.cassandra.cql3.statements.SelectStatement

All Implemented Interfaces:
  CQLStatement

    public class SelectStatement
    extends java.lang.Object
    implements CQLStatement

Encapsulates a completely parsed SELECT query, including the target column family, expression, result count, and ordering clause. A number of public methods here are only used internally. However, many of these are made accessible for the benefit of custom QueryHandler implementations, so before reducing their accessibility due consideration should be given.

### Nested Class Summary

Nested Classes
`static class` `SelectStatement.Parameters`
`static class` `SelectStatement.RawStatement`

### Field Summary

Fields
`CFMetaData` `cfm`
`static int` `DEFAULT_PAGE_SIZE`
`SelectStatement.Parameters` `parameters`

### Constructor Summary

Constructors
Constructor and Description
`SelectStatement(CFMetaData cfm, int boundTerms, SelectStatement.Parameters parameters, Selection selection, StatementRestrictions restrictions, boolean isReversed, AggregationSpecification aggregationSpec, java.util.Comparator<java.util.List<java.nio.ByteBuffer>> orderingComparator, Term limit, Term perPartitionLimit)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `checkAccess(ClientState state)` Perform any access verification necessary for the statement.
`Slices` `clusteringIndexFilterAsSlices()` Returns the slices fetched by this SELECT, assuming an internal call (no bound values in particular).
`java.lang.String` `columnFamily()`
`ResultMessage.Rows` `execute(QueryState state, QueryOptions options, long queryStartNanoTime)` Execute the statement and return the resulting result or null if there is no result.
`ResultMessage.Rows` `executeInternal(QueryState state, QueryOptions options)` Variant of execute used for internal query against the system tables, and thus only query the local node.
`ResultMessage.Rows` `executeInternal(QueryState state, QueryOptions options, int nowInSec, long queryStartNanoTime)`
`int` `getBoundTerms()` Returns the number of bound terms in this statement.
`static java.nio.ByteBuffer[]` `getComponents(CFMetaData cfm, DecoratedKey dk)`
`java.lang.Iterable<Function>` `getFunctions()` Return an Iterable over all of the functions (both native and user-defined) used by any component of the statement
`int` `getLimit(QueryOptions options)` Returns the limit specified by the user.
`int` `getPerPartitionLimit(QueryOptions options)` Returns the per partition limit specified by the user.
`ReadQuery` `getQuery(QueryOptions options, int nowInSec)`
`ReadQuery` `getQuery(QueryOptions options, int nowInSec, int userLimit, int perPartitionLimit, int pageSize)`
`StatementRestrictions` `getRestrictions()` May be used by custom QueryHandler implementations
`ResultSet.ResultMetadata` `getResultMetadata()`
`RowFilter` `getRowFilter(QueryOptions options)` May be used by custom QueryHandler implementations
`Selection` `getSelection()` May be used by custom QueryHandler implementations
`SinglePartitionReadCommand` `internalReadForView(DecoratedKey key, int nowInSec)` Returns a read command that can be used internally to query all the rows queried by this SELECT for a give key (used for materialized views).
`java.lang.String` `keyspace()`
`ResultSet` `process(PartitionIterator partitions, int nowInSec)`
`ColumnFilter` `queriedColumns()` The columns to fetch internally for this SELECT statement (which can be more than the one selected by the user as it also include any restricted column in particular).
`RowFilter` `rowFilterForInternalCalls()` The `RowFilter` for this SELECT, assuming an internal call (no bound values in particular).
`void` `validate(ClientState state)` Perform additional validation required by the statment.

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

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

### Field Detail

#### DEFAULT_PAGE_SIZE

    public static final int DEFAULT_PAGE_SIZE

See Also:
  Constant Field Values

#### cfm

    public final CFMetaData cfm

#### parameters

    public final SelectStatement.Parameters parameters

### Constructor Detail

#### SelectStatement

    public SelectStatement(CFMetaData cfm,
                           int boundTerms,
                           SelectStatement.Parameters parameters,
                           Selection selection,
                           StatementRestrictions restrictions,
                           boolean isReversed,
                           AggregationSpecification aggregationSpec,
                           java.util.Comparator<java.util.List<java.nio.ByteBuffer>> orderingComparator,
                           Term limit,
                           Term perPartitionLimit)

### Method Detail

#### getFunctions

    public java.lang.Iterable<Function> getFunctions()

Description copied from interface: `CQLStatement`
Return an Iterable over all of the functions (both native and user-defined) used by any component of the statement

Specified by:
  `getFunctions` in interface `CQLStatement`
Returns:
  functions all functions found (may contain duplicates)

#### queriedColumns

    public ColumnFilter queriedColumns()

The columns to fetch internally for this SELECT statement (which can be more than the one selected by the user as it also include any restricted column in particular).

#### getResultMetadata

    public ResultSet.ResultMetadata getResultMetadata()

#### getBoundTerms

    public int getBoundTerms()

Description copied from interface: `CQLStatement`
Returns the number of bound terms in this statement.

Specified by:
  `getBoundTerms` in interface `CQLStatement`

#### checkAccess

    public void checkAccess(ClientState state)
                     throws InvalidRequestException,
                            UnauthorizedException

Description copied from interface: `CQLStatement`
Perform any access verification necessary for the statement.

Specified by:
  `checkAccess` in interface `CQLStatement`
Parameters:
  `state` - the current client state
Throws:
  `InvalidRequestException`
  `UnauthorizedException`

#### validate

    public void validate(ClientState state)
                  throws InvalidRequestException

Description copied from interface: `CQLStatement`
Perform additional validation required by the statment. To be overriden by subclasses if needed.

Specified by:
  `validate` in interface `CQLStatement`
Parameters:
  `state` - the current client state
Throws:
  `InvalidRequestException`

#### execute

    public ResultMessage.Rows execute(QueryState state,
                                      QueryOptions options,
                                      long queryStartNanoTime)
                               throws RequestExecutionException,
                                      RequestValidationException

Description copied from interface: `CQLStatement`
Execute the statement and return the resulting result or null if there is no result.

Specified by:
  `execute` in interface `CQLStatement`
Parameters:
  `state` - the current query state
  `options` - options for this query (consistency, variables, pageSize, ...)
  `queryStartNanoTime` - the timestamp returned by System.nanoTime() when this statement was received
Throws:
  `RequestExecutionException`
  `RequestValidationException`

#### getQuery

    public ReadQuery getQuery(QueryOptions options,
                              int nowInSec)
                       throws RequestValidationException

Throws:
  `RequestValidationException`

#### getQuery

    public ReadQuery getQuery(QueryOptions options,
                              int nowInSec,
                              int userLimit,
                              int perPartitionLimit,
                              int pageSize)

#### executeInternal

    public ResultMessage.Rows executeInternal(QueryState state,
                                              QueryOptions options)
                                       throws RequestExecutionException,
                                              RequestValidationException

Description copied from interface: `CQLStatement`
Variant of execute used for internal query against the system tables, and thus only query the local node.

Specified by:
  `executeInternal` in interface `CQLStatement`
Parameters:
  `state` - the current query state
Throws:
  `RequestExecutionException`
  `RequestValidationException`

#### executeInternal

    public ResultMessage.Rows executeInternal(QueryState state,
                                              QueryOptions options,
                                              int nowInSec,
                                              long queryStartNanoTime)
                                       throws RequestExecutionException,
                                              RequestValidationException

Throws:
  `RequestExecutionException`
  `RequestValidationException`

#### process

    public ResultSet process(PartitionIterator partitions,
                             int nowInSec)
                      throws InvalidRequestException

Throws:
  `InvalidRequestException`

#### keyspace

    public java.lang.String keyspace()

#### columnFamily

    public java.lang.String columnFamily()

#### getSelection

    public Selection getSelection()

May be used by custom QueryHandler implementations

#### getRestrictions

    public StatementRestrictions getRestrictions()

May be used by custom QueryHandler implementations

#### clusteringIndexFilterAsSlices

    public Slices clusteringIndexFilterAsSlices()

Returns the slices fetched by this SELECT, assuming an internal call (no bound values in particular).

Note that if the SELECT intrinsically selects rows by names, we convert them into equivalent slices for the purpose of this method. This is used for MVs to restrict what needs to be read when we want to read everything that could be affected by a given view (and so, if the view SELECT statement has restrictions on the clustering columns, we can restrict what we read).

#### internalReadForView

    public SinglePartitionReadCommand internalReadForView(DecoratedKey key,
                                                          int nowInSec)

Returns a read command that can be used internally to query all the rows queried by this SELECT for a give key (used for materialized views).

#### rowFilterForInternalCalls

    public RowFilter rowFilterForInternalCalls()

The `RowFilter` for this SELECT, assuming an internal call (no bound values in particular).

#### getLimit

    public int getLimit(QueryOptions options)

Returns the limit specified by the user. May be used by custom QueryHandler implementations

Returns:
  the limit specified by the user or `DataLimits.NO_LIMIT` if no value as been specified.

#### getPerPartitionLimit

    public int getPerPartitionLimit(QueryOptions options)

Returns the per partition limit specified by the user. May be used by custom QueryHandler implementations

Returns:
  the per partition limit specified by the user or `DataLimits.NO_LIMIT` if no value as been specified.

#### getRowFilter

    public RowFilter getRowFilter(QueryOptions options)
                           throws InvalidRequestException

May be used by custom QueryHandler implementations

Throws:
  `InvalidRequestException`

#### getComponents

    public static java.nio.ByteBuffer[] getComponents(CFMetaData cfm,
                                                      DecoratedKey dk)