Class AbstractStatement

java.lang.Object
org.apache.druid.sql.AbstractStatement
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
DirectStatement, PreparedStatement

public abstract class AbstractStatement extends Object implements Closeable
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 Details

    • sqlToolbox

      protected final SqlToolbox sqlToolbox
    • queryPlus

      protected final SqlQueryPlus queryPlus
    • reporter

      protected final SqlExecutionReporter reporter
    • authContextKeys

      protected final Set<String> authContextKeys
      Immutable set of query context keys needs to be authorization checked.
    • queryContext

      protected final Map<String,Object> 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

      protected PlannerContext plannerContext
    • authResult

      protected DruidPlanner.AuthResult authResult
    • hook

      protected PlannerHook hook
  • Constructor Details

  • Method Details

    • sqlQueryId

      public String sqlQueryId()
    • context

      public Map<String,Object> context()
      Returns the context as it evolves during planning. In general, this copy will not be the same as the one from getQuery().context().
    • setHook

      public void setHook(PlannerHook hook)
      Set the hook which can capture planner artifacts during planning. Primarily used for testing. Defaults to a "no op" hook that does nothing.
    • validate

      protected void validate(DruidPlanner planner)
      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

      protected Function<Set<ResourceAction>,AuthorizationResult> authorizer()
      Returns an authorizer that can provide authorization result given a set of required resource actions and authentication result.
    • resources

      public Set<ResourceAction> resources()
      Return the datasource and table resources for this statement.
    • allResources

      public Set<ResourceAction> allResources()
    • query

      public SqlQueryPlus query()
    • reporter

      public SqlExecutionReporter reporter()
    • close

      public void close()
      Releases resources and emits logs and metrics as defined the associated reporter.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • closeQuietly

      public void closeQuietly()
      Closes the statement without reporting metrics.
    • closeWithError

      public void closeWithError(Throwable e)
      Convenience method to close the statement and report an error associated with the statement. Same as calling: stmt.reporter().failed(e); stmt.close();