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-1551115] Fix test failure for test_execution_queries_and_queries when sql_simplifier is disabled #1960

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 34 additions & 19 deletions tests/integ/scala/test_snowflake_plan_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

import sys
from typing import Dict, List

import pytest

Expand Down Expand Up @@ -130,32 +131,46 @@ def test_execution_queries_and_queries(session):
# create a df where cte optimization can be applied
df2 = df1.union(df1)
original_cte_enabled_value = session.cte_optimization_enabled

plan_queries = {
PlanQueryType.QUERIES: df2._plan.queries,
PlanQueryType.POST_ACTIONS: df2._plan.post_actions,
}

def check_plan_queries(
cte_applied: bool, exec_queries: Dict[PlanQueryType, List["Query"]]
) -> None:
assert (
exec_queries[PlanQueryType.POST_ACTIONS]
== plan_queries[PlanQueryType.POST_ACTIONS]
== []
)
if cte_applied:
assert (
exec_queries[PlanQueryType.QUERIES][-1].sql
!= plan_queries[PlanQueryType.QUERIES][-1].sql
)
assert exec_queries[PlanQueryType.QUERIES][-1].sql.startswith("WITH")
assert not plan_queries[PlanQueryType.QUERIES][-1].sql.startswith("WITH")
else:
assert (
exec_queries[PlanQueryType.QUERIES]
== plan_queries[PlanQueryType.QUERIES]
)
assert not (exec_queries[PlanQueryType.QUERIES][-1].sql.startswith("WITH"))

try:
# when cte is disabled, verify that the execution query got is the same as
# the plan queries and post actions
session.cte_optimization_enabled = False
execution_queries = df2._plan.execution_queries
assert execution_queries[PlanQueryType.QUERIES] == df2._plan.queries
assert not (execution_queries[PlanQueryType.QUERIES][-1].sql.startswith("WITH"))
assert (
execution_queries[PlanQueryType.POST_ACTIONS]
== df2._plan.post_actions
== []
)
check_plan_queries(cte_applied=False, exec_queries=df2._plan.execution_queries)

# when cte is enabled, verify that the execution query got is different
# from the original plan queries
session.cte_optimization_enabled = True
execution_queries = df2._plan.execution_queries
assert (
execution_queries[PlanQueryType.QUERIES][-1].sql
!= df2._plan.queries[-1].sql
)
assert execution_queries[PlanQueryType.QUERIES][-1].sql.startswith("WITH")
assert not df2._plan.queries[-1].sql.startswith("WITH")
assert (
execution_queries[PlanQueryType.POST_ACTIONS]
== df2._plan.post_actions
== []
check_plan_queries(
cte_applied=session.sql_simplifier_enabled,
sfc-gh-yzou marked this conversation as resolved.
Show resolved Hide resolved
exec_queries=df2._plan.execution_queries,
)

finally:
Expand Down
Loading