Use the :class:`RedshiftSQLOperator <airflow.providers.amazon.aws.operators.redshift>` to execute statements against an Amazon Redshift cluster.
:class:`RedshiftSQLOperator <airflow.providers.amazon.aws.operators.redshift.RedshiftSQLOperator>` works together with :class:`RedshiftSQLHook <airflow.providers.amazon.aws.hooks.redshift.RedshiftSQLHook>` to establish connections with Amazon Redshift.
This is a basic example dag for using :class:`RedshiftSQLOperator <airflow.providers.amazon.aws.operators.redshift>` to execute statements against an Amazon Redshift cluster.
In the following code we are creating a table called "fruit".
.. exampleinclude:: /../../airflow/providers/amazon/aws/example_dags/example_redshift.py :language: python :start-after: [START howto_operator_redshift_create_table] :end-before: [END howto_operator_redshift_create_table]
In the following code we insert a few sample rows into the "fruit" table.
.. exampleinclude:: /../../airflow/providers/amazon/aws/example_dags/example_redshift.py :language: python :start-after: [START howto_operator_redshift_populate_table] :end-before: [END howto_operator_redshift_populate_table]
Creating a new table, "more_fruit" from the "fruit" table.
.. exampleinclude:: /../../airflow/providers/amazon/aws/example_dags/example_redshift.py :language: python :start-after: [START howto_operator_redshift_get_all_rows] :end-before: [END howto_operator_redshift_get_all_rows]
RedshiftSQLOperator supports the parameters
attribute which allows us to dynamically pass
parameters into SQL statements.
.. exampleinclude:: /../../airflow/providers/amazon/aws/example_dags/example_redshift.py :language: python :start-after: [START howto_operator_redshift_get_with_filter] :end-before: [END howto_operator_redshift_get_with_filter]
All together, here is our DAG:
.. exampleinclude:: /../../airflow/providers/amazon/aws/example_dags/example_redshift.py :language: python :start-after: [START redshift_operator_howto_guide] :end-before: [END redshift_operator_howto_guide]
To resume a 'paused' AWS Redshift Cluster you can use :class:`~airflow.providers.amazon.aws.operators.redshift_resume_cluster.RedshiftResumeClusterOperator`.
This Operator leverages the AWS CLI resume-cluster API
To pause an 'available' AWS Redshift Cluster you can use :class:`~airflow.providers.amazon.aws.operators.redshift_pause_cluster.RedshiftPauseClusterOperator`.
This Operator leverages the AWS CLI pause-cluster API