code: def get_sql_results(  # pylint: disable=too-many-arguments
      query_id: int,
      rendered_query: str,
      return_results: bool = True,
      store_results: bool = False,
      username: Optional[str] = None,
      start_time: Optional[float] = None,
      expand_data: bool = False,
      log_params: Optional[dict[str, Any]] = None,
  ) -> Optional[dict[str, Any]]:
      """Executes the sql query returns the results."""
      with override_user(security_manager.find_user(username)):
          try:
              return execute_sql_statements(
                  query_id,
                  rendered_query,
                  return_results,
                  store_results,
                  start_time=start_time,
                  expand_data=expand_data,
                  log_params=log_params,
              )
          except Exception as ex:  # pylint: disable=broad-except
              logger.debug("Query %d: %s", query_id, ex)
              stats_logger.incr("error_sqllab_unhandled")
              query = get_query(query_id)
              return handle_query_error(ex, query)
  
imports: import dataclasses
  import logging
  import uuid
  from contextlib import closing
  from datetime import datetime
  from sys import getsizeof
  from typing import Any, cast, Optional, Union
  import backoff
  import msgpack
  import simplejson
  from celery.exceptions import SoftTimeLimitExceeded
  from flask_babel import gettext
  from superset import app, db, is_feature_enabled, results_backend, results_backend_use_msgpack, security_manager
  from superset.common.db_query_status import QueryStatus
  from superset.constants import QUERY_CANCEL_KEY, QUERY_EARLY_CANCEL_KEY
  from superset.dataframe import df_to_records
  from superset.db_engine_specs import BaseEngineSpec
  from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
  from superset.exceptions import SupersetErrorException, SupersetErrorsException
  from superset.extensions import celery_app
  from superset.models.core import Database
  from superset.models.sql_lab import Query
  from superset.result_set import SupersetResultSet
  from superset.sql_parse import CtasMethod, insert_rls_as_subquery, insert_rls_in_predicate, ParsedQuery
  from superset.sqllab.limiting_factor import LimitingFactor
  from superset.sqllab.utils import write_ipc_buffer
  from superset.utils.core import json_iso_dttm_ser, override_user, QuerySource, zlib_compress
  from superset.utils.dates import now_as_float
  from superset.utils.decorators import stats_timing
label_desc: Use image node_id 5 for calling a global function with example usage: get_sql_results(query_id, rendered_query, return_results, store_results, username, start_time, expand_data, log_params) and returns: execute_sql_statements, handle_query_error