Skip to content

Commit e14b78b

Browse files
authored
SNOW-1541091: Add plan compiler component (#1946)
1 parent dc16701 commit e14b78b

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"snowflake.snowpark",
8888
"snowflake.snowpark._internal",
8989
"snowflake.snowpark._internal.analyzer",
90+
"snowflake.snowpark._internal.compiler",
9091
"snowflake.snowpark.mock",
9192
"snowflake.snowpark.modin",
9293
"snowflake.snowpark.modin.config",

src/snowflake/snowpark/_internal/analyzer/snowflake_plan.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,10 @@ def execution_queries(self) -> Dict["PlanQueryType", List["Query"]]:
266266
-------
267267
A mapping between the PlanQueryType and the list of Queries corresponds to the type.
268268
"""
269-
# apply optimizations
270-
final_plan = self.replace_repeated_subquery_with_cte()
271-
return {
272-
PlanQueryType.QUERIES: final_plan.queries,
273-
PlanQueryType.POST_ACTIONS: final_plan.post_actions,
274-
}
269+
from snowflake.snowpark._internal.compiler.plan_compiler import PlanCompiler
270+
271+
compiler = PlanCompiler(self)
272+
return compiler.compile()
275273

276274
@property
277275
def children_plan_nodes(self) -> List[Union["Selectable", "SnowflakePlan"]]:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
3+
#
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
3+
#
4+
5+
from typing import Dict, List
6+
7+
from snowflake.snowpark._internal.analyzer.snowflake_plan import (
8+
PlanQueryType,
9+
Query,
10+
SnowflakePlan,
11+
)
12+
13+
14+
class PlanCompiler:
15+
"""This class is common point of entry from compiling SnowflakePlan to list of queries and post actions.
16+
We run pre-check and pre-process steps for optimization steps, and apply the activated optimizations.
17+
"""
18+
19+
def __init__(self, plan: SnowflakePlan) -> None:
20+
self._plan = plan
21+
22+
def compile(self) -> Dict[PlanQueryType, List[Query]]:
23+
# apply optimizations
24+
final_plan = self._plan.replace_repeated_subquery_with_cte()
25+
return {
26+
PlanQueryType.QUERIES: final_plan.queries,
27+
PlanQueryType.POST_ACTIONS: final_plan.post_actions,
28+
}

0 commit comments

Comments
 (0)