Skip to content

Commit

Permalink
Read server side CTE parameter when initializing the session (#1809)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jdu committed Jun 20, 2024
1 parent af35bc3 commit 3a3d240
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/snowflake/snowpark/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
_PYTHON_SNOWPARK_USE_LOGICAL_TYPE_FOR_CREATE_DATAFRAME_STRING = (
"PYTHON_SNOWPARK_USE_LOGICAL_TYPE_FOR_CREATE_DATAFRAME"
)
_PYTHON_SNOWPARK_USE_CTE_OPTIMIZATION_STRING = "PYTHON_SNOWPARK_USE_CTE_OPTIMIZATION"
WRITE_PANDAS_CHUNK_SIZE: int = 100000 if is_in_stored_procedure() else None


Expand Down Expand Up @@ -492,7 +493,11 @@ def __init__(
_PYTHON_SNOWPARK_USE_SQL_SIMPLIFIER_STRING, True
)
)
self._cte_optimization_enabled: bool = False
self._cte_optimization_enabled: bool = (
self._conn._get_client_side_session_parameter(
_PYTHON_SNOWPARK_USE_CTE_OPTIMIZATION_STRING, False
)
)
self._use_logical_type_for_create_df: bool = (
self._conn._get_client_side_session_parameter(
_PYTHON_SNOWPARK_USE_LOGICAL_TYPE_FOR_CREATE_DATAFRAME_STRING, True
Expand Down
28 changes: 25 additions & 3 deletions tests/integ/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
SnowparkSessionException,
)
from snowflake.snowpark.session import (
_PYTHON_SNOWPARK_USE_CTE_OPTIMIZATION_STRING,
_PYTHON_SNOWPARK_USE_SQL_SIMPLIFIER_STRING,
_active_sessions,
_get_active_session,
Expand Down Expand Up @@ -639,9 +640,9 @@ def test_close_session_twice(db_parameters):


@pytest.mark.skipif(IS_IN_STORED_PROC, reason="Can't create a session in SP")
@pytest.mark.skip(
reason="This test passed with a local dev Snowflake env. "
"Will be enabled soon once Snowflake publicize the sql simplifier parameter."
@pytest.mark.skipif(
"config.getoption('local_testing_mode', default=False)",
reason="reading server side parameter is not supported in local testing",
)
def test_sql_simplifier_disabled_on_session(db_parameters):
with Session.builder.configs(db_parameters).create() as new_session:
Expand All @@ -659,6 +660,27 @@ def test_sql_simplifier_disabled_on_session(db_parameters):
assert new_session2.sql_simplifier_enabled is False


@pytest.mark.skipif(IS_IN_STORED_PROC, reason="Can't create a session in SP")
@pytest.mark.skipif(
"config.getoption('local_testing_mode', default=False)",
reason="reading server side parameter is not supported in local testing",
)
def test_cte_optimization_enabled_on_session(db_parameters):
with Session.builder.configs(db_parameters).create() as new_session:
assert new_session.cte_optimization_enabled is False
new_session.cte_optimization_enabled = True
assert new_session.cte_optimization_enabled is True
new_session.cte_optimization_enabled = False
assert new_session.cte_optimization_enabled is False

parameters = db_parameters.copy()
parameters["session_parameters"] = {
_PYTHON_SNOWPARK_USE_CTE_OPTIMIZATION_STRING: True
}
with Session.builder.configs(parameters).create() as new_session2:
assert new_session2.cte_optimization_enabled is True


@pytest.mark.skipif(IS_IN_STORED_PROC, reason="Cannot create session in SP")
def test_create_session_from_default_config_file(monkeypatch, db_parameters):
import tomlkit
Expand Down

0 comments on commit 3a3d240

Please sign in to comment.