Package org.apache.druid.sql
Class AbstractStatement
java.lang.Object
org.apache.druid.sql.AbstractStatement
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
DirectStatement,PreparedStatement
Represents a SQL statement either for preparation or execution.
A statement is given by a lifecycle context and the statement
to execute. See derived classes for actions. Closing the statement
emits logs and metrics for the statement.
The query context has a complex lifecycle. It is provided in the SQL query
request (SqlQueryPlus), then modified during planning. The
user-provided copy is immutable: a copy is made in this class, and that
copy is the one which the planner adjusts as planning proceeds. Context
authorization, if enabled, is done based on the user-provided context keys,
not the internally-defined context.
-
Field Summary
FieldsModifier and TypeFieldDescriptionImmutable set of query context keys needs to be authorization checked.protected DruidPlanner.AuthResultprotected PlannerHookprotected PlannerContextMutable copy of the query context provided by the user, can be modified during planning.protected final SqlQueryPlusprotected final SqlExecutionReporterprotected final SqlToolbox -
Constructor Summary
ConstructorsConstructorDescriptionAbstractStatement(SqlToolbox sqlToolbox, SqlQueryPlus queryPlus, String remoteAddress) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidauthorize(DruidPlanner planner, Function<Set<ResourceAction>, AuthorizationResult> authorizer) Authorize the query using the authorizer provided, and an option to authorize context variables as well as query resources.protected Function<Set<ResourceAction>,AuthorizationResult> Returns an authorizer that can provide authorization result given a set of required resource actions and authentication result.voidclose()Releases resources and emits logs and metrics as defined the associated reporter.voidCloses the statement without reporting metrics.voidConvenience method to close the statement and report an error associated with the statement.context()Returns the context as it evolves during planning.query()reporter()Return the datasource and table resources for this statement.voidsetHook(PlannerHook hook) Set the hook which can capture planner artifacts during planning.protected voidvalidate(DruidPlanner planner) Validate SQL query and authorize against any datasources or views which will take part in the query.
-
Field Details
-
sqlToolbox
-
queryPlus
-
reporter
-
authContextKeys
Immutable set of query context keys needs to be authorization checked. -
queryContext
Mutable copy of the query context provided by the user, can be modified during planning. Modifications are possible up to the point where the context is passed to a native query. At that point, the context becomes immutable and can be changed only by copying the entire native query. -
plannerContext
-
authResult
-
hook
-
-
Constructor Details
-
AbstractStatement
-
-
Method Details
-
sqlQueryId
-
context
Returns the context as it evolves during planning. In general, this copy will not be the same as the one fromgetQuery().context(). -
setHook
Set the hook which can capture planner artifacts during planning. Primarily used for testing. Defaults to a "no op" hook that does nothing. -
validate
Validate SQL query and authorize against any datasources or views which will take part in the query. Must be called by the API methods, not directly. -
authorize
protected void authorize(DruidPlanner planner, Function<Set<ResourceAction>, AuthorizationResult> authorizer) Authorize the query using the authorizer provided, and an option to authorize context variables as well as query resources. -
authorizer
Returns an authorizer that can provide authorization result given a set of required resource actions and authentication result. -
resources
Return the datasource and table resources for this statement. -
allResources
-
query
-
reporter
-
close
public void close()Releases resources and emits logs and metrics as defined the associated reporter.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
closeQuietly
public void closeQuietly()Closes the statement without reporting metrics. -
closeWithError
Convenience method to close the statement and report an error associated with the statement. Same as calling:stmt.reporter().failed(e); stmt.close();
-