Package org.apache.cassandra.cql3
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 CassandraVersionCQL_VERSIONstatic QueryProcessorinstancestatic CQLMetricsmetricsstatic CassandraVersionNEW_PREPARED_STATEMENT_BEHAVIOUR_SINCE_30static CassandraVersionNEW_PREPARED_STATEMENT_BEHAVIOUR_SINCE_3Xstatic CassandraVersionNEW_PREPARED_STATEMENT_BEHAVIOUR_SINCE_40static intPRELOAD_PREPARED_STATEMENTS_FETCH_SIZEstatic longPREPARED_STATEMENT_CACHE_SIZE_BYTES
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidclearInternalStatementsCache()Clear our internal statmeent cache for test purposes.static voidclearPreparedStatements(boolean memoryOnly)Clears the prepared statement cache.static voidclearPreparedStatementsCache()voidevictPrepared(MD5Digest id)static UntypedResultSetexecute(java.lang.String query, ConsistencyLevel cl, java.lang.Object... values)static UntypedResultSetexecute(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 UntypedResultSetexecuteInternal(java.lang.String query, java.lang.Object... values)static java.util.Map<DecoratedKey,java.util.List<Row>>executeInternalRawWithNow(int 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 UntypedResultSetexecuteInternalWithNow(int 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 UntypedResultSetexecuteInternalWithNowInSec(java.lang.String query, int nowInSec, java.lang.Object... values)static UntypedResultSetexecuteInternalWithPaging(java.lang.String query, int pageSize, java.lang.Object... values)static UntypedResultSetexecuteOnceInternal(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 UntypedResultSetexecuteOnceInternalWithNowAndTimestamp(int nowInSec, long timestamp, java.lang.String query, java.lang.Object... values)Execute an internal query with the providednowInSecandtimestampfor theQueryState.static UntypedResultSetexecuteOnceInternalWithPaging(java.lang.String query, int pageSize, java.lang.Object... values)Executes with a non-prepared statement using paging.static java.util.concurrent.ConcurrentMap<java.lang.String,QueryHandler.Prepared>getInternalStatements()QueryHandler.PreparedgetPrepared(MD5Digest id)java.util.HashMap<MD5Digest,QueryHandler.Prepared>getPreparedStatements()static CQLStatementgetStatement(java.lang.String queryStr, ClientState clientState)static ResultMessage.PreparedgetStoredPreparedStatement(java.lang.String queryString, java.lang.String clientKeyspace)static QueryStateinternalQueryState()static QueryOptionsmakeInternalOptions(CQLStatement prepared, java.lang.Object[] values)static QueryOptionsmakeInternalOptionsWithNowInSec(CQLStatement prepared, int nowInSec, java.lang.Object[] values)CQLStatementparse(java.lang.String queryString, QueryState queryState, QueryOptions options)static QueryHandler.PreparedparseAndPrepare(java.lang.String query, ClientState clientState, boolean isInternal)static QueryHandler.PreparedparseAndPrepare(java.lang.String query, ClientState clientState, boolean isInternal, boolean measure)static CQLStatement.RawparseStatement(java.lang.String queryStr)static <T extends CQLStatement.Raw>
TparseStatement(java.lang.String queryStr, java.lang.Class<T> klass, java.lang.String type)static CQLStatementparseStatement(java.lang.String queryStr, ClientState clientState)voidpreloadPreparedStatements()intpreloadPreparedStatements(int pageSize)ResultMessage.Preparedprepare(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.Preparedprepare(java.lang.String query, ClientState clientState, java.util.Map<java.lang.String,java.nio.ByteBuffer> customPayload)static intpreparedStatementsCount()static QueryHandler.PreparedprepareInternal(java.lang.String query)static UntypedResultSetprocess(java.lang.String query, ConsistencyLevel cl)static UntypedResultSetprocess(java.lang.String query, ConsistencyLevel cl, java.util.List<java.nio.ByteBuffer> values)static ResultMessageprocess(java.lang.String queryString, ConsistencyLevel cl, QueryState queryState, Dispatcher.RequestTime requestTime)ResultMessageprocess(CQLStatement statement, QueryState state, QueryOptions options, java.util.Map<java.lang.String,java.nio.ByteBuffer> customPayload, Dispatcher.RequestTime requestTime)ResultMessageprocess(CQLStatement prepared, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime)ResultMessageprocessBatch(BatchStatement statement, QueryState state, BatchQueryOptions options, java.util.Map<java.lang.String,java.nio.ByteBuffer> customPayload, Dispatcher.RequestTime requestTime)ResultMessageprocessBatch(BatchStatement batch, QueryState queryState, BatchQueryOptions options, Dispatcher.RequestTime requestTime)ResultMessageprocessPrepared(CQLStatement statement, QueryState state, QueryOptions options, java.util.Map<java.lang.String,java.nio.ByteBuffer> customPayload, Dispatcher.RequestTime requestTime)ResultMessageprocessPrepared(CQLStatement statement, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime)ResultMessageprocessStatement(CQLStatement statement, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime)static UntypedResultSetresultify(java.lang.String query, PartitionIterator partitions)static UntypedResultSetresultify(java.lang.String query, RowIterator partition)static ResultMessage.PreparedstorePreparedStatement(java.lang.String queryString, java.lang.String keyspace, QueryHandler.Prepared prepared)booleanuseNewPreparedStatementBehaviour()static voidvalidateKey(java.nio.ByteBuffer key)
-
-
-
Field Detail
-
CQL_VERSION
public static final CassandraVersion CQL_VERSION
-
NEW_PREPARED_STATEMENT_BEHAVIOUR_SINCE_30
public static final CassandraVersion NEW_PREPARED_STATEMENT_BEHAVIOUR_SINCE_30
-
NEW_PREPARED_STATEMENT_BEHAVIOUR_SINCE_3X
public static final CassandraVersion NEW_PREPARED_STATEMENT_BEHAVIOUR_SINCE_3X
-
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
-
PRELOAD_PREPARED_STATEMENTS_FETCH_SIZE
public static final int PRELOAD_PREPARED_STATEMENTS_FETCH_SIZE
- See Also:
- Constant Field Values
-
PREPARED_STATEMENT_CACHE_SIZE_BYTES
public static long PREPARED_STATEMENT_CACHE_SIZE_BYTES
-
-
Method Detail
-
preparedStatementsCount
public static int preparedStatementsCount()
-
preloadPreparedStatements
public void preloadPreparedStatements()
-
preloadPreparedStatements
public int preloadPreparedStatements(int pageSize)
-
clearPreparedStatements
public static void clearPreparedStatements(boolean memoryOnly)
Clears the prepared statement cache.- Parameters:
memoryOnly-trueif only the in memory caches must be cleared,falseotherwise.
-
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:
getPreparedin 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:
parsein 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:
processin interfaceQueryHandler- Throws:
RequestExecutionExceptionRequestValidationException
-
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, int 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
-
parseAndPrepare
public static QueryHandler.Prepared parseAndPrepare(java.lang.String query, ClientState clientState, boolean isInternal, boolean measure) 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, int 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)
-
executeOnceInternalWithPaging
public static UntypedResultSet executeOnceInternalWithPaging(java.lang.String query, int pageSize, java.lang.Object... values)
Executes with a non-prepared statement using paging. GenerallyexecuteInternalWithPaging(String, int, Object...)should be used instead of this, but this may be used in niche cases likeSystemKeyspace.loadPreparedStatement(MD5Digest, SystemKeyspace.TriFunction)where prepared statements are being loaded intopreparedStatementsso it doesn't make sense to prepare a statement in this context.
-
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(int nowInSec, long timestamp, java.lang.String query, java.lang.Object... values)
Execute an internal query with the providednowInSecandtimestampfor theQueryState.This method ensure that the statement will not be cached in the prepared statement cache.
-
executeInternalWithNow
public static UntypedResultSet executeInternalWithNow(int 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(int 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:
preparein 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 < 3.0.26) - Existing clients have hash 1 or 3 - Query prepared on a 3.0.26/3.11.12/4.0.2 instance needs to return hash 1/3 to be able to execute it on a 3.0.25 instance - This is handled by the useNewPreparedStatementBehaviour flag - while there still are 3.0.25 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:
processPreparedin interfaceQueryHandler- Throws:
RequestExecutionExceptionRequestValidationException
-
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:
processBatchin interfaceQueryHandler- Throws:
RequestExecutionExceptionRequestValidationException
-
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()
-
-