kaxil opened a new pull request, #65040:
URL: https://github.com/apache/airflow/pull/65040
Fixes two longstanding issues with `SnowflakeHook.run()` that broke
Snowflake transaction support:
1. **Multi-statement SQL with `split_statements=False`** (#48233): When
sending a multi-statement block like `BEGIN; INSERT ...; COMMIT;` as a single
`cursor.execute()` call, Snowflake rejects it because the connector defaults
`MULTI_STATEMENT_COUNT=1`. Now passes `num_statements=0` (auto-detect) to
`cursor.execute()` when `split_statements=False`.
2. **AUTOCOMMIT session parameter override** (#30236): Users who set
`session_parameters={"AUTOCOMMIT": True}` on their connection had it
immediately overridden by `set_autocommit(conn, False)` in `run()`. Now
respects the session parameter when `autocommit=False` (the default).
## Design rationale
**Why override `_run_command()` instead of modifying `run()` inline?** The
base `DbApiHook._run_command()` handles logging, lineage tracking, and row
counts. Overriding it in `SnowflakeHook` keeps the `num_statements` logic close
to `cursor.execute()` while preserving all side effects. The override drops the
psycopg list-to-tuple conversion since Snowflake never uses psycopg.
**Why case-insensitive AUTOCOMMIT check?** Snowflake session parameters are
case-insensitive, so users may write `{"autocommit": True}` or `{"AUTOCOMMIT":
True}`. The check normalizes to uppercase.
**Why set `conn.autocommit_mode = True` in the else branch?** When we skip
`set_autocommit()` to respect the session parameter, `get_autocommit()` would
return `False` (since `autocommit_mode` was never set), causing a redundant
`conn.commit()` at the end of `run()`. Setting the mode explicitly avoids this.
**Why `_get_static_conn_params` instead of `_get_conn_params()`?** The
static version is a `@cached_property` and doesn't trigger OAuth token refresh,
avoiding surprise HTTP requests from what should be a simple config check.
## Validated against real Snowflake
All three scenarios pass against a real Snowflake instance:
- Multi-statement block (CREATE + INSERT + SELECT + DROP) with
`split_statements=False`
- Transaction block (CREATE + BEGIN + INSERT x3 + COMMIT) with
`split_statements=False`
- Backward compat: `split_statements=True` (default) still works with
separate query IDs
Closes #48233
Closes #30236
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]