Skip to content

fix: planner fixes for parent entity jumps and unique nodes selections#1230

Merged
devsergiy merged 4 commits intomasterfrom
sergiy/eng-7397-fix-planner-parent-entity-jump
Jul 22, 2025
Merged

fix: planner fixes for parent entity jumps and unique nodes selections#1230
devsergiy merged 4 commits intomasterfrom
sergiy/eng-7397-fix-planner-parent-entity-jump

Conversation

@devsergiy
Copy link
Copy Markdown
Member

@devsergiy devsergiy commented Jul 14, 2025

fixes ENG-7397
fixes ENG-7355
fixes ENG-7228

Summary by CodeRabbit

  • New Features

    • Added a new validation rule to detect and report empty selection sets in dynamically generated GraphQL operations.
  • Bug Fixes

    • Improved internal logic for selecting parent and duplicate nodes in data source planning, resulting in more accurate and streamlined node selection.
  • Tests

    • Updated test descriptions to reflect changes in node selection reasoning, ensuring test clarity and consistency.

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 14, 2025

Walkthrough

A new GraphQL validation rule for empty selection sets is introduced and integrated into the operation validation pipeline for dynamically generated operations. The data source filter visitor logic is refactored to adjust node selection stages, remove certain leaf node selections, and modify parent chain handling, with corresponding updates to selection reason constants and test case reason strings.

Changes

Files/Paths Change Summary
v2/pkg/astvalidation/operation_rule_validate_empty_selection_set.go Added a new validation rule to detect empty selection sets in GraphQL operations.
v2/pkg/engine/datasource/graphql_datasource/graphql_datasource.go Integrated the new empty selection set validation rule into the printKit operation validator initialization.
v2/pkg/engine/plan/datasource_filter_visitor.go Refactored node selection logic by removing leaf child/sibling selection, reordered duplicate node stages, removed two reason constants, and revised parent chain handling.
v2/pkg/engine/plan/datasource_filter_visitor_test.go Updated test cases to replace certain selection reason strings; no logic changes.

Estimated code review effort

3 (~40 minutes)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7eeecc3 and cae4374.

📒 Files selected for processing (1)
  • v2/pkg/engine/plan/datasource_filter_visitor.go (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • v2/pkg/engine/plan/datasource_filter_visitor.go
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sergiy/eng-7397-fix-planner-parent-entity-jump

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@devsergiy devsergiy changed the title Sergiy/eng 7397 fix planner parent entity jump fix: fix planner parent entity jump Jul 14, 2025
@devsergiy devsergiy force-pushed the sergiy/eng-7397-fix-planner-parent-entity-jump branch from cd67466 to 528a716 Compare July 14, 2025 12:56
@devsergiy devsergiy force-pushed the sergiy/eng-7397-fix-planner-parent-entity-jump branch from 528a716 to 00e61d2 Compare July 22, 2025 18:05
@devsergiy devsergiy changed the title fix: fix planner parent entity jump fix: planner fixes for parent entity jumps and unique nodes selections Jul 22, 2025
@devsergiy devsergiy marked this pull request as ready for review July 22, 2025 18:38
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (5)
v2/pkg/astvalidation/operation_rule_validate_empty_selection_set.go (3)

10-12: Clarify the usage context in the comment.

The comment mentions "should be used only when the operation is created on the fly" but doesn't explain why this restriction exists or what constitutes an operation "created on the fly".

Consider expanding the comment to clarify:

-// ValidateEmptySelectionSets validates if selection sets are not empty
-// should be used only when the operation is created on the fly
+// ValidateEmptySelectionSets validates that selection sets are not empty.
+// This rule is specifically designed for dynamically generated operations
+// where empty selection sets indicate a planner error, as opposed to
+// user-provided queries where empty selection sets are caught by standard validation.

33-35: Enhance error message for better debugging.

The error message could be more descriptive to aid in debugging.

-		r.Walker.StopWithInternalErr(fmt.Errorf("astvalidation selection set on path %s is empty", r.Walker.Path.DotDelimitedString()))
+		r.Walker.StopWithInternalErr(fmt.Errorf("empty selection set detected at path: %s - this indicates a planner error in dynamically generated operations", r.Walker.Path.DotDelimitedString()))

1-36: Add unit tests for the validation rule.

This new validation rule should have corresponding unit tests to ensure it works correctly.

Would you like me to generate unit tests for the ValidateEmptySelectionSets rule to ensure proper coverage?

v2/pkg/engine/plan/datasource_filter_visitor.go (2)

523-527: Update stage numbering in comments to match implementation.

The comment mentions "stages 2,3,4" but the implementation shows stages 2-5.

-		// stages 2,3,4 - are stages when choices are equal, and we should select first available node
+		// stages 2-5 are stages when choices are equal, and we should select first available node

597-627: Clarify the TODO comment about parent entity chain selection.

The TODO comment suggests replacing the logic with "smallest parent entity chain" selection, but the current implementation already considers jump counts.

Consider clarifying or implementing the TODO:

-		// TODO: replace with all nodes check - select smallest parent entity chain
+		// TODO: Consider all possible parent chains and select the one with the minimum jumps
+		// Current implementation only checks the first valid parent chain found
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b96f7e and 7eeecc3.

📒 Files selected for processing (4)
  • v2/pkg/astvalidation/operation_rule_validate_empty_selection_set.go (1 hunks)
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource.go (1 hunks)
  • v2/pkg/engine/plan/datasource_filter_visitor.go (6 hunks)
  • v2/pkg/engine/plan/datasource_filter_visitor_test.go (8 hunks)
🧠 Learnings (1)
v2/pkg/engine/datasource/graphql_datasource/graphql_datasource.go (1)

Learnt from: SkArchon
PR: #1203
File: v2/pkg/engine/resolve/loader.go:63-67
Timestamp: 2025-07-02T15:28:02.122Z
Learning: In the graphql-go-tools codebase, result structs are consistently initialized with non-nil bytes.Buffer instances, making additional nil checks for res.out unnecessary defensive programming.

🧰 Additional context used
🧠 Learnings (1)
v2/pkg/engine/datasource/graphql_datasource/graphql_datasource.go (1)

Learnt from: SkArchon
PR: #1203
File: v2/pkg/engine/resolve/loader.go:63-67
Timestamp: 2025-07-02T15:28:02.122Z
Learning: In the graphql-go-tools codebase, result structs are consistently initialized with non-nil bytes.Buffer instances, making additional nil checks for res.out unnecessary defensive programming.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build and test (go 1.23 / windows-latest)
🔇 Additional comments (3)
v2/pkg/engine/datasource/graphql_datasource/graphql_datasource.go (1)

1687-1698: LGTM! Excellent defensive programming approach.

This validation rule integration effectively catches incorrect planner behavior by ensuring that only selection sets containing fields are processed. The clear comments explain the rationale well, and placing this validation in the pool initialization ensures consistent application across all operations.

This change aligns perfectly with the PR objectives around planner fixes for parent entity jumps and unique node selections.

v2/pkg/engine/plan/datasource_filter_visitor_test.go (1)

294-294: LGTM! Test updates align with simplified selection logic.

The test updates correctly reflect the changes in the main code where the selection reason strings have been simplified to "stage1: unique". This maintains test coverage while aligning with the refactored selection logic.

Also applies to: 563-564, 823-823, 832-832, 941-941, 959-959, 995-995, 998-998, 1008-1008, 1011-1011

v2/pkg/engine/plan/datasource_filter_visitor.go (1)

240-280: Verify impact of new root-node requirement in selectUniqNodeParentsUpToRootNode

It looks like no existing tests exercise this method or the ReasonStage1SameSourceParent path, so we can’t confirm that the change won’t break query planning. Please manually review and/or add tests to cover:

  • Calling selectUniqNodeParentsUpToRootNode when:
    • The parent chain never reaches a root node → expect no selections.
    • A root node is found but has DisabledEntityResolver == true → expect no selections.
    • A root node is found and resolver is enabled → expect all intermediate parents to be selected.
  • Behaviors when encountering an external parent with IsProvided == false.
  • Edge cases around IsRootNode on the initial item.

File to review:
• v2/pkg/engine/plan/datasource_filter_visitor.go (lines ~240–280)

Comment thread v2/pkg/engine/plan/datasource_filter_visitor.go Outdated
Comment thread v2/pkg/engine/plan/datasource_filter_visitor.go
@devsergiy devsergiy merged commit 1a7ed16 into master Jul 22, 2025
11 checks passed
@devsergiy devsergiy deleted the sergiy/eng-7397-fix-planner-parent-entity-jump branch July 22, 2025 18:45
devsergiy pushed a commit that referenced this pull request Jul 22, 2025
🤖 I have created a release *beep* *boop*
---


##
[2.0.0-rc.210](v2.0.0-rc.209...v2.0.0-rc.210)
(2025-07-22)


### Bug Fixes

* planner fixes for parent entity jumps and unique nodes selections
([#1230](#1230))
([1a7ed16](1a7ed16))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
@coderabbitai coderabbitai Bot mentioned this pull request Jul 28, 2025
3 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Oct 24, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant