Class QueryProcessor
- All Implemented Interfaces:
QueryHandler
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.cassandra.cql3.QueryHandler
QueryHandler.Prepared -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CassandraVersionstatic final QueryProcessorstatic final CQLMetricsstatic final CassandraVersionstatic final intstatic long -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClear our internal statmeent cache for test purposes.static voidclearPreparedStatements(boolean memoryOnly) Clears the prepared statement cache.static voidvoidstatic UntypedResultSetexecute(String query, ConsistencyLevel cl, Object... values) static UntypedResultSetexecute(String query, ConsistencyLevel cl, QueryState state, Object... values) static Future<UntypedResultSet>executeAsync(InetAddressAndPort address, String query, Object... values) static UntypedResultSetexecuteInternal(String query, Object... values) static Map<DecoratedKey,List<Row>> executeInternalRawWithNow(long nowInSec, String query, Object... values) A special version of executeInternal that takes the time used as "now" for the query in argument.static UntypedResultSetexecuteInternalWithNow(long nowInSec, Dispatcher.RequestTime requestTime, String query, Object... values) A special version of executeLocally that takes the time used as "now" for the query in argument.static UntypedResultSetexecuteInternalWithNowInSec(String query, long nowInSec, Object... values) static UntypedResultSetexecuteInternalWithPaging(String query, int pageSize, Object... values) static UntypedResultSetexecuteOnceInternal(String query, 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(long nowInSec, long timestamp, String query, Object... values) Execute an internal query with the providednowInSecandtimestampfor theQueryState.static UntypedResultSetexecuteOnceInternalWithPaging(String query, int pageSize, Object... values) Executes with a non-prepared statement using paging.static ConcurrentMap<String,QueryHandler.Prepared> getPrepared(MD5Digest id) static CQLStatementgetStatement(String queryStr, ClientState clientState) static ResultMessage.PreparedgetStoredPreparedStatement(String queryString, String clientKeyspace) static QueryStatestatic QueryOptionsmakeInternalOptions(CQLStatement prepared, Object[] values) static QueryOptionsmakeInternalOptionsWithNowInSec(CQLStatement prepared, long nowInSec, Object[] values) parse(String queryString, QueryState queryState, QueryOptions options) static QueryHandler.PreparedparseAndPrepare(String query, ClientState clientState, boolean isInternal) static QueryHandler.PreparedparseAndPrepare(String query, ClientState clientState, boolean isInternal, boolean measure) static CQLStatement.RawparseStatement(String queryStr) static <T extends CQLStatement.Raw>
TparseStatement(String queryStr, Class<T> klass, String type) static CQLStatementparseStatement(String queryStr, ClientState clientState) voidintpreloadPreparedStatements(int pageSize) prepare(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.prepare(String query, ClientState clientState, Map<String, ByteBuffer> customPayload) static intstatic QueryHandler.PreparedprepareInternal(String query) static UntypedResultSetprocess(String query, ConsistencyLevel cl) static UntypedResultSetprocess(String query, ConsistencyLevel cl, List<ByteBuffer> values) static ResultMessageprocess(String queryString, ConsistencyLevel cl, QueryState queryState, Dispatcher.RequestTime requestTime) process(CQLStatement statement, QueryState state, QueryOptions options, Map<String, ByteBuffer> customPayload, Dispatcher.RequestTime requestTime) process(CQLStatement prepared, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime) processBatch(BatchStatement statement, QueryState state, BatchQueryOptions options, Map<String, ByteBuffer> customPayload, Dispatcher.RequestTime requestTime) processBatch(BatchStatement batch, QueryState queryState, BatchQueryOptions options, Dispatcher.RequestTime requestTime) processPrepared(CQLStatement statement, QueryState state, QueryOptions options, Map<String, ByteBuffer> customPayload, Dispatcher.RequestTime requestTime) processPrepared(CQLStatement statement, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime) processStatement(CQLStatement statement, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime) static UntypedResultSetresultify(String query, PartitionIterator partitions) static UntypedResultSetresultify(String query, RowIterator partition) static ResultMessage.PreparedstorePreparedStatement(String queryString, String keyspace, QueryHandler.Prepared prepared) booleanstatic voidvalidateKey(ByteBuffer key)
-
Field Details
-
CQL_VERSION
-
NEW_PREPARED_STATEMENT_BEHAVIOUR_SINCE_40
-
instance
-
metrics
-
PRELOAD_PREPARED_STATEMENTS_FETCH_SIZE
public static final int PRELOAD_PREPARED_STATEMENTS_FETCH_SIZE- See Also:
-
PREPARED_STATEMENT_CACHE_SIZE_BYTES
public static long PREPARED_STATEMENT_CACHE_SIZE_BYTES
-
-
Method Details
-
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
-
internalQueryState
-
evictPrepared
-
getPreparedStatements
-
getPrepared
- Specified by:
getPreparedin interfaceQueryHandler
-
validateKey
- Throws:
InvalidRequestException
-
processStatement
public ResultMessage processStatement(CQLStatement statement, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime) throws RequestExecutionException, RequestValidationException -
process
public static ResultMessage process(String queryString, ConsistencyLevel cl, QueryState queryState, Dispatcher.RequestTime requestTime) throws RequestExecutionException, RequestValidationException -
parse
- Specified by:
parsein interfaceQueryHandler
-
process
public ResultMessage process(CQLStatement statement, QueryState state, QueryOptions options, Map<String, 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(String queryStr, ClientState clientState) throws RequestValidationException - Throws:
RequestValidationException
-
process
public static UntypedResultSet process(String query, ConsistencyLevel cl) throws RequestExecutionException - Throws:
RequestExecutionException
-
process
public static UntypedResultSet process(String query, ConsistencyLevel cl, List<ByteBuffer> values) throws RequestExecutionException - Throws:
RequestExecutionException
-
makeInternalOptions
-
makeInternalOptionsWithNowInSec
public static QueryOptions makeInternalOptionsWithNowInSec(CQLStatement prepared, long nowInSec, Object[] values) -
prepareInternal
- Throws:
RequestValidationException
-
parseAndPrepare
public static QueryHandler.Prepared parseAndPrepare(String query, ClientState clientState, boolean isInternal) throws RequestValidationException - Throws:
RequestValidationException
-
parseAndPrepare
public static QueryHandler.Prepared parseAndPrepare(String query, ClientState clientState, boolean isInternal, boolean measure) throws RequestValidationException - Throws:
RequestValidationException
-
executeInternal
-
executeAsync
public static Future<UntypedResultSet> executeAsync(InetAddressAndPort address, String query, Object... values) -
execute
public static UntypedResultSet execute(String query, ConsistencyLevel cl, Object... values) throws RequestExecutionException - Throws:
RequestExecutionException
-
executeInternalWithNowInSec
public static UntypedResultSet executeInternalWithNowInSec(String query, long nowInSec, Object... values) -
execute
public static UntypedResultSet execute(String query, ConsistencyLevel cl, QueryState state, Object... values) throws RequestExecutionException - Throws:
RequestExecutionException
-
executeInternalWithPaging
public static UntypedResultSet executeInternalWithPaging(String query, int pageSize, Object... values) -
executeOnceInternalWithPaging
public static UntypedResultSet executeOnceInternalWithPaging(String query, int pageSize, 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
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, String query, 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(long nowInSec, Dispatcher.RequestTime requestTime, String query, 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 Map<DecoratedKey,List<Row>> executeInternalRawWithNow(long nowInSec, String query, 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
-
resultify
-
prepare
public ResultMessage.Prepared prepare(String query, ClientState clientState, Map<String, ByteBuffer> customPayload) throws RequestValidationException- Specified by:
preparein interfaceQueryHandler- Throws:
RequestValidationException
-
useNewPreparedStatementBehaviour
public boolean useNewPreparedStatementBehaviour() -
prepare
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(String queryString, String clientKeyspace) throws InvalidRequestException - Throws:
InvalidRequestException
-
storePreparedStatement
public static ResultMessage.Prepared storePreparedStatement(String queryString, String keyspace, QueryHandler.Prepared prepared) throws InvalidRequestException - Throws:
InvalidRequestException
-
processPrepared
public ResultMessage processPrepared(CQLStatement statement, QueryState state, QueryOptions options, Map<String, 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, Map<String, 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(String queryStr, ClientState clientState) throws RequestValidationException - Throws:
RequestValidationException
-
parseStatement
public static <T extends CQLStatement.Raw> T parseStatement(String queryStr, Class<T> klass, String type) throws SyntaxException - Throws:
SyntaxException
-
parseStatement
- Throws:
SyntaxException
-
clearInternalStatementsCache
public static void clearInternalStatementsCache()Clear our internal statmeent cache for test purposes. -
clearPreparedStatementsCache
public static void clearPreparedStatementsCache()
-