Repository navigation
Keep Coalesce(...) with a single sub-query from changing what that sub-query returns - #2474
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 14.x #2474 +/- ##
==========================================
+ Coverage 93.24% 93.54% +0.29%
==========================================
Files 279 279
Lines 7819 7871 +52
Branches 878 882 +4
==========================================
+ Hits 7291 7363 +72
+ Misses 333 313 -20
Partials 195 195 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… its parent Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ves the same inlined Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
danielcweber
force-pushed
the
optimize/single-traversal-coalesce
branch
from
September 30, 2026 09:52
ecaf218 to
0fba749
Compare
coalesce() with a single child traversal without the coalesce stepCoalesce(...) with a single sub-query from changing what that sub-query returns
This was referenced Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Coalesce(...)with a single sub-query no longer changes what that sub-query returns. Until now the steps of a single sub-query were always written directly into the surrounding query, sog.V<Person>().Coalesce(__ => __.Out<WorksFor>().Limit(1))was emitted asg.V().hasLabel('Person').out('WorksFor').limit(1)and returned one vertex in total, instead of up to one per person. It is now emitted asg.V().hasLabel('Person').flatMap(__.out('WorksFor').limit(1)): with nothing to fall back to, acoalesceof a single traversal is aflatMap. The same applies to every sub-query containing a step that acts on the whole stream once it is inlined:Limit,Range,Skip,Tail,Dedup,Order,Fold,Countand the other aggregations.A sub-query that gives the same result either way is emitted exactly as before, without any step around it:
Coalesce(__ => __.Out<WorksFor>())still becomesout('WorksFor'), filters still merge with the steps in front of them, andCoalesce(__ => __.Identity())still adds nothing to the query.Changes
Coalesce(...)query method adds the steps of a single sub-query to the query only if the new internalTraversal.IsLocal()says that they behave the same per element and as part of the surrounding query. Otherwise it adds aFlatMapStepwith that sub-query. Either way the query carries the projection of the sub-query.Coalesce(...)with two or more sub-queries is unchanged.IsLocal()is a conservative allow-list of steps: filters, navigation, one-to-one maps, string and date functions, steps whose own traversals are evaluated per element (map,flatMap,local,coalesce,project), and the scoped steps (limit,range,tail,skip,dedup,count,order,min,max,mean,sum) in local scope only. Everything else, and every traversal that writes, is not local.Coalesce(...)with a single sub-query was written as before, so the fix shows as changes to those snapshots. A test over all step classes makes a new step fail until it has been decided whether it is local.Notes
CoalesceSteppushed directly viaConfigureStepsis written as pushed.Coalesce(__ => __.Out().Limit(1))limiting the whole result, now gets per-element results. Moving the step out of theCoalesce(...)restores the previous query.flatMap(...)as well, even where inlining would have been harmless:Coalesce(__ => __.Drop())is now emitted asflatMap(__.drop())instead ofdrop(). The result is the same, the query is a little longer.Out()and withIdentity().🤖 Generated with Claude Code