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-1819531: propagate referenced ctes to all root nodes #2670

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

sfc-gh-aalam
Copy link
Contributor

@sfc-gh-aalam sfc-gh-aalam commented Nov 22, 2024

  1. Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-1819531

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
      • If this test skips Local Testing mode, I'm requesting review from @snowflakedb/local-testing
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am adding new credentials
    • I am adding a new dependency
    • If this is a new feature/behavior, I'm adding the Local Testing parity changes.
    • I acknowledge that I have ensured my changes to be thread-safe. Follow the link for more information: Thread-safe Developer Guidelines
  3. Please describe how your code solves the related issue.

    i) SNOW-1748140: Modify schema_expression to be structured type aware. #2659 re-enable test which is fixed by SNOW-1844090: deprecate propagate referenced ctes #2720
    ii) fix a bug where relaxed_pipeline_breaker property for SnowflakePlan and SelectSnowflakePlan were not read correctly
    iii) updated plan plotter to color nodes that are not valid for replacement with red color.
    iv) updated plan plotter to print number of reference a node contains.

@sfc-gh-aalam sfc-gh-aalam added the NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md label Nov 22, 2024
@sfc-gh-aalam sfc-gh-aalam marked this pull request as ready for review November 25, 2024 21:03
@sfc-gh-aalam sfc-gh-aalam requested review from a team as code owners November 25, 2024 21:03
Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

@sfc-gh-aalam sfc-gh-aalam changed the title SNOW-1819531: lqb bug fixes SNOW-1819531: propagate referenced ctes to all root nodes Nov 27, 2024
return True

if isinstance(node, SnowflakePlan) and node.source_plan is not None:
return node._is_valid_for_replacement
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am kind of confused about why we need this function here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add comment for this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while testing, I noticed that large query breakdown failed with error saying node is not valid for replacement for a SnowflakePlan whose child was a WithQueryBlock. At the time, I though this function would help us catch-up all such cases but on a second thought, it was a bug in repeated subquery elimination. I fixed the bug and removed this function now.

Copy link

github-actions bot commented Dec 2, 2024

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

@@ -169,6 +169,7 @@ def do_resolve_with_resolved_children(
iceberg_config=logical_plan.iceberg_config,
table_exists=logical_plan.table_exists,
)
resolved_plan.referenced_ctes = resolved_child.referenced_ctes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the correction of code generation, we can use the way you have now, but please make sure we comment it out clearly about why things is done in such way

@@ -306,7 +309,17 @@ def get_snowflake_plan_queries(

plan_queries = plan.queries
post_action_queries = plan.post_actions
if len(plan.referenced_ctes) > 0:
if len(plan.referenced_ctes) > 0 and not isinstance(
plan.source_plan,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adda a comment here about why are we doing this here

Comment on lines 174 to 175
resolved_with_block._is_valid_for_replacement = True
resolved_with_block_map[
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the optimization may fail. @sfc-gh-aalam maybe it would be good to add a try catch for the optimization stage, and fallback to the original query if the optimization fails.

Copy link

github-actions bot commented Dec 3, 2024

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

github-actions bot commented Dec 3, 2024

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

github-actions bot commented Dec 3, 2024

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Comment on lines 127 to 129
selectable = SelectSnowflakePlan(snowflake_plan, analyzer=query_generator)
selectable._is_valid_for_replacement = snowflake_plan._is_valid_for_replacement
return selectable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before update:
Screenshot 2024-12-03 at 2 43 49 PM

after update:
Screenshot 2024-12-03 at 3 26 25 PM

Copy link

github-actions bot commented Dec 4, 2024

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

github-actions bot commented Dec 4, 2024

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

github-actions bot commented Dec 4, 2024

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link
Contributor

@sfc-gh-helmeleegy sfc-gh-helmeleegy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local testing tests are still failing.

Copy link

github-actions bot commented Dec 4, 2024

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

Copy link

Seems like your changes contain some Local Testing changes, please request review from @snowflakedb/local-testing

@sfc-gh-aalam sfc-gh-aalam enabled auto-merge (squash) December 12, 2024 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants