Skip to content

fix: right bound node lookups BED-7469#44

Open
urangel wants to merge 5 commits intomainfrom
BED-7469
Open

fix: right bound node lookups BED-7469#44
urangel wants to merge 5 commits intomainfrom
BED-7469

Conversation

@urangel
Copy link
Contributor

@urangel urangel commented Mar 23, 2026

Single step and expansion relationship patterns are updated to handle bindings associated with the right node.
Test cases that reflect the patterns in the reported issues have been added.

The okta example in the ticket:
image

Simplied BP-1590 pattern:
image

Shortest path, gh issue/BP-2257:
image

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed pattern matching for queries with bound node references, improving SQL translation accuracy
    • Enhanced support for complex multi-part path patterns and pattern expansion scenarios
    • Corrected shortest path query generation to properly resolve node and edge bindings
  • Documentation

    • Removed documentation of previously identified pattern binding defect

@coderabbitai
Copy link

coderabbitai bot commented Mar 23, 2026

Walkthrough

The changes fix pattern matching translation for right-node-bound scenarios and shortest-path queries by introducing a previousValidFrame mechanism in the expansion builder, updating test case SQL output to reflect corrected recursive CTE generation, and removing documentation of a now-fixed defect.

Changes

Cohort / File(s) Summary
Documentation
cypher/Cypher Syntax Support.md
Removed documentation describing a known defect pattern and its associated SQL translation error.
Test Case Updates
cypher/models/pgsql/test/translation_cases/multipart.sql, pattern_binding.sql, pattern_expansion.sql, shortest_paths.sql
Updated generated SQL test expectations for recursive CTE queries: modified recursive step FROM clauses and join correlation, adjusted node-kind filter predicates, and added new pattern-binding test cases.
Core Translation Logic
cypher/models/pgsql/translate/expansion.go
Refactored ExpansionBuilder to introduce previousValidFrame field for binding projection queries to prior materialized frames; changed constraint checking from PrimerNodeConstraints to PrimerNodeJoinCondition; updated shortest-path projection query construction and constraint rewriting semantics.
Pattern & Traversal Translation
cypher/models/pgsql/translate/pattern.go, traversal.go
Added derivation and assignment of previousValidFrame in shortest-path expansion pattern building; implemented RightNodeBound handling in traversal root builder with proper FROM clause and join construction.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 With frames now bound and traversals right,
Shortest paths shine with corrected light,
Recursive steps now dance in place,
Right-node bounds find their proper space,
A defect fixed, the syntax soars,
Pattern matching opens new doors! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the primary change: handling right-bound node lookups in relationship patterns, which is the main focus across multiple translation and pattern matching files.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BED-7469

Comment @coderabbitai help to get the list of available commands and usage tips.

Queries that contain similar constructs will result in the following translation error:
`ERROR: column notation .id applied to type nodecomposite[], which is not a composite type (SQLSTATE 42809)`.

### Right-Hand Bound Node Lookups
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The pattern noted here (and a few related patterns) has been fixed though it is unclear whether all possible occurrences of right-hand bound node lookups have been addressed.

Is removing this documentation premature?

@urangel urangel marked this pull request as ready for review March 23, 2026 15:41
Copy link

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cypher/models/pgsql/translate/expansion.go (1)

128-139: ⚠️ Potential issue | 🔴 Critical

Fix line 401: change condition check to PrimerNodeJoinCondition.

Lines 128 and 300 correctly check if expansionModel.PrimerNodeJoinCondition != nil before adding the primer node join, but line 401 in prepareBackwardFrontRecursiveQuery incorrectly checks if expansionModel.PrimerNodeConstraints != nil. Since the join uses s.traversalStep.Expansion.PrimerNodeJoinCondition as its constraint, the condition should match the field being used. Change line 401 to check PrimerNodeJoinCondition for consistency with the other two primer query functions and to ensure the join is added based on actual join condition presence rather than filter constraint presence.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cypher/models/pgsql/translate/expansion.go` around lines 128 - 139, The
prepareBackwardFrontRecursiveQuery function incorrectly checks
expansionModel.PrimerNodeConstraints before adding the primer node join; update
that condition to check expansionModel.PrimerNodeJoinCondition so it matches the
join's Constraint usage (s.traversalStep.Expansion.PrimerNodeJoinCondition) and
aligns with the checks in the other primer query functions (see the similar
blocks that use expansionModel.PrimerNodeJoinCondition to append to
nextQueryFrom.Joins).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@cypher/models/pgsql/translate/expansion.go`:
- Around line 128-139: The prepareBackwardFrontRecursiveQuery function
incorrectly checks expansionModel.PrimerNodeConstraints before adding the primer
node join; update that condition to check expansionModel.PrimerNodeJoinCondition
so it matches the join's Constraint usage
(s.traversalStep.Expansion.PrimerNodeJoinCondition) and aligns with the checks
in the other primer query functions (see the similar blocks that use
expansionModel.PrimerNodeJoinCondition to append to nextQueryFrom.Joins).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d44fbecb-98c0-40f5-8d9b-a79b820a07bd

📥 Commits

Reviewing files that changed from the base of the PR and between 21473e6 and 194bdd2.

📒 Files selected for processing (8)
  • cypher/Cypher Syntax Support.md
  • cypher/models/pgsql/test/translation_cases/multipart.sql
  • cypher/models/pgsql/test/translation_cases/pattern_binding.sql
  • cypher/models/pgsql/test/translation_cases/pattern_expansion.sql
  • cypher/models/pgsql/test/translation_cases/shortest_paths.sql
  • cypher/models/pgsql/translate/expansion.go
  • cypher/models/pgsql/translate/pattern.go
  • cypher/models/pgsql/translate/traversal.go
💤 Files with no reviewable changes (1)
  • cypher/Cypher Syntax Support.md

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