dlt icon indicating copy to clipboard operation
dlt copied to clipboard

Update docs for transaction handling - snowflake.md

Open sspaeti opened this issue 8 months ago • 5 comments

Description

If you use Snowflake and have transaction settings not set to default, e.g., have set ALTER SESSION SET AUTOCOMMIT = FALSE;, dlt will not work properly and end up having an open session with uncommitted Inserts/merge statements.

I added a note to the docs with this PR to make that clear and not run into errors I did.

Additional Context

Even better would be to explicitly set ALTER SESSION SET AUTOCOMMIT = TRUE; on the insert to destination schema as well as you do for inserting into Staging, where you added ALTER SESSION SET AUTOCOMMIT = TRUE; explicitly.

PS: I added the note to Additional connection options, not sure if that is the best place. Feel free to reorder or let me know where it would make more sense.

sspaeti avatar Apr 03 '25 09:04 sspaeti

Deploy Preview for dlt-hub-docs ready!

Name Link
Latest commit 0c50c145874f89150df4a77a7705bb5ab0b5e0d5
Latest deploy log https://app.netlify.com/sites/dlt-hub-docs/deploys/67ee5561924a5b0008441815
Deploy Preview https://deploy-preview-2480--dlt-hub-docs.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Apr 03 '25 09:04 netlify[bot]

Just FYI: I'm not sure if the :::note is not working, or the preview (above link isn't correct), but it does not show my additional note on the preview.

sspaeti avatar Apr 04 '25 07:04 sspaeti

@sspaeti how did you manage to change session settings? each loader job gets a separate connection which is closed after COPY/MERGE command. I'm asking because indeed we didn't start the transaction before SQL job and I changed that: we do it in LoadJob managed run method. MERGE/COPY SQL scripts are not affected.

rudolfix avatar Apr 13 '25 16:04 rudolfix

@rudolfix It was set at a account level (globally). As it can be set on three levels:

  • Account (global) -> alter account set autocommit = false;
  • User -> alter user <username> set autocommit = false;
  • Session -> alter session set autocommit = false;

Whereas session user and account settings overrule. See https://docs.snowflake.com/en/sql-reference/parameters#label-autocommit.

I believe this happens, because you only explicitly set the ALTER SESSION SET AUTOCOMMIT = TRUE; but not for FALSE. Meaning if someone has it the global/account settings set to FALSE, that's when we ran into the issue of open sessions. Small issues, but might be worth mentioning or make it explicit in both way? 🤔

sspaeti avatar Apr 22 '25 08:04 sspaeti

@sspaeti now I get it? should we just set autocommit explicitly to TRUE on opening the connection? we do that anyway after comitting/rollbacking the transaction. if we do that, we just need to mention that we set it explicitly in the docs and user can still have those account settings, right?

rudolfix avatar Apr 23 '25 12:04 rudolfix

this PR will explicitly set autocommit on new connection https://github.com/dlt-hub/dlt/pull/2593

rudolfix avatar May 02 '25 16:05 rudolfix