Repository navigation
Fix STRATEGY BREADTH_FIRST performing a depth-first traversal - #5134
Conversation
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).
|
Tick the box to add this pull request to the merge queue (same as
|
There was a problem hiding this comment.
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.
Up to standards ✅🟢 Issues
|
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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)
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).