-
Notifications
You must be signed in to change notification settings - Fork 120
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-1878372: Fix analyzer access across threads #2912
base: main
Are you sure you want to change the base?
Conversation
@@ -121,7 +121,7 @@ def test_selectable_entity_individual_node_complexity(mock_session, mock_analyze | |||
assert plan_node.individual_node_complexity == {PlanNodeCategory.COLUMN: 1} | |||
|
|||
|
|||
def test_select_sql_individual_node_complexity(mock_analyzer): | |||
def test_select_sql_individual_node_complexity(mock_session, mock_analyzer): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does adding mock_session do for these tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good question, calling mock session here sets mock_analyzer.session=mock_session
.
snowpark-python/tests/unit/conftest.py
Lines 75 to 82 in 7d4b43c
@pytest.fixture(scope="module") | |
def mock_session(mock_analyzer) -> Session: | |
fake_session = mock.create_autospec(Session) | |
fake_session._cte_optimization_enabled = False | |
fake_session._analyzer = mock_analyzer | |
fake_session._plan_lock = mock.MagicMock() | |
mock_analyzer.session = fake_session | |
return fake_session |
this is probably not the best way to do it. open to suggestions.
@@ -84,7 +84,7 @@ def test_find_duplicate_subtrees(test_case): | |||
assert repeated_node_complexity == expected_repeated_node_complexity | |||
|
|||
|
|||
def test_encode_node_id_with_query_select_sql(mock_analyzer): | |||
def test_encode_node_id_with_query_select_sql(mock_session, mock_analyzer): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as jamison's question. Linking old response: #2912 (comment)
assert new_replaced_plan.analyzer == mock_query_generator | ||
# new_replaced_plan is created with QueryGenerator.to_selectable | ||
assert new_replaced_plan.analyzer == mock_analyzer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this change to pass the new "setter" check?
is mock_query_generator/mock_analyzer used in any of the test code after?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new_replaced_plan
is created by calling within QueryGenerator.to_selectable
which uses self
as an analyzer.
Before this change Selectable.analyzer
would have returned the analyzer used to create the selectable i.e. mock_query_generator
.
After this change, Selectable.analyzer
will return the appropriate session.analyzer
. Therefore, we need to update this test.
Co-authored-by: Jianzhun Du <[email protected]>
Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.
Fixes SNOW-1878372
Fill out the following pre-review checklist:
Please describe how your code solves the related issue.
In this change, we make the following changes to
Selectable
:_is_valid_for_replacement=True
.We also update
Analyzer
to initializealias_maps_to_use
with an empty dict{}
instead ofNone
. In single threaded-case,resolve
would initialize alias_maps_to_use to{}
and then use it foranalyze
but in multithreaded-case, it is possible for one thread to callresolve
and a different thread to callanalyze
.