docstr: Execute a SQL query.
  ---
  post:
    summary: Execute a SQL query
    requestBody:
      description: SQL query and params
      required: true
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ExecutePayloadSchema'
    responses:
      200:
        description: Query execution result
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/QueryExecutionResponseSchema'
      202:
        description: Query execution result, query still running
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/QueryExecutionResponseSchema'
      400:
        $ref: '#/components/responses/400'
      401:
        $ref: '#/components/responses/401'
      403:
        $ref: '#/components/responses/403'
      404:
        $ref: '#/components/responses/404'
      500:
        $ref: '#/components/responses/500'
docstr_tok: ["Execute","a","SQL","query",".","--","-","post",":","summary",":","Execute","a","SQL","query","requestBody",":","description",":","SQL","query","and","params","required",":","true","content",":","application\/json",":","schema",":","$","ref",":","'","#","\/components\/schemas\/ExecutePayloadSchema'","responses",":","200",":","description",":","Query","execution","result","content",":","application\/json",":","schema",":","$","ref",":","'","#","\/components\/schemas\/QueryExecutionResponseSchema'","202",":","description",":","Query","execution","result",",","query","still","running","content",":","application\/json",":","schema",":","$","ref",":","'","#","\/components\/schemas\/QueryExecutionResponseSchema'","400",":","$","ref",":","'","#","\/components\/responses\/400'","401",":","$","ref",":","'","#","\/components\/responses\/401'","403",":","$","ref",":","'","#","\/components\/responses\/403'","404",":","$","ref",":","'","#","\/components\/responses\/404'","500",":","$","ref",":","'","#","\/components\/responses\/500","'"]
code: def execute_sql_query(self) -> FlaskResponse:
      """Execute a SQL query.
      ---
      post:
        summary: Execute a SQL query
        requestBody:
          description: SQL query and params
          required: true
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExecutePayloadSchema'
        responses:
          200:
            description: Query execution result
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/QueryExecutionResponseSchema'
          202:
            description: Query execution result, query still running
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/QueryExecutionResponseSchema'
          400:
            $ref: '#/components/responses/400'
          401:
            $ref: '#/components/responses/401'
          403:
            $ref: '#/components/responses/403'
          404:
            $ref: '#/components/responses/404'
          500:
            $ref: '#/components/responses/500'
      """
      try:
          self.execute_model_schema.load(request.json)
      except ValidationError as error:
          return self.response_400(message=error.messages)
  
      try:
          log_params = {
              "user_agent": cast(
                  Optional[str], request.headers.get("USER_AGENT")
              )
          }
          execution_context = SqlJsonExecutionContext(request.json)
          command = self._create_sql_json_command(
              execution_context, log_params
          )
          command_result: CommandResult = command.run()
  
          response_status = (
              202
              if command_result["status"]
              == SqlJsonExecutionStatus.QUERY_IS_RUNNING
              else 200
          )
          # return the execution result without special encoding
          return json_success(
              command_result["payload"], response_status
          )
      except SqlLabException as ex:
          payload = {"errors": [ex.to_dict()]}
  
          response_status = (
              403
              if isinstance(ex, QueryIsForbiddenToAccessException)
              else ex.status
          )
          return self.response(response_status, **payload)
  
imports: import logging
  from typing import Any, cast, Optional
  from urllib import parse
  import simplejson
  import sqlparse
  from flask import request, Response
  from flask_appbuilder import permission_name
  from flask_appbuilder.api import expose, protect, rison, safe
  from flask_appbuilder.models.sqla.interface import SQLAInterface
  from marshmallow import ValidationError
  from superset import app, is_feature_enabled
  from superset.commands.sql_lab.estimate import QueryEstimationCommand
  from superset.commands.sql_lab.execute import CommandResult, ExecuteSqlCommand
  from superset.commands.sql_lab.export import SqlResultExportCommand
  from superset.commands.sql_lab.results import SqlExecutionResultsCommand
  from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP
  from superset.daos.database import DatabaseDAO
  from superset.daos.query import QueryDAO
  from superset.extensions import event_logger
  from superset.jinja_context import get_template_processor
  from superset.models.sql_lab import Query
  from superset.sql_lab import get_sql_results
  from superset.sqllab.command_status import SqlJsonExecutionStatus
  from superset.sqllab.exceptions import QueryIsForbiddenToAccessException, SqlLabException
  from superset.sqllab.execution_context_convertor import ExecutionContextConvertor
  from superset.sqllab.query_render import SqlQueryRenderImpl
  from superset.sqllab.schemas import EstimateQueryCostSchema, ExecutePayloadSchema, FormatQueryPayloadSchema, QueryExecutionResponseSchema, sql_lab_get_results_schema, SQLLabBootstrapSchema
  from superset.sqllab.sql_json_executer import ASynchronousSqlJsonExecutor, SqlJsonExecutor, SynchronousSqlJsonExecutor
  from superset.sqllab.sqllab_execution_context import SqlJsonExecutionContext
  from superset.sqllab.utils import bootstrap_sqllab_data
  from superset.sqllab.validators import CanAccessQueryValidatorImpl
  from superset.superset_typing import FlaskResponse
  from superset.utils import core
  from superset.views.base import CsvResponse, generate_download_headers, json_success
  from superset.views.base_api import BaseSupersetApi, requires_json, statsd_metrics
label_desc: Use image node_id 6 for calling the SqlLabRestApi obj's underlying member method code with example usage: obj.execute_sql_query() and returns: json_success, self, self