Class PlannerContext

java.lang.Object
org.apache.druid.sql.calcite.planner.PlannerContext

public class PlannerContext extends Object
Like PlannerConfig, but that has static configuration and this class contains dynamic, per-query configuration. Additional Druid-specific static configuration resides in the PlannerToolbox class.
  • Field Details

  • Method Details

    • create

      public static PlannerContext create(PlannerToolbox plannerToolbox, String sql, org.apache.calcite.sql.SqlNode sqlNode, SqlEngine engine, Set<String> authContextKeys, Map<String,Object> queryContext, PlannerHook hook)
    • getJoinAlgorithm

      public static JoinAlgorithm getJoinAlgorithm(QueryContext queryContext)
      Returns the join algorithm specified in a query context.
    • getJoinAlgorithm

      public static JoinAlgorithm getJoinAlgorithm(Map<String,Object> queryContext)
      Returns the join algorithm specified in a query context.
    • getPlannerToolbox

      public PlannerToolbox getPlannerToolbox()
    • getExprMacroTable

      public ExprMacroTable getExprMacroTable()
    • getExpressionParser

      public ExpressionParser getExpressionParser()
    • parseExpression

      public Expr parseExpression(String expr)
    • getJsonMapper

      public com.fasterxml.jackson.databind.ObjectMapper getJsonMapper()
    • getPlannerConfig

      public PlannerConfig getPlannerConfig()
    • getLocalNow

      public org.joda.time.DateTime getLocalNow()
    • getTimeZone

      public org.joda.time.DateTimeZone getTimeZone()
    • getJoinableFactoryWrapper

      public JoinableFactoryWrapper getJoinableFactoryWrapper()
    • getSchemaResourceType

      @Nullable public String getSchemaResourceType(String schema, String resourceName)
    • addLookupToLoad

      public void addLookupToLoad(String lookupName)
      Adds the given lookup name to the lookup loading spec.
    • getLookupLoadingSpec

      public LookupLoadingSpec getLookupLoadingSpec()
      Lookup loading spec used if this context corresponds to an MSQ task.
    • queryContextMap

      public Map<String,Object> queryContextMap()
      Return the query context as a mutable map. Use this form when modifying the context during planning.
    • authContextKeys

      public Set<String> authContextKeys()
      Return an immutable set of context keys need to be authorization checked, this usually comes from user-provided query context, including SET parameters.
    • queryContext

      public QueryContext queryContext()
      Return the query context as an immutable object. Use this form when querying the context as it provides type-safe accessors.
    • isStringifyArrays

      public boolean isStringifyArrays()
    • isUseBoundsAndSelectors

      public boolean isUseBoundsAndSelectors()
      Whether we should use BoundDimFilter and SelectorDimFilter (true) or RangeFilter, EqualityFilter, and NullFilter (false). Can be overriden by the context parameter CTX_SQL_USE_BOUNDS_AND_SELECTORS.
    • isUseExtractionFns

      public boolean isUseExtractionFns()
      Whether we should use ExtractionFn in planning.
    • isUseLegacyInFilter

      public boolean isUseLegacyInFilter()
      Whether we should use InDimFilter (true) or TypedInFilter (false).
    • isPullUpLookup

      public boolean isPullUpLookup()
      Whether we should use AggregatePullUpLookupRule to pull LOOKUP functions on injective lookups up above a GROUP BY.
    • isReverseLookup

      public boolean isReverseLookup()
      Whether we should use ReverseLookupRule to reduce the LOOKUP function, and whether we should set the "optimize" flag on RegisteredLookupExtractionFn.
    • isUseGranularity

      public boolean isUseGranularity()
      Whether we should use granularities other than Granularities.ALL when planning queries. This is provided mainly so it can be set to false when running SQL queries on non-time-ordered tables, which do not support any other granularities.
    • getParameters

      public List<org.apache.calcite.avatica.remote.TypedValue> getParameters()
    • getAuthenticationResult

      public AuthenticationResult getAuthenticationResult()
    • getJoinAlgorithm

      public JoinAlgorithm getJoinAlgorithm()
    • getSql

      public String getSql()
    • getSqlNode

      public org.apache.calcite.sql.SqlNode getSqlNode()
    • getPlannerHook

      public PlannerHook getPlannerHook()
    • getSqlQueryId

      public String getSqlQueryId()
    • getNativeQueryIds

      public CopyOnWriteArrayList<String> getNativeQueryIds()
    • addNativeQueryId

      public void addNativeQueryId(String queryId)
    • getPlanningError

      @Nullable public String getPlanningError()
    • setPlanningError

      public void setPlanningError(String formatText, Object... arguments)
      Sets the planning error in the context that will be shown to the user if the SQL query cannot be translated to a native query. This error is often a hint and thus should be phrased as such. Also, the final plan can be very different from SQL that user has written. So again, the error should be phrased to indicate this gap clearly.
    • createDataContext

      public org.apache.calcite.DataContext createDataContext(org.apache.calcite.adapter.java.JavaTypeFactory typeFactory, List<org.apache.calcite.avatica.remote.TypedValue> parameters)
    • getAuthorizationResult

      public AuthorizationResult getAuthorizationResult()
    • setParameters

      public void setParameters(List<org.apache.calcite.avatica.remote.TypedValue> parameters)
    • setAuthenticationResult

      public void setAuthenticationResult(AuthenticationResult authenticationResult)
    • setAuthorizationResult

      public void setAuthorizationResult(AuthorizationResult access)
    • getResourceActions

      public Set<ResourceAction> getResourceActions()
    • setResourceActions

      public void setResourceActions(Set<ResourceAction> resourceActions)
    • setQueryMaker

      public void setQueryMaker(QueryMaker queryMaker)
    • addAllToQueryContext

      public void addAllToQueryContext(Map<String,Object> toAdd)
      Add additional query context parameters, overriding any existing values.
    • getEngine

      public SqlEngine getEngine()
    • featureAvailable

      public boolean featureAvailable(EngineFeature feature)
      Checks if the current SqlEngine supports a particular feature.

      When executing a specific query, use this method instead of SqlEngine.featureAvailable(EngineFeature) because it also verifies feature flags.

    • getQueryMaker

      public QueryMaker getQueryMaker()
    • getJoinExpressionVirtualColumnRegistry

      public VirtualColumnRegistry getJoinExpressionVirtualColumnRegistry()
    • setJoinExpressionVirtualColumnRegistry

      public void setJoinExpressionVirtualColumnRegistry(VirtualColumnRegistry joinExpressionVirtualColumnRegistry)
    • getExplainAttributes

      public ExplainAttributes getExplainAttributes()
    • setExplainAttributes

      public void setExplainAttributes(ExplainAttributes explainAttributes)
    • getLookup

      public LookupExtractor getLookup(String lookupName)
      Retrieve a named LookupExtractor.
    • dispatchHook

      public <T> void dispatchHook(DruidHook.HookKey<T> key, T object)