Skip to content

Commit

Permalink
Snowflake handle empty sql list
Browse files Browse the repository at this point in the history
  • Loading branch information
pankajastro committed Jan 23, 2023
1 parent a5868f0 commit d6fbd77
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions astronomer/providers/snowflake/hooks/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ def fetch_one_snowflake_handler(cursor: SnowflakeCursor) -> dict[str, Any] | tup
class SnowflakeHookAsync(SnowflakeHook):
"""
A client to interact with Snowflake.
This hook requires the snowflake_conn_id connection. The snowflake host, login,
and, password field must be setup in the connection. Other inputs can be defined
in the connection or hook instantiation. If used with the S3ToSnowflakeOperator
add 'aws_access_key_id' and 'aws_secret_access_key' to extra field in the connection.
:param snowflake_conn_id: Reference to
:ref:`Snowflake connection id<howto/connection:snowflake>`
:param account: snowflake account name
Expand Down Expand Up @@ -63,21 +61,20 @@ def run( # type: ignore[override]
) -> list[str]:
"""
Runs a SQL command or a list of SQL commands.
:param sql: the sql string to be executed with possibly multiple statements,
or a list of sql statements to execute
:param autocommit: What to set the connection's autocommit setting to before executing the query.
:param parameters: The parameters to render the SQL query with.
"""
self.query_ids = []
with closing(self.get_conn()) as conn:
self.set_autocommit(conn, autocommit)

self.log.info("SQL statement to be executed: %s ", sql)
if isinstance(sql, str):
split_statements_tuple = split_statements(StringIO(sql))
sql = [sql_string for sql_string, _ in split_statements_tuple if sql_string]

if not sql:
raise ValueError("List of SQL statements is empty")
self.set_autocommit(conn, autocommit)
self.log.debug("Executing %d statements against Snowflake DB", len(sql))
with self._get_cursor(conn, return_dictionaries) as cur:

Expand Down

0 comments on commit d6fbd77

Please sign in to comment.