dstandish commented on a change in pull request #11350:
URL: https://github.com/apache/airflow/pull/11350#discussion_r582108801
##########
File path: airflow/providers/snowflake/hooks/snowflake.py
##########
@@ -142,3 +143,16 @@ def set_autocommit(self, conn, autocommit: Any) -> None:
def get_autocommit(self, conn):
return getattr(conn, 'autocommit_mode', False)
+
+ def run(self, sql, autocommit=False, parameters=None):
+ """
+ Snowflake-connector doesn't allow natively the execution of multiple
SQL statements in the same
+ call. So for allowing to pass files or strings with several queries
this method is coded,
+ that relies on run from DBApiHook
+ """
+ conn = self.get_conn()
+ self.set_autocommit(conn, autocommit)
+
+ queries = [item[0] for item in split_statements(StringIO(sql))]
+ for query in queries:
+ super().run(query, autocommit, parameters)
Review comment:
the problem with this @JavierLopezT is it will reconnect for every
statement.
this can be a nightmare when you use okta :) (though it's possible to cache
the creds)
but more importantly, the way you've implemented, it's not possible to use
temp tables (which is pretty important). after reconnect the table will be
gone.
instead you should connect only once and use same connection for the whole
series of statements.
e.g.
```
with closing(hook.get_conn()) as cnx:
cur = cnx.cursor()
for query in queries:
cur.execute(query)
for row in cur.fetchall():
print(row)
```
(you want to print fetchall because this is how you get statement results,
and operator is not meant to be used for a bare "select" statement so no worry
about writing a billion rows to the log :) )
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]