class_docstr: Execute an UNLOAD command to s3 as a CSV with headers.
  
  .. seealso::
      For more information on how to use this operator, take a look at the guide:
      :ref:`howto/operator:RedshiftToS3Operator`
  
  :param s3_bucket: reference to a specific S3 bucket
  :param s3_key: reference to a specific S3 key. If ``table_as_file_name`` is set
      to False, this param must include the desired file name
  :param schema: reference to a specific schema in redshift database
      Applicable when ``table`` param provided.
  :param table: reference to a specific table in redshift database
      Used when ``select_query`` param not provided.
  :param select_query: custom select query to fetch data from redshift database
  :param redshift_conn_id: reference to a specific redshift database
  :param aws_conn_id: reference to a specific S3 connection
      If the AWS connection contains 'aws_iam_role' in ``extras``
      the operator will use AWS STS credentials with a token
      https://docs.aws.amazon.com/redshift/latest/dg/copy-parameters-authorization.html#copy-credentials
  :param verify: Whether or not to verify SSL certificates for S3 connection.
      By default SSL certificates are verified.
      You can provide the following values:
  
      - ``False``: do not validate SSL certificates. SSL will still be used
               (unless use_ssl is False), but SSL certificates will not be
               verified.
      - ``path/to/cert/bundle.pem``: A filename of the CA cert bundle to uses.
               You can specify this argument if you want to use a different
               CA cert bundle than the one used by botocore.
  :param unload_options: reference to a list of UNLOAD options
  :param autocommit: If set to True it will automatically commit the UNLOAD statement.
      Otherwise it will be committed right before the redshift connection gets closed.
  :param include_header: If set to True the s3 file contains the header columns.
  :param parameters: (optional) the parameters to render the SQL query with.
  :param table_as_file_name: If set to True, the s3 file will be named as the table.
      Applicable when ``table`` param provided.
  :param redshift_data_api_kwargs: If using the Redshift Data API instead of the SQL-based connection,
      dict of arguments for the hook's ``execute_query`` method.
      Cannot include any of these kwargs: ``{'sql', 'parameters'}``
code: def _build_unload_query(
      self,
      credentials_block: str,
      select_query: str,
      s3_key: str,
      unload_options: str,
  ) -> str:
      # Un-escape already escaped queries
      select_query = re.sub(r"''(.+)''", r"'\1'", select_query)
      return f"""
                      UNLOAD ($${select_query}$$)
                      TO 's3://{self.s3_bucket}/{s3_key}'
                      credentials
                      '{credentials_block}'
                      {unload_options};
          """
  
file_path: airflow/airflow/providers/amazon/aws/transfers/redshift_to_s3.py
imports: from __future__ import annotations
  import re
  from typing import TYPE_CHECKING, Iterable, Mapping, Sequence
  from airflow.exceptions import AirflowException
  from airflow.models import BaseOperator
  from airflow.providers.amazon.aws.hooks.redshift_data import RedshiftDataHook
  from airflow.providers.amazon.aws.hooks.redshift_sql import RedshiftSQLHook
  from airflow.providers.amazon.aws.hooks.s3 import S3Hook
  from airflow.providers.amazon.aws.utils.redshift import build_credentials_block
label_desc: Use image node_id 2 for calling the RedshiftToS3Operator obj's underlying member method code with example usage: obj._build_unload_query(credentials_block, select_query, s3_key, unload_options) and returns: str, select_query, str, self, str, s3_key, str, credentials_block, str, unload_options, str