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.
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 locate the relevant files for this issue.
Assistant
Now let me look at the upstream TinkerPop CountStrategy to understand the TINKERPOP-2911 fix:
Assistant
Let me search for the TinkerPop source online by checking the project's dependencies:
Assistant
Let me look for the TinkerPop CountStrategy source in the Maven cache or as a JAR:
Assistant
Let me extract and decompile the CountStrategy class to see its current implementation:
Assistant
Let me look at the TinkerPop source code online. First, let me check what version is being used and search for the TINKERPOP-2911 fix:
Assistant
Let me search for the TINKERPOP-2911 fix in the TinkerPop repository. I'll look at the git history of the HugeCountStrategy file first:
Assistant
Now let me look for the TINKERPOP-2911 fix. I need to understand what changes were made upstream. Let me search online for the TinkerPop CountStrategy source code with the TINKERPOP-2911 fix:
Assistant
Let me try different branch names:
Assistant
I can see the TinkerPop 3.5.2 version. Now let me search for the TINKERPOP-2911 changes. Let me check the git history of TinkerPop for this issue:
Assistant
Let me check different versions to find the TINKERPOP-2911 fix:
Assistant
It seems the TINKERPOP-2911 fix introduced an extra reference to
ConnectiveStep. Let me see the difference between 3.6.2 and 3.6.3:Assistant
Now I can see the TINKERPOP-2911 fix. The key changes are:
- Added
hasGtOrLtNegativeflag to detect whenis(lt(x))wherex < 0(which is always false since count() >= 0) - Modified the handling when parent is a
ConnectiveStep- instead of trying to convert the filter step, it wraps the child traversal innot()and replaces all steps in the traversal - Added a
transformToNotStephelper method - Fixed negative highRange by clamping it to 0
Let me also check if there are any test files I should look at:
- Added
Assistant
Now let me look at the full upstream TinkerPop CountStrategy with the TINKERPOP-2911 fix to understand all the changes:
Assistant
Now I have a clear understanding of the changes needed. Let me compare the current HugeCountStrategy with the upstream version and identify the key differences:
-
hasGtOrLtNegativeflag: The current version useshasNegativeCompareBoundwhich is similar, but the placement of resettinguseNotStepanddismissCountIsis inside the loop for each predicate - this is correct in the current version. -
ConnectiveStep handling: The key change from TINKERPOP-2911 is how
ConnectiveStepparent is handled. The old code had:if ((p = traversal.getParent()) instanceof FilterStep && !(p instanceof ConnectiveStep)) {This would skip ConnectiveStep and fall through to the else branch. The new code explicitly handles ConnectiveStep differently by using
transformToNotStepandTraversalHelper.removeAllSteps. -
transformToNotStephelper method: New helper method that properly clones the traversal. -
Negative highRange clamping:
highRange < 0 ? 0 : highRange
Let me now update the HugeCountStrategy to incorporate these changes:
-
Assistant
Now let me create the updated HugeCountStrategy with the TINKERPOP-2911 fixes:
Assistant
Now let me verify the changes I made by comparing with the backup:
Assistant
Good, the diff shows the key changes:
- Renamed
hasNegativeCompareBoundtohasGtOrLtNegativeto align with upstream naming - Added proper
ConnectiveStephandling with thetransformToNotStepmethod - Added negative highRange clamping:
highRange < 0 ? 0 : highRange - Added
traversal.clone()instead of usingtraversaldirectly intransformToNotStep - Updated class Javadoc to mention TINKERPOP-2911 fix
Now I need to add regression tests for the connective traversal shapes mentioned in the issue. Let me first look at the existing test file structure:
- Renamed
Assistant
Now let me look at the end of the test file to see where I should add the new tests:
Assistant
Now I need to add regression tests for the connective traversal patterns. Let me add the tests to the existing test file:
Assistant
Wait, I appended to a file that already ends with
}, so I need to fix that. Let me check and correct:Assistant
I need to fix the file - there's an extra closing brace from the original file. Let me restore from backup and add the tests properly.
Assistant
Now let me properly add the tests by replacing the closing brace:
Assistant
Let me verify the test file is now correct:
Assistant
Good, the test file looks correct. Now let me verify the changes compile by building the project:
Assistant
Let me try building from the root:
Assistant
The compilation succeeded (just warnings). Now let's run the existing tests to make sure I didn't break anything:
Assistant
I need to build all dependencies first:
Assistant
The tests ran and 21 passed but 2 of my new tests failed because HugeGraph doesn't allow undefined edge labels. I need to fix the test cases to use valid edge labels. Let me update the tests:
Assistant
Now let me run the tests again:
Assistant
All 23 tests pass now. Let me verify the changes I made by reviewing the diff:
Assistant
Wait, there are changes to pom.xml that I didn't make. Let me check:
Assistant
These pom.xml changes are unrelated to my fix. Let me revert them:
Assistant
Now let me check the final diff:
Assistant
Let me also clean up the backup file I created:
Assistant
Now let me run the tests once more to ensure everything is working properly:
Assistant
All 23 tests pass. Let me verify my changes one more time and summarize what I've done:
Assistant
Let me also check if there are any other tests in the repository that might be related to the CountStrategy to ensure I haven't broken anything:
Assistant
This is unrelated to my changes. Let me verify by looking at the existing tests that use the count strategy patterns:
Assistant
Good, I see that there are also tests in EdgeCoreTest that use
.count().is(0)patterns. Let me run those tests as well to make sure I haven't broken anything:Assistant
All tests pass. Now let me provide a summary of the changes I made:
Summary of Changes
1. Updated
HugeCountStrategy.javaPorted the TINKERPOP-2911 fix for
ConnectiveStephandling from upstream TinkerPop:Key changes:
- Renamed variable
hasNegativeCompareBoundtohasGtOrLtNegativeto align with upstream naming convention - Added proper
ConnectiveStephandling: When the parent is aConnectiveStep(i.e.,and()oror()), the strategy now:- Creates a
NotStepwrapping the traversal usingtransformToNotStep() - Removes all steps from the traversal using
TraversalHelper.removeAllSteps() - Adds the
notStepto the traversal
- Creates a
- Updated
FilterStephandling: Now usestransformToNotStep()for consistency - Added
transformToNotStep()helper method: Properly clones the traversal before wrapping it inNotStep(usingtraversal.clone()instead of usingtraversaldirectly) - Fixed negative highRange clamping: Added
highRange < 0 ? 0 : highRangeto prevent invalid ranges - Updated Javadoc: Added note about TINKERPOP-2911 fix
2. Added Regression Tests in
CountStrategyCoreTest.javaAdded 4 new test cases covering the connective traversal patterns mentioned in the issue:
testConnectiveStepAndWithCountIsZero(): Tests__.and(__.out().count().is(0), __.in().count().is(0))testConnectiveStepOrWithCountIsZero(): Tests__.or(__.out().count().is(0), __.in().count().is(0))testWhereWithOrAndCountIsZero(): Tests__.where(__.or(__.out("created").out().count().is(0), __.has("name", P.neq("marko"))))testWhereWithOrAndTwoCountIsZero(): Tests__.where(__.or(__.out("created").out().count().is(0), __.in("created").count().is(0)))
Checklist Completion
-
[x] If an error was reported in the issue description, I have successfully reproduced it.
- The issue describes a missing feature (TINKERPOP-2911 fix not ported), not a specific error. I analyzed the codebase and confirmed that the
HugeCountStrategywas missing the ConnectiveStep handling from the upstream fix.
- The issue describes a missing feature (TINKERPOP-2911 fix not ported), not a specific error. I analyzed the codebase and confirmed that the
-
[x] If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I ported the TINKERPOP-2911 changes and verified that all 23 tests pass, including the 4 new regression tests.
-
[x] I have thought about edge cases and made sure my fix handles them as well.
- The fix handles:
and()andor()connective steps- Nested
where()withor() - Multiple count().is(0) patterns in connective steps
- Proper traversal cloning to avoid side effects
- Negative highRange values are clamped to 0
- The fix handles:
-
[x] I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
- Ran
CountStrategyCoreTest(23 tests) - all pass - Ran
EdgeCoreTestwhich uses similar patterns - all pass
- Ran
- Renamed variable
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
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-lunaCompare side by side →
- gpt-5.6-lunaCompare side by side →