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) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. Assistant
I'll start by exploring the repository structure to understand the codebase and locate the relevant files.
Assistant
The open command doesn't take a line number parameter with that name. Let me just open the file first.
Assistant
Now let me look at the upstream TinkerPop
CountStrategyto see what changes were made inTINKERPOP-2911forConnectiveStephandling.Assistant
Now let me search for the TINKERPOP-2911 fix in the upstream TinkerPop repository. First, let me check if there's a local copy of TinkerPop or any reference to the CountStrategy.
Assistant
Let me search online for the TINKERPOP-2911 fix by looking at the TinkerPop source. First, let me check the Maven dependencies to understand the TinkerPop version being used:
Assistant
Now I need to understand what the TINKERPOP-2911 fix is about. Let me search for any references to it in the codebase or look up the TinkerPop CountStrategy source:
Assistant
Let me decompile the CountStrategy class to see the current implementation:
Assistant
Let me download the sources jar and examine the CountStrategy:
Assistant
Now I can see the upstream TinkerPop 3.5.1 CountStrategy. Let me compare it with the current HugeCountStrategy. Let me also look at the latest TinkerPop 3.7.x which should include TINKERPOP-2911:
Assistant
Now I can see the differences between the TinkerPop 3.5.1 CountStrategy and the 3.7.1 version. The key changes for TINKERPOP-2911 in 3.7.1 include:
- Added
hasGtOrLtNegativeflag (similar tohasNegativeCompareBoundin HugeCountStrategy) - Key change for ConnectiveStep handling: When the parent is a
ConnectiveStep(and/or), instead of replacing the filter step, it wraps the child traversal innot()and replaces all steps in the traversal with thisnot()step - Added a helper method
transformToNotStep()to handle the transformation - Fixed negative range handling:
new RangeGlobalStep<>(traversal, 0L, highRange < 0 ? 0 : highRange)to prevent negative ranges - Using
traversal.clone()instead of justtraversalwhen creating NotStep
Let me also check the git log to see the changes related to TINKERPOP-2911:
- Added
Assistant
Now let me compare the current HugeCountStrategy with the upstream 3.7.1 version to identify exactly what changes need to be made:
Assistant
Now let me identify the exact differences. Looking at the current HugeCountStrategy vs the upstream 3.7.1 version, I need to port the following changes:
- When
useNotStep || dismissCountIsis true and parent isConnectiveStep: Handle it specially by wrapping the child innot()and replacing all traversal steps - Add
transformToNotStep()helper method for creating NotStep with proper cloning - Fix negative range handling:
highRange < 0 ? 0 : highRangein RangeGlobalStep - Use
traversal.clone()instead oftraversalwhen creating NotStep inside FilterStep
Let me now look at the current HugeCountStrategy more carefully to understand the exact changes needed:
- When
Assistant
Now I understand the changes needed. Let me create the updated HugeCountStrategy with the TINKERPOP-2911 fixes:
The key changes are:
-
When
useNotStep || dismissCountIsis true and!dismissCountIs:- Handle
ConnectiveStepparent specially (lines 193-205 in current code) - Add
transformToNotStep()helper method that usestraversal.clone() - Use
transformToNotStep()forFilterStepcase too
- Handle
-
In the
elsebranch (line 248-250): UsehighRange < 0 ? 0 : highRangeto clamp negative ranges (though HugeGraph already handles this by settinghighRange = nullfor negative values, but we should still be consistent)
Let me now make the changes:
-
Assistant
Now let me verify the file was updated correctly:
Assistant
Good, the file is updated. Now let me verify the changes by comparing the key sections with the original. Let me also look at the existing tests and see if I can run them:
Assistant
Let me check if Maven is available and try to compile the project to make sure my changes are syntactically correct.
Assistant
Let me try compiling from the root to install dependencies first:
Assistant
The build seems to have succeeded. Now let me run the existing tests related to CountStrategy:
Assistant
Let me try a different approach - run the tests from the server module:
Assistant
Let me try a different approach and build the entire project properly first:
Assistant
The build succeeded. Now let me run the CountStrategyCoreTest:
Assistant
Let me try running tests from the parent project level with all dependencies:
Assistant
Let me try a different approach - run tests with the flag to ignore no tests:
Assistant
All 19 tests in CountStrategyCoreTest pass! Now let me also add regression tests for the connective traversal shapes mentioned in the issue. Let me first examine the test file more closely and understand the test patterns:
Assistant
Now let me create a temporary test script to verify the connective step handling works correctly with my changes. This will help confirm the fix before adding tests:
Assistant
Let me copy this test file to the test directory and run it:
Assistant
I need to add the Apache license header. Let me fix the test file:
Assistant
I see - one test passed (testOrConnectiveWithCount) but the others have issues:
testAndConnectiveWithCount- needs index on "name" propertytestWhereOrWithCountAndHasandtestWhereOrWithCountAndHasCount- need to define the "none" edge label
Let me fix the test file:
Assistant
All 4 new regression tests pass. Now let me also run the existing CountStrategyCoreTest to make sure I didn't break anything:
Assistant
Excellent! All tests pass. Let me now verify the changes I made by viewing the git diff:
Assistant
Let me check the pom.xml changes - I see there are some changes there that I didn't intend to make:
Assistant
I see - these pom.xml changes were already present before I started working (probably from the build process). Let me revert these unrelated changes:
Assistant
Assistant
Now let me verify my changes one more time by running all the related tests again to ensure everything still works:
Assistant
All 23 tests pass (19 from CountStrategyCoreTest + 4 from ConnectiveStepCountTest). Let me now verify the final state of my changes:
Assistant
Let me also verify the new test file:
Assistant
Now let me summarize the changes I made and verify everything is complete:
Summary of Changes
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.