Interface SqlEngine

All Known Implementing Classes:
NativeSqlEngine, ViewSqlEngine

public interface SqlEngine
Engine for running SQL queries.
  • Method Details

    • name

      String name()
      Name of this engine. Appears in user-visible messages.
    • featureAvailable

      boolean featureAvailable(EngineFeature feature)
      Whether a feature applies to this engine or not. Most callers should use PlannerContext.featureAvailable(EngineFeature) instead, which also checks feature flags in context parameters.
    • validateContext

      void validateContext(Map<String,Object> queryContext)
      Validates a provided query context. Returns quietly if the context is OK; throws ValidationException if the context has a problem.
    • resultTypeForSelect

      org.apache.calcite.rel.type.RelDataType resultTypeForSelect(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.rel.type.RelDataType validatedRowType, Map<String,Object> queryContext)
      SQL row type that would be emitted by the QueryMaker from buildQueryMakerForSelect(org.apache.calcite.rel.RelRoot, org.apache.druid.sql.calcite.planner.PlannerContext). Called for SELECT. Not called for EXPLAIN, which is handled by the planner itself.
      Parameters:
      typeFactory - type factory
      validatedRowType - row type from Calcite's validator
      queryContext - query context, in case that affects the result type
    • resultTypeForInsert

      org.apache.calcite.rel.type.RelDataType resultTypeForInsert(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.rel.type.RelDataType validatedRowType, Map<String,Object> queryContext)
      SQL row type that would be emitted by the QueryMaker from buildQueryMakerForInsert(org.apache.druid.sql.destination.IngestDestination, org.apache.calcite.rel.RelRoot, org.apache.druid.sql.calcite.planner.PlannerContext). Called for INSERT and REPLACE. Not called for EXPLAIN, which is handled by the planner itself.
      Parameters:
      typeFactory - type factory
      validatedRowType - row type from Calcite's validator
      queryContext - query context, in case that affects the result type
    • buildQueryMakerForSelect

      QueryMaker buildQueryMakerForSelect(org.apache.calcite.rel.RelRoot relRoot, PlannerContext plannerContext) throws org.apache.calcite.tools.ValidationException
      Create a QueryMaker for a SELECT query.
      Parameters:
      relRoot - planned and validated rel
      plannerContext - context for this query
      Returns:
      an executor for the provided query
      Throws:
      org.apache.calcite.tools.ValidationException - if this engine cannot build an executor for the provided query
    • buildQueryMakerForInsert

      QueryMaker buildQueryMakerForInsert(IngestDestination destination, org.apache.calcite.rel.RelRoot relRoot, PlannerContext plannerContext) throws org.apache.calcite.tools.ValidationException
      Create a QueryMaker for an INSERT ... SELECT query.
      Parameters:
      destination - destination for the INSERT portion of the query
      relRoot - planned and validated rel for the SELECT portion of the query
      plannerContext - context for this query
      Returns:
      an executor for the provided query
      Throws:
      org.apache.calcite.tools.ValidationException - if this engine cannot build an executor for the provided query
    • initContextMap

      default void initContextMap(Map<String,Object> contextMap)
      Enables the engine to make changes to the Context.
    • getSqlStatementFactory

      SqlStatementFactory getSqlStatementFactory()
      Returns a SqlStatementFactory which uses this engine to create statements.
    • getQueries

      default GetQueriesResponse getQueries(boolean selfOnly, boolean includeComplete, AuthenticationResult authenticationResult, AuthorizationResult stateReadAuthorization)
      Returns a list of QueryInfo containing the currently running queries using this engine. Returns an empty list if the operation is not supported.
      Parameters:
      selfOnly - whether to only include queries running on this server. If false, this server should contact all other servers to build a full list of all running queries.
      includeComplete - whether to include completed queries in the response. The number of completed queries returned is determined by engine-specific retention settings.
      authenticationResult - implementations should use this for filtering the list of visible queries
      stateReadAuthorization - authorization for the STATE READ resource. If this is authorized, implementations should allow all queries to be visible
    • getQueryReport

      @Nullable default GetQueryReportResponse getQueryReport(String sqlQueryId, boolean selfOnly, AuthenticationResult authenticationResult, AuthorizationResult stateReadAuthorization)
      Retrieves the report for a query, if available.
      Parameters:
      sqlQueryId - SQL query ID to retrieve the report for
      selfOnly - whether to only include queries running on this server. If false, this server should contact all other servers to find this query, if necessary.
      authenticationResult - implementations should use this to determine if a query should be visible to a user
      stateReadAuthorization - authorization for the STATE READ resource. If this is authorized, implementations should allow all queries to be visible
    • cancelQuery

      default void cancelQuery(PlannerContext plannerContext, QueryScheduler queryScheduler)
      Cancels a currently running query given the PlannerContext for the query.