docstr: Execute command as an async query.
docstr_tok: ["Execute","command","as","an","async","query","."]
code: def _run_async(
      self, form_data: dict[str, Any], command: ChartDataCommand
  ) -> Response:
      """
      Execute command as an async query.
      """
      # First, look for the chart query results in the cache.
      with contextlib.suppress(ChartDataCacheLoadError):
          result = command.run(force_cached=True)
          if result is not None:
              return self._send_chart_response(result)
      # Otherwise, kick off a background job to run the chart query.
      # Clients will either poll or be notified of query completion,
      # at which point they will call the /data/<cache_key> endpoint
      # to retrieve the results.
      async_command = CreateAsyncChartDataJobCommand()
      try:
          async_command.validate(request)
      except AsyncQueryTokenException:
          return self.response_401()
  
      result = async_command.run(form_data, get_user_id())
      return self.response(202, **result)
  
imports: from __future__ import annotations
  import contextlib
  import json
  import logging
  from typing import Any, TYPE_CHECKING
  import simplejson
  from flask import current_app, g, make_response, request, Response
  from flask_appbuilder.api import expose, protect
  from flask_babel import gettext
  from marshmallow import ValidationError
  from superset import is_feature_enabled, security_manager
  from superset.async_events.async_query_manager import AsyncQueryTokenException
  from superset.charts.api import ChartRestApi
  from superset.charts.data.query_context_cache_loader import QueryContextCacheLoader
  from superset.charts.post_processing import apply_post_process
  from superset.charts.schemas import ChartDataQueryContextSchema
  from superset.commands.chart.data.create_async_job_command import CreateAsyncChartDataJobCommand
  from superset.commands.chart.data.get_data_command import ChartDataCommand
  from superset.commands.chart.exceptions import ChartDataCacheLoadError, ChartDataQueryFailedError
  from superset.common.chart_data import ChartDataResultFormat, ChartDataResultType
  from superset.connectors.sqla.models import BaseDatasource
  from superset.daos.exceptions import DatasourceNotFound
  from superset.exceptions import QueryObjectValidationError
  from superset.extensions import event_logger
  from superset.models.sql_lab import Query
  from superset.utils.core import create_zip, get_user_id, json_int_dttm_ser
  from superset.views.base import CsvResponse, generate_download_headers, XlsxResponse
  from superset.views.base_api import statsd_metrics
label_desc: Use image node_id 4 for calling the ChartDataRestApi obj's underlying member method code with example usage: obj._run_async(form_data, command) and returns: self, self, self