blob: c53a4b95ac223ceba0575462e751f8ffd29692ed [file] [log] [blame]
.. Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
.. Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
.. _howto/operator:RedshiftSQLOperator:
.. contents::
:depth: 1
Use the :class:`RedshiftSQLOperator <>` to execute
statements against an Amazon Redshift cluster.
:class:`RedshiftSQLOperator <>` works together with
:class:`RedshiftSQLHook <>` to establish
connections with Amazon Redshift.
This is a basic example dag for using :class:`RedshiftSQLOperator <>`
to execute statements against an Amazon Redshift cluster.
Create a table
In the following code we are creating a table called "fruit".
.. exampleinclude:: /../../airflow/providers/amazon/aws/example_dags/
:language: python
:start-after: [START howto_operator_redshift_create_table]
:end-before: [END howto_operator_redshift_create_table]
Insert data into a table
In the following code we insert a few sample rows into the "fruit" table.
.. exampleinclude:: /../../airflow/providers/amazon/aws/example_dags/
:language: python
:start-after: [START howto_operator_redshift_populate_table]
:end-before: [END howto_operator_redshift_populate_table]
Fetching records from a table
Creating a new table, "more_fruit" from the "fruit" table.
.. exampleinclude:: /../../airflow/providers/amazon/aws/example_dags/
:language: python
:start-after: [START howto_operator_redshift_get_all_rows]
:end-before: [END howto_operator_redshift_get_all_rows]
Passing Parameters into RedshiftSQLOperator
RedshiftSQLOperator supports the ``parameters`` attribute which allows us to dynamically pass
parameters into SQL statements.
.. exampleinclude:: /../../airflow/providers/amazon/aws/example_dags/
:language: python
:start-after: [START howto_operator_redshift_get_with_filter]
:end-before: [END howto_operator_redshift_get_with_filter]
The complete RedshiftSQLOperator DAG
All together, here is our DAG:
.. exampleinclude:: /../../airflow/providers/amazon/aws/example_dags/
:language: python
:start-after: [START redshift_operator_howto_guide]
:end-before: [END redshift_operator_howto_guide]