Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1976643: Allow creating multi-session in sprocs if enabled #3146

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sfc-gh-smirzaei
Copy link
Contributor

@sfc-gh-smirzaei sfc-gh-smirzaei commented Mar 11, 2025

  1. Description:
    With dbt project, we are planning on supporting multiple session insides procs. So we have added new API to _snowflake to create a pristine cloned version of the default server session. Using this, we will create a new new Snowpark session (a new object with new connection obj) and we will set the session_id of the connection (will be done in C API). Currently we have a check in Snowpark lib which disallows creating multiple sessions inside sprocs. With this check we will that check the corresponding param is enabled (this param will only be enabled for dbt sprocs).

For more info on the multi-session project see this design doc: https://docs.google.com/document/d/1lwqyykHo549Vx3UWpFLWot1LIdYrwUjGKtGbQGaCnd8/edit?tab=t.0#heading=h.sil75ywnlm6n

An example of how this new API is used:

create or replace procedure get_session_sp()
returns string
language python
packages=('snowflake-snowpark-python')
runtime_version=3.8
handler='handler'
as
$$import _snowflake

def handler(session):
  new_session = _snowflake.create_session()
  new_session.sql('select foo')
  return 'done'
$$;
  1. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
      • If this test skips Local Testing mode, I'm requesting review from @snowflakedb/local-testing
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am adding new credentials
    • I am adding a new dependency
    • If this is a new feature/behavior, I'm adding the Local Testing parity changes.
    • I acknowledge that I have ensured my changes to be thread-safe. Follow the link for more information: Thread-safe Developer Guidelines

@sfc-gh-smirzaei sfc-gh-smirzaei requested review from a team as code owners March 11, 2025 20:53
@sfc-gh-snowflakedb-snyk-sa
Copy link

sfc-gh-snowflakedb-snyk-sa commented Mar 18, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

if len(_active_sessions) >= 1 and is_in_stored_procedure():
if (len(_active_sessions) >= 1
and is_in_stored_procedure()
and not conn._get_client_side_session_parameter(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This param will be enabled for internal dbt use only.

@sfc-gh-smirzaei sfc-gh-smirzaei force-pushed the SNOW-1976643-allow-multi-session-snowpark branch from 7cdcc9a to a36861f Compare March 19, 2025 00:54
@sfc-gh-smirzaei sfc-gh-smirzaei added the NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md label Mar 19, 2025
len(_active_sessions) >= 1
and is_in_stored_procedure()
and not conn._get_client_side_session_parameter(
"ENABLE_CREATE_SESSION_IN_STORED_PROCS", False
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENABLE_CREATE_SESSION_IN_STORED_PROCS is an internal param that will be only enabled for internal dbt runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants