Package org.apache.druid.server
Class QueryLifecycle
- java.lang.Object
-
- org.apache.druid.server.QueryLifecycle
-
public class QueryLifecycle extends Object
Class that helps a Druid server (broker, historical, etc) manage the lifecycle of a query that it is handling. It ensures that a query goes through the following stages, in the proper order:- Initialization (
initialize(Query)) - Authorization (
authorize(HttpServletRequest) - Execution (
execute() - Logging (
emitLogsAndMetrics(Throwable, String, long)
- Initialization (
-
-
Constructor Summary
Constructors Constructor Description QueryLifecycle(org.apache.druid.query.QueryToolChestWarehouse warehouse, org.apache.druid.query.QuerySegmentWalker texasRanger, org.apache.druid.query.GenericQueryMetricsFactory queryMetricsFactory, org.apache.druid.java.util.emitter.service.ServiceEmitter emitter, RequestLogger requestLogger, AuthorizerMapper authorizerMapper, org.apache.druid.query.DefaultQueryConfig defaultQueryConfig, AuthConfig authConfig, long startMs, long startNs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Accessauthorize(javax.servlet.http.HttpServletRequest req)Authorize the query.Accessauthorize(AuthenticationResult authenticationResult)Authorize the query using the authentication result.voidemitLogsAndMetrics(Throwable e, String remoteAddress, long bytesWritten)Emit logs and metrics for this query.<T> QueryResponse<T>execute()Execute the query.org.apache.druid.query.Query<?>getQuery()StringgetQueryId()org.apache.druid.query.QueryToolChestgetToolChest()voidinitialize(org.apache.druid.query.Query<?> baseQuery)Initializes this object to execute a specific query.com.fasterxml.jackson.databind.ObjectWriternewOutputWriter(QueryResource.ResourceIOReaderWriter ioReaderWriter)<T> QueryResponse<T>runSimple(org.apache.druid.query.Query<T> query, AuthenticationResult authenticationResult, Access authorizationResult)For callers who have already authorized their query, and where simplicity is desired over flexibility.StringthreadName(String currThreadName)
-
-
-
Constructor Detail
-
QueryLifecycle
public QueryLifecycle(org.apache.druid.query.QueryToolChestWarehouse warehouse, org.apache.druid.query.QuerySegmentWalker texasRanger, org.apache.druid.query.GenericQueryMetricsFactory queryMetricsFactory, org.apache.druid.java.util.emitter.service.ServiceEmitter emitter, RequestLogger requestLogger, AuthorizerMapper authorizerMapper, org.apache.druid.query.DefaultQueryConfig defaultQueryConfig, AuthConfig authConfig, long startMs, long startNs)
-
-
Method Detail
-
runSimple
public <T> QueryResponse<T> runSimple(org.apache.druid.query.Query<T> query, AuthenticationResult authenticationResult, Access authorizationResult)
For callers who have already authorized their query, and where simplicity is desired over flexibility. This method does it all in one call. Logs and metrics are emitted when the Sequence is either fully iterated or throws an exception.- Parameters:
query- the queryauthenticationResult- authentication result indicating identity of the requesterauthorizationResult- authorization result of requester- Returns:
- results
-
initialize
public void initialize(org.apache.druid.query.Query<?> baseQuery)
Initializes this object to execute a specific query. Does not actually execute the query.- Parameters:
baseQuery- the query
-
authorize
public Access authorize(javax.servlet.http.HttpServletRequest req)
Authorize the query. Will return an Access object denoting whether the query is authorized or not.- Parameters:
req- HTTP request object of the request. If provided, the auth-related fields in the HTTP request will be automatically set.- Returns:
- authorization result
-
authorize
public Access authorize(AuthenticationResult authenticationResult)
Authorize the query using the authentication result. Will return an Access object denoting whether the query is authorized or not. This method is to be used by the grpc-query-extension.- Parameters:
authenticationResult- authentication result indicating identity of the requester- Returns:
- authorization result of requester
-
execute
public <T> QueryResponse<T> execute()
Execute the query. Can only be called if the query has been authorized. Note that query logs and metrics will not be emitted automatically when the Sequence is fully iterated. It is the caller's responsibility to callemitLogsAndMetrics(Throwable, String, long)to emit logs and metrics.- Returns:
- result sequence and response context
-
emitLogsAndMetrics
public void emitLogsAndMetrics(@Nullable Throwable e, @Nullable String remoteAddress, long bytesWritten)
Emit logs and metrics for this query.- Parameters:
e- exception that occurred while processing this queryremoteAddress- remote address, for logging; or null if unknownbytesWritten- number of bytes written; will become a query/bytes metric if >= 0
-
getQuery
@Nullable public org.apache.druid.query.Query<?> getQuery()
-
getQueryId
public String getQueryId()
-
newOutputWriter
public com.fasterxml.jackson.databind.ObjectWriter newOutputWriter(QueryResource.ResourceIOReaderWriter ioReaderWriter)
-
getToolChest
public org.apache.druid.query.QueryToolChest getToolChest()
-
-