Hello, I'm using SnowflakeResource and would like ...
# integration-snowflake
s
Hello, I'm using SnowflakeResource and would like to submit multiple statements in one transaction. There is a pattern for this in the Snowflake docs, using the
autocommit=False
argument to
snowflake.connector.connect
(https://docs.snowflake.com/developer-guide/python-connector/python-connector-example#using-context-manager-to-connect-and-control-transactions). How can I get a Snowflake connection with
autocommit=False
from
SnowflakeResource.get_connection()
?
🤖 1
j
hey @Simrun Basuita the
SnowflakeResource
accepts an
autocommit
configuration that is forwarded to the snowflake connection https://docs.dagster.io/_apidocs/libraries/dagster-snowflake#dagster_snowflake.SnowflakeResource
s
@jamie can I set that config for just one asset?
I'm guessing it's something I can pass to @asset()? Will take a look
thanks
j
the config set for a resource is used for all assets. But i think the
snowflake.connector.Connection
object has an
autocommit
method you could use
Copy code
@asset 
def my_asset(snowflake: SnowflakeResource):
   with snowflake.get_connection() as conn:
      conn.autocommit(False)
https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-api#object-connection
s
ah, nice! Thanks! 🙂
f
Hey @Simrun Basuita, have you tried to append multiple statements into a single string and send that for execution? That's what I'm usually doing. It can be significantly faster, since it avoids the connection overhead
s
Hey, I haven't! Thanks for the tip @FĂ©lix Tremblay