-
Notifications
You must be signed in to change notification settings - Fork 144
SNOW-1734385: Do not create CTE when partitioning WithQueryBlocks #2948
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -356,6 +356,17 @@ def is_active_transaction(session): | |
| return session._run_query("SELECT CURRENT_TRANSACTION()")[0][0] is not None | ||
|
|
||
|
|
||
| def is_with_query_block(node: Optional[LogicalPlan]) -> bool: | ||
|
||
| if isinstance(node, WithQueryBlock): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a comment here that this function is check whether a given logical node is a node or resolved SnowflakePlan or Selectable for WithQueryBlock |
||
| return True | ||
| if isinstance(node, SnowflakePlan): | ||
| return is_with_query_block(node.source_plan) | ||
| if isinstance(node, SelectSnowflakePlan): | ||
| return is_with_query_block(node.snowflake_plan) | ||
|
|
||
| return False | ||
|
|
||
|
|
||
| def plot_plan_if_enabled(root: LogicalPlan, filename: str) -> None: | ||
| """A helper function to plot the query plan tree using graphviz useful for debugging. | ||
| It plots the plan if the environment variable ENABLE_SNOWPARK_LOGICAL_PLAN_PLOTTING | ||
|
|
@@ -456,16 +467,6 @@ def get_sql_text(node: LogicalPlan) -> str: # pragma: no cover | |
|
|
||
| return f"{name=}\n{score=}, {ref_ctes=}, {sql_size=}\n{sql_preview=}" | ||
|
|
||
| def is_with_query_block(node: Optional[LogicalPlan]) -> bool: # pragma: no cover | ||
| if isinstance(node, WithQueryBlock): | ||
| return True | ||
| if isinstance(node, SnowflakePlan): | ||
| return is_with_query_block(node.source_plan) | ||
| if isinstance(node, SelectSnowflakePlan): | ||
| return is_with_query_block(node.snowflake_plan) | ||
|
|
||
| return False | ||
|
|
||
| g = graphviz.Graph(format="png") | ||
|
|
||
| curr_level = [root] | ||
|
|
||
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.
move this to utils right below is_with_query_block function to group the functionality.