Skip to content

Fix STRATEGY BREADTH_FIRST performing a depth-first traversal - #5134

Merged
lvca merged 1 commit into
ArcadeData:mainfrom
saevarb:fix/breadth-first-traversal-order
Jul 9, 2026
Merged

lvca merged 1 commit into
ArcadeData:mainfrom
saevarb:fix/breadth-first-traversal-order

Conversation

@saevarb

@saevarb saevarb commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

BreadthFirstTraverseStep pushed newly discovered nodes onto the front of the entryPoints deque (addFirst) while consuming from the front (removeFirst), making it a LIFO stack: STRATEGY BREADTH_FIRST actually walked the graph depth-first. Its own prettyPrint even reported "DEPTH-FIRST TRAVERSE". The step has behaved this way since the first commit (OrientDB's BreadthFirstTraverseStep is a correct FIFO).

Push discovered nodes to the end (addLast) so entryPoints is a FIFO queue and the traversal is genuinely breadth-first, and correct the prettyPrint label.

The existing breadthFirst() test could not catch this: it ran on a linear chain (a->b->c->d), on which breadth-first and depth-first emit the identical sequence, so the STRATEGY had no observable effect. Replace it with breadthFirstOrder() and depthFirstOrder(), which run on a balanced binary tree (two branches of equal depth) and assert the emitted $depth sequence -- [0,1,1,2,2,2,2] for BFS vs [0,1,2,2,1,2,2] for DFS. Sibling order within a level is not asserted (TRAVERSE has no clause to control expansion order, and BFS does not guarantee it).

BreadthFirstTraverseStep pushed newly discovered nodes onto the front of
the entryPoints deque (addFirst) while consuming from the front
(removeFirst), making it a LIFO stack: STRATEGY BREADTH_FIRST actually
walked the graph depth-first. Its own prettyPrint even reported
"DEPTH-FIRST TRAVERSE". The step has behaved this way since the first
commit (OrientDB's BreadthFirstTraverseStep is a correct FIFO).

Push discovered nodes to the end (addLast) so entryPoints is a FIFO
queue and the traversal is genuinely breadth-first, and correct the
prettyPrint label.

The existing breadthFirst() test could not catch this: it ran on a
linear chain (a->b->c->d), on which breadth-first and depth-first emit
the identical sequence, so the STRATEGY had no observable effect.
Replace it with breadthFirstOrder() and depthFirstOrder(), which run on
a balanced binary tree (two branches of equal depth) and assert the
emitted $depth sequence -- [0,1,1,2,2,2,2] for BFS vs [0,1,2,2,1,2,2]
for DFS. Sibling order within a level is not asserted (TRAVERSE has no
clause to control expansion order, and BFS does not guarantee it).
@mergify

mergify Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request fixes the breadth-first traversal strategy in BreadthFirstTraverseStep by correctly adding entry points to the end of the queue (addLast) instead of the front (addFirst), which previously caused it to behave like a depth-first traversal. It also corrects the string representation in prettyPrint to output 'BREADTH-FIRST TRAVERSE' instead of 'DEPTH-FIRST TRAVERSE'. Additionally, the tests in TraverseStatementExecutionTest have been updated to thoroughly verify both breadth-first and depth-first traversal order contracts on a balanced binary tree. There are no review comments, so we have no further feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 65.91%. Comparing base (32b1582) to head (c1cffc7).
⚠️ Report is 22 commits behind head on main.

Files with missing lines Patch % Lines
...b/query/sql/executor/BreadthFirstTraverseStep.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5134      +/-   ##
============================================
+ Coverage     65.84%   65.91%   +0.06%     
- Complexity      913      931      +18     
============================================
  Files          1692     1692              
  Lines        136278   136278              
  Branches      29129    29129              
============================================
+ Hits          89736    89828      +92     
+ Misses        34336    34215     -121     
- Partials      12206    12235      +29     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lvca
lvca self-requested a review July 9, 2026 01:02
@lvca lvca added this to the 26.7.2 milestone Jul 9, 2026
@lvca

lvca commented Jul 9, 2026

Copy link
Copy Markdown
Member

Reviewed and verified end-to-end (fix + regression guard confirmed). Tracking issue: #5158. Closes #5158.

@lvca
lvca merged commit f0a9a56 into ArcadeData:main Jul 9, 2026
15 of 21 checks passed
robfrank pushed a commit that referenced this pull request Aug 14, 2026
BreadthFirstTraverseStep pushed newly discovered nodes onto the front of
the entryPoints deque (addFirst) while consuming from the front
(removeFirst), making it a LIFO stack: STRATEGY BREADTH_FIRST actually
walked the graph depth-first. Its own prettyPrint even reported
"DEPTH-FIRST TRAVERSE". The step has behaved this way since the first
commit (OrientDB's BreadthFirstTraverseStep is a correct FIFO).

Push discovered nodes to the end (addLast) so entryPoints is a FIFO
queue and the traversal is genuinely breadth-first, and correct the
prettyPrint label.

The existing breadthFirst() test could not catch this: it ran on a
linear chain (a->b->c->d), on which breadth-first and depth-first emit
the identical sequence, so the STRATEGY had no observable effect.
Replace it with breadthFirstOrder() and depthFirstOrder(), which run on
a balanced binary tree (two branches of equal depth) and assert the
emitted $depth sequence -- [0,1,1,2,2,2,2] for BFS vs [0,1,2,2,1,2,2]
for DFS. Sibling order within a level is not asserted (TRAVERSE has no
clause to control expansion order, and BFS does not guarantee it).

(cherry picked from commit f0a9a56)
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.

2 participants