Skip to content

Commit a6ae80b

Browse files
SNOW-2356876: Set cte_optimization_enabled to True for all Snowpark pandas sessions (#3815)
1 parent 7eab363 commit a6ae80b

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
- When hybrid execution is enabled, `pd.merge`, `pd.concat`, `DataFrame.merge`, and `DataFrame.join` may now move arguments to backends other than those among the function arguments.
141141
- Improved performance of `DataFrame.to_snowflake` and `pd.to_snowflake(dataframe)` for large data by uploading data via a parquet file. You can control the dataset size at which Snowpark pandas switches to parquet with the variable `modin.config.PandasToSnowflakeParquetThresholdBytes`.
142142
- Improved performance of `Series.to_snowflake` and `pd.to_snowflake(series)` for large data by uploading data via a parquet file. You can control the dataset size at which Snowpark pandas switches to parquet with the variable `modin.config.PandasToSnowflakeParquetThresholdBytes`.
143+
- Set `cte_optimization_enabled` to True for all Snowpark pandas sessions.
143144

144145
## 1.39.1 (2025-09-25)
145146

src/snowflake/snowpark/modin/plugin/_internal/session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def _get_active_session(self) -> Session:
8181
self._warn_if_possible_when_quoted_identifiers_ignore_case_is_set(
8282
self._session
8383
)
84+
self._session.cte_optimization_enabled = True
8485
return self._session
8586

8687
try:
@@ -89,6 +90,7 @@ def _get_active_session(self) -> Session:
8990
self._warn_if_possible_when_quoted_identifiers_ignore_case_is_set(
9091
self._session
9192
)
93+
session.cte_optimization_enabled = True
9294
return session
9395
except SnowparkSessionException as ex:
9496
if ex.error_code == "1409":
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved.
4+
#
5+
6+
from snowflake.snowpark.session import _get_active_session
7+
8+
from tests.integ.utils.sql_counter import sql_count_checker
9+
10+
11+
@sql_count_checker(query_count=0)
12+
def test_cte_optimization_for_snowpark_pandas(db_parameters):
13+
session = _get_active_session()
14+
15+
# Preserve original setting
16+
cte_optimization_original = session.cte_optimization_enabled
17+
18+
# Ensure cte optimization is disabled for current session
19+
session.cte_optimization_enabled = False
20+
assert session.cte_optimization_enabled is False
21+
22+
# Import Snowpark pandas
23+
import modin.pandas as pd
24+
import snowflake.snowpark.modin.plugin # noqa: F401
25+
26+
# Verify that cte optimization will now be enabled
27+
assert pd.session == session
28+
assert pd.session.cte_optimization_enabled is True
29+
30+
# Revert to original setting
31+
session.cte_optimizatin_enabled = cte_optimization_original
32+
assert session.cte_optimizatin_enabled == cte_optimization_original

0 commit comments

Comments
 (0)