Skip to content

Commit

Permalink
SNOW-1413967: Remove workaround for dynamic pivot when CTE optimizati…
Browse files Browse the repository at this point in the history
…on is enabled (#1855)
  • Loading branch information
sfc-gh-jdu authored Jun 28, 2024
1 parent 29c4a76 commit f91e7a1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 27 deletions.
20 changes: 0 additions & 20 deletions src/snowflake/snowpark/_internal/analyzer/cte_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ def traverse(root: "TreeNode") -> None:
while len(current_level) > 0:
next_level = []
for node in current_level:
# all subqueries under dynamic pivot node will not be optimized now
# due to a server side bug
# TODO: SNOW-1413967 Remove it when the bug is fixed
if is_dynamic_pivot_node(node):
continue
node_count_map[node] += 1
for child in node.children_plan_nodes:
# converting non-SELECT child query to SELECT query here,
Expand All @@ -89,21 +84,6 @@ def is_duplicate_subtree(node: "TreeNode") -> bool:
return True
return False

def is_dynamic_pivot_node(node: "TreeNode") -> bool:
from snowflake.snowpark._internal.analyzer.select_statement import (
SelectSnowflakePlan,
)
from snowflake.snowpark._internal.analyzer.snowflake_plan import SnowflakePlan
from snowflake.snowpark._internal.analyzer.unary_plan_node import Pivot

if isinstance(node, SelectSnowflakePlan):
source_plan = node.snowflake_plan.source_plan
elif isinstance(node, SnowflakePlan):
source_plan = node.source_plan
else:
return False
return isinstance(source_plan, Pivot) and source_plan.pivot_values is None

traverse(root)
return {node for node in node_count_map if is_duplicate_subtree(node)}

Expand Down
7 changes: 0 additions & 7 deletions tests/integ/test_cte.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,6 @@ def test_pivot_unpivot(session):
check_result(session, df_result, expect_cte_optimized=True)
assert count_number_of_ctes(df_result.queries["queries"][-1]) == 1

# Because of SNOW-1375062, dynamic pivot doesn't work with nested CTE
# TODO: SNOW-1413967 Remove it when the bug is fixed
df_nested = session.table("monthly_sales").select("*")
df_nested = df_nested.union_all(df_nested).select("*")
df_dynamic_pivot = df_nested.pivot("month").sum("amount")
check_result(session, df_dynamic_pivot, expect_cte_optimized=False)


def test_window_function(session):
window1 = (
Expand Down

0 comments on commit f91e7a1

Please sign in to comment.