Skip to content

fix: optimized traversal bindings and directionless traversals w/ correlations BED-8320#98

Open
seanjSO wants to merge 5 commits into
mainfrom
seanj/BED-8320
Open

fix: optimized traversal bindings and directionless traversals w/ correlations BED-8320#98
seanjSO wants to merge 5 commits into
mainfrom
seanj/BED-8320

Conversation

@seanjSO

@seanjSO seanjSO commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Description

  • adds builder for row-correlated directionless traversals (ie., path predicates inside of a match)
  • adds exhaustive node bindings for optimized relationship exists builder, directionless traversals builder

Resolves: BED-8320

Type of Change

  • Chore (a change that does not modify the application functionality)
  • Bug fix (a change that fixes an issue)
  • New feature / enhancement (a change that adds new functionality)
  • Refactor (no behaviour change)
  • Test coverage
  • Build / CI / tooling
  • Documentation

Testing

  • Unit tests added / updated
  • Integration tests added / updated
  • Full test suite run (make test_all with CONNECTION_STRING set)

Screenshots (if appropriate):

Driver Impact

  • PostgreSQL driver (drivers/pg)
  • Neo4j driver (drivers/neo4j)

Checklist

  • Code is formatted
  • All existing tests pass
  • go.mod / go.sum are up to date if dependencies changed

Summary by CodeRabbit

  • New Features

    • Added support for undirected relationship patterns in queries, enabling bidirectional edge matching.
    • Enhanced pattern predicates to handle complex relationship scenarios with varied node binding configurations.
  • Tests

    • Added comprehensive test cases for undirected relationship pattern translations.
    • Added integration tests validating undirected pattern behavior with typed and untyped relationships.
  • Refactor

    • Improved traversal pattern optimization for relationship predicate handling.

@seanjSO seanjSO self-assigned this Jun 17, 2026
@seanjSO seanjSO added bug Something isn't working go Pull requests that update go code labels Jun 17, 2026
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f6e101f3-b04e-4e4d-aad3-6bb849172887

📥 Commits

Reviewing files that changed from the base of the PR and between 3265e86 and 4b400ce.

📒 Files selected for processing (10)
  • cypher/models/pgsql/model.go
  • cypher/models/pgsql/test/translation_cases/multipart.sql
  • cypher/models/pgsql/test/translation_cases/nodes.sql
  • cypher/models/pgsql/test/translation_cases/pattern_binding.sql
  • cypher/models/pgsql/translate/predicate.go
  • cypher/models/pgsql/translate/traversal.go
  • cypher/models/pgsql/translate/traversal_directionless.go
  • integration/testdata/bed8320.json
  • integration/testdata/cases/bed8320-correlated_undirected_pattern_predicates.json
  • integration/testdata/cases/bed8320-optimized_undirected_pattern_predicates.json

Walkthrough

Adds SQL translation support for undirected (directionless) Cypher relationship patterns in the PostgreSQL translator. A new traversal_directionless.go file implements four binding strategies. predicate.go and traversal.go are updated to dispatch to these builders. A new OptionalParenthetical helper is added, and SQL unit fixtures plus integration test data are added for validation.

Changes

Directionless Traversal Translation

Layer / File(s) Summary
OptionalParenthetical helper
cypher/models/pgsql/model.go
Adds OptionalParenthetical(optional Expression) Expression that returns nil for nil input or wraps non-nil input in a Parenthetical. Simplifies a var (...) block to var emptyU U.
Directionless traversal builder
cypher/models/pgsql/translate/traversal_directionless.go
Introduces the full directionless traversal translation file: defines directionlessSingleBoundPlan, implements buildDirectionlessTraversalPatternRoot dispatching to four strategies (expand-into, pairwise-both-bound, single-bound, unbound), adds OR-based pairwise edge constraint generation, and provides outer-correlation variants for all four strategies.
Predicate and traversal dispatch updates
cypher/models/pgsql/translate/predicate.go, cypher/models/pgsql/translate/traversal.go
Refactors buildOptimizedRelationshipExistPredicate to compute whereClause explicitly for all bound-endpoint combinations via OptionalParenthetical. Removes the direction-gate in buildPatternPredicates. Updates buildTraversalPatternRootWithOuterCorrelation to delegate DirectionBoth to the new directionless builder.
SQL translation test fixtures
cypher/models/pgsql/test/translation_cases/nodes.sql, cypher/models/pgsql/test/translation_cases/multipart.sql, cypher/models/pgsql/test/translation_cases/pattern_binding.sql
Adds and updates SQL test cases for undirected patterns, directionless EXISTS subqueries, multipart CTE chains with undirected edges, and path construction via ordered_edges_to_path.
Integration test graph and Cypher cases
integration/testdata/bed8320.json, integration/testdata/cases/bed8320-*.json
Adds the bed8320 test graph (10 nodes, 6 edges) and two case files covering optimized and correlated undirected predicates across all binding combinations (left/right/both-bound, unbound, typed/untyped, negated/non-negated).

Sequence Diagram(s)

sequenceDiagram
    participant Predicate as buildPatternPredicates
    participant TraversalRoot as buildTraversalPatternRootWithOuterCorrelation
    participant DirlessRoot as buildDirectionlessTraversalPatternRootWithOuterCorrelation
    participant Strategy as DirlessStrategy

    Predicate->>TraversalRoot: LeftNodeBound || RightNodeBound (any direction)
    TraversalRoot->>DirlessRoot: DirectionBoth → delegate
    DirlessRoot->>Strategy: dispatch(UseExpandInto / BothBound / SingleBound / Unbound)
    Strategy-->>DirlessRoot: edge JOIN node (OR direction constraint)
    DirlessRoot-->>TraversalRoot: EXISTS subquery with pairwise OR whereClause
    TraversalRoot-->>Predicate: correlated EXISTS predicate
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • SpecterOps/DAWGS#73: Modifies the same predicate.go buildOptimizedRelationshipExistPredicate and traversal root correlation logic alongside translation test updates.
  • SpecterOps/DAWGS#88: Refactors traversal and predicate placement in the same PostgreSQL translation pipeline that this PR extends for directionless support.

Suggested reviewers

  • zinic

🐇 Hoppity hop, no direction to pick,
Left OR right — the edge does the trick!
A pairwise constraint with OR in the middle,
Directionless paths solved the bidirectional riddle.
CTEs built high, existence confirmed,
The rabbit tests patterns, all cases affirmed! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main changes: fixing optimized traversal bindings and directionless traversals with correlations, while referencing the ticket BED-8320.
Description check ✅ Passed The description covers all required template sections: it clearly explains what the PR does (row-correlated directionless traversals, exhaustive node bindings), references the issue (BED-8320), marks appropriate change types and testing methods, and confirms driver impact and checklist items.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 seanj/BED-8320

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

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

@brandonshearin brandonshearin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sean spent about 3 hours downloading his mental model of this problem to me, the layman of all laymans.

His manual testing strategy against a live neo and pg backend, and the automated test coverage he has included in the changeset itself give me confidence that this bug has been conquered for all time.

Great work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants