You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/03/21 18:40:53 UTC

[GitHub] [airflow] pohek321 commented on a change in pull request #22391: Update the redshift sql operator to accept multiple sql statements

pohek321 commented on a change in pull request #22391:
URL: https://github.com/apache/airflow/pull/22391#discussion_r831430895



##########
File path: airflow/providers/amazon/aws/operators/redshift_sql.py
##########
@@ -74,5 +75,12 @@ def get_hook(self) -> RedshiftSQLHook:
     def execute(self, context: 'Context') -> None:
         """Execute a statement against Amazon Redshift"""
         self.log.info(f"Executing statement: {self.sql}")
+        sql_stmts = sqlparse.split(self.sql)
         hook = self.get_hook()
-        hook.run(self.sql, autocommit=self.autocommit, parameters=self.parameters)
+
+        with hook.get_conn() as con:
+            con.autocommit = self.autocommit
+            with con.cursor() as cursor:
+                for stmt in sql_stmts:
+                    cursor.execute(stmt)
+                    if self.autocommit is False: con.commit()

Review comment:
       @eladkal I went ahead and moved lines 81-86 to the RedshiftSQLHook as a sub method and called it in the RedshiftSQLOperator. Is this the right approach that you were envisioning?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org