Search in sources :

Example 1 with AbstractSqlHandler

use of org.apache.drill.exec.planner.sql.handlers.AbstractSqlHandler in project drill by apache.

the class DrillSqlWorker method getQueryPlan.

/**
   * Converts sql query string into query physical plan.
   *
   * @param context query context
   * @param sql sql query
   * @param textPlan text plan
   * @return query physical plan
   */
private static PhysicalPlan getQueryPlan(QueryContext context, String sql, Pointer<String> textPlan) throws ForemanSetupException {
    final SqlConverter parser = new SqlConverter(context);
    injector.injectChecked(context.getExecutionControls(), "sql-parsing", ForemanSetupException.class);
    final SqlNode sqlNode = parser.parse(sql);
    final AbstractSqlHandler handler;
    final SqlHandlerConfig config = new SqlHandlerConfig(context, parser);
    switch(sqlNode.getKind()) {
        case EXPLAIN:
            handler = new ExplainHandler(config, textPlan);
            break;
        case SET_OPTION:
            handler = new SetOptionHandler(context);
            break;
        case OTHER:
            if (sqlNode instanceof SqlCreateTable) {
                handler = ((DrillSqlCall) sqlNode).getSqlHandler(config, textPlan);
                break;
            }
            if (sqlNode instanceof DrillSqlCall) {
                handler = ((DrillSqlCall) sqlNode).getSqlHandler(config);
                break;
            }
        // fallthrough
        default:
            handler = new DefaultSqlHandler(config, textPlan);
    }
    try {
        return handler.getPlan(sqlNode);
    } catch (ValidationException e) {
        String errorMessage = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
        throw UserException.validationError(e).message(errorMessage).build(logger);
    } catch (AccessControlException e) {
        throw UserException.permissionError(e).build(logger);
    } catch (SqlUnsupportedException e) {
        throw UserException.unsupportedError(e).build(logger);
    } catch (IOException | RelConversionException e) {
        throw new QueryInputException("Failure handling SQL.", e);
    }
}
Also used : DefaultSqlHandler(org.apache.drill.exec.planner.sql.handlers.DefaultSqlHandler) ExplainHandler(org.apache.drill.exec.planner.sql.handlers.ExplainHandler) ValidationException(org.apache.calcite.tools.ValidationException) SetOptionHandler(org.apache.drill.exec.planner.sql.handlers.SetOptionHandler) AccessControlException(org.apache.hadoop.security.AccessControlException) SqlHandlerConfig(org.apache.drill.exec.planner.sql.handlers.SqlHandlerConfig) IOException(java.io.IOException) SqlCreateTable(org.apache.drill.exec.planner.sql.parser.SqlCreateTable) RelConversionException(org.apache.calcite.tools.RelConversionException) AbstractSqlHandler(org.apache.drill.exec.planner.sql.handlers.AbstractSqlHandler) SqlUnsupportedException(org.apache.drill.exec.work.foreman.SqlUnsupportedException) DrillSqlCall(org.apache.drill.exec.planner.sql.parser.DrillSqlCall) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

IOException (java.io.IOException)1 SqlNode (org.apache.calcite.sql.SqlNode)1 RelConversionException (org.apache.calcite.tools.RelConversionException)1 ValidationException (org.apache.calcite.tools.ValidationException)1 AbstractSqlHandler (org.apache.drill.exec.planner.sql.handlers.AbstractSqlHandler)1 DefaultSqlHandler (org.apache.drill.exec.planner.sql.handlers.DefaultSqlHandler)1 ExplainHandler (org.apache.drill.exec.planner.sql.handlers.ExplainHandler)1 SetOptionHandler (org.apache.drill.exec.planner.sql.handlers.SetOptionHandler)1 SqlHandlerConfig (org.apache.drill.exec.planner.sql.handlers.SqlHandlerConfig)1 DrillSqlCall (org.apache.drill.exec.planner.sql.parser.DrillSqlCall)1 SqlCreateTable (org.apache.drill.exec.planner.sql.parser.SqlCreateTable)1 SqlUnsupportedException (org.apache.drill.exec.work.foreman.SqlUnsupportedException)1 AccessControlException (org.apache.hadoop.security.AccessControlException)1