-
Notifications
You must be signed in to change notification settings - Fork 146
SNOW-2097586: Add Debug mode for eager evaluation #3380
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c9b4bc3
SNOW-2097586: Add Debug mode for eager evaluation
sfc-gh-jrose 391cdda
Merge branch 'main' into jrose_snow_2097586_debug_mode
sfc-gh-jrose fbf4f96
test fixes
sfc-gh-jrose b4e151a
CHANGELOG.md
sfc-gh-jrose 819858a
Move flag to context. Make compatible with enhanced error messages
sfc-gh-jrose 69ec17c
Merge branch 'main' into jrose_snow_2097586_debug_mode
sfc-gh-jrose 7e91def
Review feedback
sfc-gh-jrose 4ee299e
add comment
sfc-gh-jrose 4f99565
Merge branch 'main' into jrose_snow_2097586_debug_mode
sfc-gh-jrose a7f638a
Update changelog
sfc-gh-jrose a39b9a2
test fixes
sfc-gh-jrose 80a99f5
Update src/snowflake/snowpark/dataframe.py
sfc-gh-jrose f598da0
Merge branch 'main' into jrose_snow_2097586_debug_mode
sfc-gh-jrose 7c578e8
test fixes
sfc-gh-jrose 75b7884
typo
sfc-gh-jrose File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| #!/usr/bin/env python3 | ||
| # | ||
| # Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved. | ||
| # | ||
|
|
||
| import pytest | ||
| import snowflake.snowpark.context as context | ||
| from copy import copy | ||
| from unittest.mock import patch, Mock | ||
|
|
||
|
|
||
| from snowflake.snowpark.functions import col, lit, max | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| "config.getoption('local_testing_mode', default=False)", | ||
| reason="debug_mode not used in local testing mode", | ||
| ) | ||
| @pytest.mark.parametrize("debug_mode", [True, False]) | ||
| @pytest.mark.parametrize( | ||
| "transform", | ||
| [ | ||
| pytest.param(lambda x: copy(x), id="copy"), | ||
| pytest.param(lambda x: x.to_df(["C", "D"]), id="to_df"), | ||
| pytest.param(lambda x: x.distinct(), id="distinct"), | ||
| pytest.param(lambda x: x.drop_duplicates(), id="drop_duplicates"), | ||
| pytest.param(lambda x: x.limit(1), id="limit"), | ||
| pytest.param(lambda x: x.union(x), id="union"), | ||
| pytest.param(lambda x: x.union_all(x), id="union_all"), | ||
| pytest.param(lambda x: x.union_by_name(x), id="union_by_name"), | ||
| pytest.param(lambda x: x.union_all_by_name(x), id="union_all_by_name"), | ||
| pytest.param(lambda x: x.intersect(x), id="intersect"), | ||
| pytest.param(lambda x: x.natural_join(x), id="natural_join"), | ||
| pytest.param(lambda x: x.cross_join(x), id="cross_join"), | ||
| pytest.param(lambda x: x.sample(n=1), id="sample"), | ||
| pytest.param( | ||
| lambda x: x.with_column_renamed(col("A"), "B"), id="with_column_renamed" | ||
| ), | ||
| # Unpivot already validates names | ||
| pytest.param(lambda x: x.unpivot("x", "y", ["A"]), id="unpivot"), | ||
| # The following functions do not error early because their schema_query do not contain | ||
| # information about the transformation being called. | ||
| pytest.param(lambda x: x.drop(col("A")), id="drop"), | ||
| pytest.param(lambda x: x.filter(col("A") == lit(1)), id="filter"), | ||
| pytest.param(lambda x: x.sort(col("A").desc()), id="sort"), | ||
| ], | ||
| ) | ||
| def test_early_attributes(session, transform, debug_mode): | ||
| with patch.object(context, "_debug_eager_schema_validation", debug_mode): | ||
| df = session.create_dataframe([(1, "A"), (2, "B"), (3, "C")], ["A", "B"]) | ||
|
|
||
| transformed = transform(df) | ||
|
|
||
| # When debug mode is enabled the dataframe plan attributes are populated early | ||
| if debug_mode: | ||
| assert transformed._plan._metadata.attributes is not None | ||
| else: | ||
| assert transformed._plan._metadata.attributes is None | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| "config.getoption('local_testing_mode', default=False)", | ||
| reason="debug_mode not used in local testing mode", | ||
| ) | ||
| @pytest.mark.parametrize("debug_mode", [True, False]) | ||
| @pytest.mark.parametrize( | ||
| "transform", | ||
| [ | ||
| pytest.param(lambda x: x.select("B"), id="select"), | ||
| pytest.param(lambda x: x.select_expr("cast(b as str)"), id="select_expr"), | ||
| pytest.param(lambda x: x.agg(max("B")), id="agg"), | ||
| pytest.param(lambda x: x.join(copy(x), on=(col("A") == col("B"))), id="join"), | ||
| pytest.param( | ||
| lambda x: x.join_table_function("flatten", col("B")), | ||
| id="join_table_function", | ||
| ), | ||
| pytest.param(lambda x: x.with_column("C", col("B")), id="with_column"), | ||
| pytest.param(lambda x: x.with_columns(["C"], [col("B")]), id="with_columns"), | ||
| ], | ||
| ) | ||
| def test_early_error(session, transform, debug_mode): | ||
| with patch.object(context, "_debug_eager_schema_validation", debug_mode): | ||
| df = session.create_dataframe([1, 2, 3], ["A"]) | ||
|
|
||
| show_mock = Mock() | ||
| show_mock.__qualname__ = "show" | ||
| show_mock.__name__ = "show" | ||
|
|
||
| with patch("snowflake.snowpark.dataframe.DataFrame.show", show_mock): | ||
| try: | ||
| transformed = transform(df) | ||
| transformed.show() | ||
| except Exception: | ||
| pass | ||
| # When debug mode is enabled the error is thrown before reaching show. | ||
| # Without debug mode the error only shows up once show is called. | ||
| if debug_mode: | ||
| show_mock.assert_not_called() | ||
| assert df._plan._metadata.attributes is not None | ||
| else: | ||
| show_mock.assert_called() | ||
| assert df._plan._metadata.attributes is None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.