ISSUE DESCRIPTION [Improve] Align HugeCountStrategy with upstream TINKERPOP-2911…
- User
ISSUE DESCRIPTION
[Improve] Align HugeCountStrategy with upstream TINKERPOP-2911 ConnectiveStep fixes
Feature Description (功能描述)
Background
PR #2993 introduced
HugeCountStrategyto fix the negative-bound optimization issues behind #2930, #2931, and #2932.That fix was implemented by forking an older version of TinkerPop's
CountStrategyand adding HugeGraph-specific guards for negative bounds.However, the current local fork does not yet include the upstream follow-up fix for
ConnectiveStep/and()/or()handling fromTINKERPOP-2911.As a result, HugeGraph is now aligned for the negative-bound cases fixed in #2993, but it may still inherit older
CountStrategybehavior for some connective-filter patterns.Follow-up Scope
Port the upstream
TINKERPOP-2911changes forConnectiveStepintoHugeCountStrategy, and add regression coverage for connective traversal shapes.Suggested regression cases include:
__.and(__.out().count().is(0), __.in().count().is(0))__.or(__.out().count().is(0), __.in().count().is(0))__.where(__.or(__.out("none").out().count().is(0), __.has("none")))__.where(__.or(__.out("none").out().count().is(0), __.has("none").count().is(0)))
Expected Result
HugeCountStrategyshould behave consistently with the upstreamCountStrategyfixes aroundConnectiveStep- connective
and()/or()traversal shapes should no longer rely on older inherited behavior from the forked strategy - regression tests should cover the above traversal forms and protect against future drift
I’d be happy to follow up on this as a separate improvement issue and work on a later refinement PR.
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /hugegraph, current file: none) bash-$
Assistant
I'll start by exploring the repository structure to understand the codebase and find the relevant files mentioned in the issue.
Assistant
Now let me look at the test file:
Assistant
Now let me look at the upstream TinkerPop
CountStrategyto understand whatTINKERPOP-2911changes look like. Let me check the TinkerPop dependency version:Assistant
Let me get the full decompiled output of the upstream
CountStrategyto understand theTINKERPOP-2911changes:Assistant
Now let me look at the TINKERPOP-2911 fix details. Let me check the
ConnectiveStephandling difference. The key change in TINKERPOP-2911 is indoStrategy: it adds a check forConnectiveStepas the parent. Let me look more closely at the upstreamdoStrategy:Assistant
Let me look for the TINKERPOP-2911 source code. The key issue is about
ConnectiveStephandling. Let me look at the upstream source from the TinkerPop github:Assistant
Now let me understand the key difference in TINKERPOP-2911. Let me search for the source of the upstream CountStrategy. The key change is that in
doStrategy, it addsConnectiveStepas a special case - when the parent is aConnectiveStep, it should also do the strategy. Let me look at the actual source:Assistant
Now I can see the key changes in TINKERPOP-2911. Let me also check the
HugeCountStrategyversion and the git history to understand what was already fixed:Assistant
Now I have a clear picture. Let me check if
TraversalHelper.removeAllStepsexists in 3.5.1:Assistant
Good,
removeAllStepsexists. Now let me compare the current HugeCountStrategy with the latest upstream. Let me understand the key differences:-
TINKERPOP-2911 ConnectiveStep handling: The upstream 3.7.0 version added special handling for
ConnectiveStepparents: whenparent instanceof ConnectiveStep, it wraps the child ofand()/or()innot()usingtransformToNotStepandremoveAllSteps. The current HugeGraph version uses the older code path that falls into theelsebranch (prev-based NotStep handling) forConnectiveStep. -
transformToNotStepusestraversal.clone()instead oftraversaldirectly - the current HugeGraph code usestraversaldirectly. -
highRange < 0 ? 0 : highRangeinRangeGlobalStep- the HugeGraph version already handles this with a separateif (highRange != null && highRange < 0L) { highRange = null; }block (which is actually different - it nullifies instead of clamping to 0).
Let me first create a test to reproduce the issue with connective traversals:
-
Assistant
Now let me write a reproduction test to understand what the current behavior is. Let me create a temporary test:
Assistant
Need to add the license header. Let me fix the test file:
Assistant
The "none" edge label needs to exist in schema for HugeGraph. Let me update the test to add those schema items (with no data, so they return empty):
Assistant
I found the bug.
testWhereOrWithNoneAndHasNoneexpects 3 (all vertices match becauseout("none").out().count().is(0)is true for all), but returns 0. This is the ConnectiveStep handling bug.Let me now look at the current HugeCountStrategy code more carefully and apply the TINKERPOP-2911 fix:
Assistant
Now I'll apply the TINKERPOP-2911 fix. Let me replace the
if (!dismissCountIs)block to add ConnectiveStep handling:Assistant
Let me use the
editcommand instead. First let me view the exact lines to replace:Assistant
Now let me add the
transformToNotStephelper method. Let me view the end of the file:Assistant
I see there's a duplication. Let me fix lines 272-317:
Assistant
Now let me verify the file compiles by building the core module:
Assistant
There's a generics type inference issue. The upstream uses raw
Steptype. Let me fix thefilterStepdeclaration:Assistant
Now let me try to compile again:
Assistant
It compiles. Now let me run the reproduction test:
Assistant
Need to use
-amflag to build dependencies:Assistant
All 4 tests pass. The key fix:
testWhereOrWithNoneAndHasNonewent from 0 (wrong) to 3 (correct). Now let me run the existingCountStrategyCoreTestto ensure nothing broke:Assistant
All 19 existing tests pass. Now let me add regression tests for the connective traversal shapes to the existing test file. First, let me clean up my temp test:
Assistant
Now let me add regression tests to the
CountStrategyCoreTestfile. Let me open the end of the test file:Assistant
Let me look at the end of the test file to add new tests. I need to add regression tests for the connective traversal shapes mentioned in the issue:
__.and(__.out().count().is(0), __.in().count().is(0))__.or(__.out().count().is(0), __.in().count().is(0))__.where(__.or(__.out("none").out().count().is(0), __.has("none")))__.where(__.or(__.out("none").out().count().is(0), __.has("none").count().is(0)))
I need a schema with "none" edge label and "none" property key. Let me add a separate init method or extend the existing initSchema. I'll add a separate helper for the connective tests that includes "none" label/key.
Let me view the end of the file first.
Assistant
Now let me add the regression tests. I'll add a new schema init method that includes the "none" label/key, and add tests for the connective traversal shapes:
Assistant
Let me check the expected values more carefully. Let me verify the graph structure and correct the assertions. Let me run the tests to see actual values:
Assistant
The actual values match my careful semantic derivation. Let me fix the assertions and comments to be correct:
testAndConnectiveCountIsZero: and(out==0, in==0) → no vertex has both 0 out and 0 in → 0testOrConnectiveCountIsZero: or(out==0, in==0) → marko(in=0), josh(out=0), lop(out=0) → 3testOrConnectiveWithNegativeBoundKeepsSemantics: or(out.lt(-1) [always false], in==0) → marko(in=0) → 1
Assistant
Now let me fix the last assertion for
testOrConnectiveWithNegativeBoundKeepsSemantics:Assistant
Now let me run the full test suite again:
Assistant
All 25 tests pass (19 existing + 6 new). Now let me verify the fix doesn't break the negative-bound regression by checking that the strategy is being properly applied. Let me also verify the fix actually transforms the traversal correctly by writing a quick verification script that prints the traversal after strategy application:
Assistant
Let me remove the verification script since the tests already confirm correctness:
Assistant
Now let me verify the old behavior was actually broken by reverting the fix temporarily and running the new tests. First, let me check the diff of my changes:
Assistant
Let me verify the old behavior was broken by temporarily stashing my fix and running just the new tests:
Assistant
This confirms the bug exists in the old code:
testWhereOrWithNonExistentLabelAndHasNonefails withexpected:<3> but was:<0>. Now let me restore my fix:Assistant
I see there's a
pom.xmlmodification. Let me check what that is:Assistant
The
pom.xmlchanges are unrelated to my fix (they appear to be pre-existing environment modifications for lombok/compiler plugin). Let me revert them to keep my submission focused:Assistant
Now let me run the full test suite one more time to confirm everything passes after the pom.xml revert:
Assistant
All 25 tests pass. Now let me also run a broader set of related tests to make sure I haven't broken anything else. Let me check what other test classes might be affected by the CountStrategy change:
Assistant
Let me find the test method name and run it to confirm it still works with the connective + repeat pattern:
Assistant
That test passes. Now let me run a broader test to check for any regressions. Let me run the full EdgeCoreTest and VertexCoreTest which are the most likely to use traversals:
Assistant
All 168 EdgeCoreTest tests pass. Let me also check there's a TinkerPop test suite that might be relevant. Let me search for any count strategy related tests in the test suite:
Assistant
Good, only those two test files use count().is(). Both pass now. Let me also verify the final state of the HugeCountStrategy file is correct:
Assistant
The implementation looks correct and matches the upstream TINKERPOP-2911 approach. Let me run the full CountStrategyCoreTest one final time and verify no temp files are left:
Assistant
No temp files left. Let me run the full CountStrategyCoreTest suite one final time to confirm everything is green:
Assistant
All 25 tests pass. Let me do a final review of the complete diff:
Assistant
The diff is clean and focused. Let me do a final verification run of both affected test suites together:
Assistant
All tests pass. Let me now go through the checklist before submitting:
Checklist Review
-
[x] If an error was reported in the issue description, I have successfully reproduced it. — Yes. The issue described that connective
and()/or()traversal shapes still rely on older inheritedCountStrategybehavior. I reproduced the concrete bug:__.where(__.or(__.out("none").out().count().is(0), __.has("none")))returned0matching vertices with the old code, when it should return3(sinceout("none")yields nothing, makingcount().is(0)always true). -
[x] If an error was reported in the issue description, I have confirmed that my fix resolves the error. — Yes. After porting the TINKERPOP-2911
ConnectiveStephandling, the same traversal correctly returns3. I verified by stashing the fix and confirming the test failed with old code (expected:<3> but was:<0>), then restoring the fix and confirming it passes. -
[x] I have thought about edge cases and made sure my fix handles them as well. — Yes. I considered: (a) connective children with prefix steps before
count()(e.g.,out("none").out().count().is(0)) — now the whole prefix is wrapped innot(); (b) connective children with negative bounds — the #2993/TINKERPOP-2893 guards still fire (useNotStep/dismissCountIsset false, negativehighRangenullified), preserving semantics; (c) empty child after removing count+is —transformToNotStepfalls back to__.identity(); (d) the non-connectiveFilterStepcase — refactored to usetransformToNotStepwithclone()(matches upstream, equivalent behavior, existing tests pass); (e)repeat().until(or(...))connective pattern used inEdgeCoreTest#testQueryCountAsCondition— still passes. -
[x] I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. — Yes.
CountStrategyCoreTest(25 tests: 19 existing + 6 new) andEdgeCoreTest(168 tests, includingtestQueryCountAsConditionwhich usesor(inE().count().is(0), loops().is(3))inside repeat/until) all pass.
The solution ports the upstream
TINKERPOP-2911ConnectiveStepfix intoHugeCountStrategy:- Added an explicit
parent instanceof ConnectiveStepbranch that wraps the entire child traversal in aNotStep(via a newtransformToNotStephelper), then replaces the child's steps with just thatNotStep— instead of the old behavior that only rewrote the trailing step beforecount()and discarded prefix steps. - Refactored the
FilterStepbranch to reusetransformToNotStep(which usestraversal.clone()so the original traversal can be safely cleared). - Added 6 regression tests covering the suggested connective traversal shapes plus negative-bound connective cases.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →