Class QueryProcessor
- java.lang.Object
-
- org.apache.cassandra.cql3.QueryProcessor
-
- All Implemented Interfaces:
QueryHandler
public class QueryProcessor extends java.lang.Object implements QueryHandler
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.cassandra.cql3.QueryHandler
QueryHandler.Prepared
-
-
Field Summary
Fields Modifier and Type Field Description static CassandraVersion
CQL_VERSION
static QueryProcessor
instance
static CQLMetrics
metrics
static CassandraVersion
NEW_PREPARED_STATEMENT_BEHAVIOUR_SINCE_40
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
clearInternalStatementsCache()
Clear our internal statmeent cache for test purposes.static void
clearPreparedStatements(boolean memoryOnly)
Clears the prepared statement cache.static void
clearPreparedStatementsCache()
void
evictPrepared(MD5Digest id)
static UntypedResultSet
execute(java.lang.String query, ConsistencyLevel cl, java.lang.Object... values)
static UntypedResultSet
execute(java.lang.String query, ConsistencyLevel cl, QueryState state, java.lang.Object... values)
static Future<UntypedResultSet>
executeAsync(InetAddressAndPort address, java.lang.String query, java.lang.Object... values)
static UntypedResultSet
executeInternal(java.lang.String query, java.lang.Object... values)
static java.util.Map<DecoratedKey,java.util.List<Row>>
executeInternalRawWithNow(long nowInSec, java.lang.String query, java.lang.Object... values)
A special version of executeInternal that takes the time used as "now" for the query in argument.static UntypedResultSet
executeInternalWithNow(long nowInSec, Dispatcher.RequestTime requestTime, java.lang.String query, java.lang.Object... values)
A special version of executeLocally that takes the time used as "now" for the query in argument.static UntypedResultSet
executeInternalWithNowInSec(java.lang.String query, long nowInSec, java.lang.Object... values)
static UntypedResultSet
executeInternalWithPaging(java.lang.String query, int pageSize, java.lang.Object... values)
static UntypedResultSet
executeOnceInternal(java.lang.String query, java.lang.Object... values)
Same than executeLocally, but to use for queries we know are only executed once so that the created statement object is not cached.static UntypedResultSet
executeOnceInternalWithNowAndTimestamp(long nowInSec, long timestamp, java.lang.String query, java.lang.Object... values)
Execute an internal query with the providednowInSec
andtimestamp
for theQueryState
.static java.util.concurrent.ConcurrentMap<java.lang.String,QueryHandler.Prepared>
getInternalStatements()
QueryHandler.Prepared
getPrepared(MD5Digest id)
java.util.HashMap<MD5Digest,QueryHandler.Prepared>
getPreparedStatements()
static CQLStatement
getStatement(java.lang.String queryStr, ClientState clientState)
static ResultMessage.Prepared
getStoredPreparedStatement(java.lang.String queryString, java.lang.String clientKeyspace)
static QueryState
internalQueryState()
static QueryOptions
makeInternalOptions(CQLStatement prepared, java.lang.Object[] values)
static QueryOptions
makeInternalOptionsWithNowInSec(CQLStatement prepared, long nowInSec, java.lang.Object[] values)
CQLStatement
parse(java.lang.String queryString, QueryState queryState, QueryOptions options)
static QueryHandler.Prepared
parseAndPrepare(java.lang.String query, ClientState clientState, boolean isInternal)
static CQLStatement.Raw
parseStatement(java.lang.String queryStr)
static <T extends CQLStatement.Raw>
TparseStatement(java.lang.String queryStr, java.lang.Class<T> klass, java.lang.String type)
static CQLStatement
parseStatement(java.lang.String queryStr, ClientState clientState)
void
preloadPreparedStatements()
ResultMessage.Prepared
prepare(java.lang.String queryString, ClientState clientState)
This method got slightly out of hand, but this is with best intentions: to allow users to be upgraded from any prior version, and help implementers avoid previous mistakes by clearly separating fully qualified and non-fully qualified statement behaviour.ResultMessage.Prepared
prepare(java.lang.String query, ClientState clientState, java.util.Map<java.lang.String,java.nio.ByteBuffer> customPayload)
static int
preparedStatementsCount()
static QueryHandler.Prepared
prepareInternal(java.lang.String query)
static UntypedResultSet
process(java.lang.String query, ConsistencyLevel cl)
static UntypedResultSet
process(java.lang.String query, ConsistencyLevel cl, java.util.List<java.nio.ByteBuffer> values)
static ResultMessage
process(java.lang.String queryString, ConsistencyLevel cl, QueryState queryState, Dispatcher.RequestTime requestTime)
ResultMessage
process(CQLStatement statement, QueryState state, QueryOptions options, java.util.Map<java.lang.String,java.nio.ByteBuffer> customPayload, Dispatcher.RequestTime requestTime)
ResultMessage
process(CQLStatement prepared, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime)
ResultMessage
processBatch(BatchStatement statement, QueryState state, BatchQueryOptions options, java.util.Map<java.lang.String,java.nio.ByteBuffer> customPayload, Dispatcher.RequestTime requestTime)
ResultMessage
processBatch(BatchStatement batch, QueryState queryState, BatchQueryOptions options, Dispatcher.RequestTime requestTime)
ResultMessage
processPrepared(CQLStatement statement, QueryState state, QueryOptions options, java.util.Map<java.lang.String,java.nio.ByteBuffer> customPayload, Dispatcher.RequestTime requestTime)
ResultMessage
processPrepared(CQLStatement statement, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime)
ResultMessage
processStatement(CQLStatement statement, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime)
static UntypedResultSet
resultify(java.lang.String query, PartitionIterator partitions)
static UntypedResultSet
resultify(java.lang.String query, RowIterator partition)
static ResultMessage.Prepared
storePreparedStatement(java.lang.String queryString, java.lang.String keyspace, QueryHandler.Prepared prepared)
boolean
useNewPreparedStatementBehaviour()
static void
validateKey(java.nio.ByteBuffer key)
-
-
-
Field Detail
-
CQL_VERSION
public static final CassandraVersion CQL_VERSION
-
NEW_PREPARED_STATEMENT_BEHAVIOUR_SINCE_40
public static final CassandraVersion NEW_PREPARED_STATEMENT_BEHAVIOUR_SINCE_40
-
instance
public static final QueryProcessor instance
-
metrics
public static final CQLMetrics metrics
-
-
Method Detail
-
preparedStatementsCount
public static int preparedStatementsCount()
-
preloadPreparedStatements
public void preloadPreparedStatements()
-
clearPreparedStatements
public static void clearPreparedStatements(boolean memoryOnly)
Clears the prepared statement cache.- Parameters:
memoryOnly
-true
if only the in memory caches must be cleared,false
otherwise.
-
getInternalStatements
public static java.util.concurrent.ConcurrentMap<java.lang.String,QueryHandler.Prepared> getInternalStatements()
-
internalQueryState
public static QueryState internalQueryState()
-
evictPrepared
public void evictPrepared(MD5Digest id)
-
getPreparedStatements
public java.util.HashMap<MD5Digest,QueryHandler.Prepared> getPreparedStatements()
-
getPrepared
public QueryHandler.Prepared getPrepared(MD5Digest id)
- Specified by:
getPrepared
in interfaceQueryHandler
-
validateKey
public static void validateKey(java.nio.ByteBuffer key) throws InvalidRequestException
- Throws:
InvalidRequestException
-
processStatement
public ResultMessage processStatement(CQLStatement statement, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime) throws RequestExecutionException, RequestValidationException
-
process
public static ResultMessage process(java.lang.String queryString, ConsistencyLevel cl, QueryState queryState, Dispatcher.RequestTime requestTime) throws RequestExecutionException, RequestValidationException
-
parse
public CQLStatement parse(java.lang.String queryString, QueryState queryState, QueryOptions options)
- Specified by:
parse
in interfaceQueryHandler
-
process
public ResultMessage process(CQLStatement statement, QueryState state, QueryOptions options, java.util.Map<java.lang.String,java.nio.ByteBuffer> customPayload, Dispatcher.RequestTime requestTime) throws RequestExecutionException, RequestValidationException
- Specified by:
process
in interfaceQueryHandler
- Throws:
RequestExecutionException
RequestValidationException
-
process
public ResultMessage process(CQLStatement prepared, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime) throws RequestExecutionException, RequestValidationException
-
parseStatement
public static CQLStatement parseStatement(java.lang.String queryStr, ClientState clientState) throws RequestValidationException
- Throws:
RequestValidationException
-
process
public static UntypedResultSet process(java.lang.String query, ConsistencyLevel cl) throws RequestExecutionException
- Throws:
RequestExecutionException
-
process
public static UntypedResultSet process(java.lang.String query, ConsistencyLevel cl, java.util.List<java.nio.ByteBuffer> values) throws RequestExecutionException
- Throws:
RequestExecutionException
-
makeInternalOptions
public static QueryOptions makeInternalOptions(CQLStatement prepared, java.lang.Object[] values)
-
makeInternalOptionsWithNowInSec
public static QueryOptions makeInternalOptionsWithNowInSec(CQLStatement prepared, long nowInSec, java.lang.Object[] values)
-
prepareInternal
public static QueryHandler.Prepared prepareInternal(java.lang.String query) throws RequestValidationException
- Throws:
RequestValidationException
-
parseAndPrepare
public static QueryHandler.Prepared parseAndPrepare(java.lang.String query, ClientState clientState, boolean isInternal) throws RequestValidationException
- Throws:
RequestValidationException
-
executeInternal
public static UntypedResultSet executeInternal(java.lang.String query, java.lang.Object... values)
-
executeAsync
public static Future<UntypedResultSet> executeAsync(InetAddressAndPort address, java.lang.String query, java.lang.Object... values)
-
execute
public static UntypedResultSet execute(java.lang.String query, ConsistencyLevel cl, java.lang.Object... values) throws RequestExecutionException
- Throws:
RequestExecutionException
-
executeInternalWithNowInSec
public static UntypedResultSet executeInternalWithNowInSec(java.lang.String query, long nowInSec, java.lang.Object... values)
-
execute
public static UntypedResultSet execute(java.lang.String query, ConsistencyLevel cl, QueryState state, java.lang.Object... values) throws RequestExecutionException
- Throws:
RequestExecutionException
-
executeInternalWithPaging
public static UntypedResultSet executeInternalWithPaging(java.lang.String query, int pageSize, java.lang.Object... values)
-
executeOnceInternal
public static UntypedResultSet executeOnceInternal(java.lang.String query, java.lang.Object... values)
Same than executeLocally, but to use for queries we know are only executed once so that the created statement object is not cached.
-
executeOnceInternalWithNowAndTimestamp
public static UntypedResultSet executeOnceInternalWithNowAndTimestamp(long nowInSec, long timestamp, java.lang.String query, java.lang.Object... values)
Execute an internal query with the providednowInSec
andtimestamp
for theQueryState
.This method ensure that the statement will not be cached in the prepared statement cache.
-
executeInternalWithNow
public static UntypedResultSet executeInternalWithNow(long nowInSec, Dispatcher.RequestTime requestTime, java.lang.String query, java.lang.Object... values)
A special version of executeLocally that takes the time used as "now" for the query in argument. Note that this only make sense for Selects so this only accept SELECT statements and is only useful in rare cases.
-
executeInternalRawWithNow
public static java.util.Map<DecoratedKey,java.util.List<Row>> executeInternalRawWithNow(long nowInSec, java.lang.String query, java.lang.Object... values)
A special version of executeInternal that takes the time used as "now" for the query in argument. Note that this only make sense for Selects so this only accept SELECT statements and is only useful in rare cases.
-
resultify
public static UntypedResultSet resultify(java.lang.String query, RowIterator partition)
-
resultify
public static UntypedResultSet resultify(java.lang.String query, PartitionIterator partitions)
-
prepare
public ResultMessage.Prepared prepare(java.lang.String query, ClientState clientState, java.util.Map<java.lang.String,java.nio.ByteBuffer> customPayload) throws RequestValidationException
- Specified by:
prepare
in interfaceQueryHandler
- Throws:
RequestValidationException
-
useNewPreparedStatementBehaviour
public boolean useNewPreparedStatementBehaviour()
-
prepare
public ResultMessage.Prepared prepare(java.lang.String queryString, ClientState clientState)
This method got slightly out of hand, but this is with best intentions: to allow users to be upgraded from any prior version, and help implementers avoid previous mistakes by clearly separating fully qualified and non-fully qualified statement behaviour.Basically we need to handle 4 different hashes here; 1. fully qualified query with keyspace 2. fully qualified query without keyspace 3. unqualified query with keyspace 4. unqualified query without keyspace
The correct combination to return is 2/3 - the problem is during upgrades (assuming upgrading from < 4.0.2) - Existing clients have hash 1 or 3 - Query prepared on a post-4.0.2 instance needs to return hash 1/3 to be able to execute it on a pre-4.0.2 instance - This is handled by the useNewPreparedStatementBehaviour flag - while there still are pre-4.0.2 instances in the cluster we always return hash 1/3 - Once fully upgraded we start returning hash 2/3, this will cause a prepared statement id mismatch for existing clients, but they will be able to continue using the old prepared statement id after that exception since we store the query both with and without keyspace.
-
getStoredPreparedStatement
public static ResultMessage.Prepared getStoredPreparedStatement(java.lang.String queryString, java.lang.String clientKeyspace) throws InvalidRequestException
- Throws:
InvalidRequestException
-
storePreparedStatement
public static ResultMessage.Prepared storePreparedStatement(java.lang.String queryString, java.lang.String keyspace, QueryHandler.Prepared prepared) throws InvalidRequestException
- Throws:
InvalidRequestException
-
processPrepared
public ResultMessage processPrepared(CQLStatement statement, QueryState state, QueryOptions options, java.util.Map<java.lang.String,java.nio.ByteBuffer> customPayload, Dispatcher.RequestTime requestTime) throws RequestExecutionException, RequestValidationException
- Specified by:
processPrepared
in interfaceQueryHandler
- Throws:
RequestExecutionException
RequestValidationException
-
processPrepared
public ResultMessage processPrepared(CQLStatement statement, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime) throws RequestExecutionException, RequestValidationException
-
processBatch
public ResultMessage processBatch(BatchStatement statement, QueryState state, BatchQueryOptions options, java.util.Map<java.lang.String,java.nio.ByteBuffer> customPayload, Dispatcher.RequestTime requestTime) throws RequestExecutionException, RequestValidationException
- Specified by:
processBatch
in interfaceQueryHandler
- Throws:
RequestExecutionException
RequestValidationException
-
processBatch
public ResultMessage processBatch(BatchStatement batch, QueryState queryState, BatchQueryOptions options, Dispatcher.RequestTime requestTime) throws RequestExecutionException, RequestValidationException
-
getStatement
public static CQLStatement getStatement(java.lang.String queryStr, ClientState clientState) throws RequestValidationException
- Throws:
RequestValidationException
-
parseStatement
public static <T extends CQLStatement.Raw> T parseStatement(java.lang.String queryStr, java.lang.Class<T> klass, java.lang.String type) throws SyntaxException
- Throws:
SyntaxException
-
parseStatement
public static CQLStatement.Raw parseStatement(java.lang.String queryStr) throws SyntaxException
- Throws:
SyntaxException
-
clearInternalStatementsCache
public static void clearInternalStatementsCache()
Clear our internal statmeent cache for test purposes.
-
clearPreparedStatementsCache
public static void clearPreparedStatementsCache()
-
-