Class DruidPlanner

java.lang.Object
org.apache.druid.sql.calcite.planner.DruidPlanner
All Implemented Interfaces:
Closeable, AutoCloseable

public class DruidPlanner extends Object implements Closeable
Druid SQL planner. Wraps the underlying Calcite planner with Druid-specific actions around resource validation and conversion of the Calcite logical plan into a Druid native query.

The planner is designed to use once: it makes one trip through its lifecycle defined as:

start --> validate [--> prepare] --> plan

  • Method Details

    • validate

      public void validate()
      Validates a SQL query and populates PlannerContext.getResourceActions().
    • prepare

      public PrepareResult prepare()
      Prepare a SQL query for execution, including some initial parsing and validation and any dynamic parameter type resolution, to support prepared statements via JDBC.

      Prepare reuses the validation done in validate() which must be called first.

      A query can be prepared on a data source without having permissions on that data source. This odd state of affairs is necessary because DruidViewMacro prepares a view while having no information about the user of that view.

    • authorize

      public DruidPlanner.AuthResult authorize(Function<Set<ResourceAction>,AuthorizationResult> authorizer, Set<ResourceAction> extraActions)
      Authorizes the statement. Done within the planner to enforce the authorization step within the planner's state machine.
      Parameters:
      authorizer - a function produces AuthorizationResult based on resource actions.
      extraActions - set of additional resource actions beyond those inferred from the query itself. Specifically, the set of context keys to authorize.
      Returns:
      the return value from the authorizer
    • plan

      public PlannerResult plan()
      Plan an SQL query for execution, returning a PlannerResult which can be used to actually execute the query.

      Ideally, the query can be planned into a native Druid query, but will fall-back to bindable convention if this is not possible.

      Planning reuses the validation done in validate() which must be called first.

    • getPlannerContext

      public PlannerContext getPlannerContext()
    • prepareResult

      public PrepareResult prepareResult()
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • translateException

      public static DruidException translateException(Exception e)