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 and finding the relevant files.
Assistant
Let me start by exploring the repository.
Assistant
Now let me look at the upstream TinkerPop CountStrategy to understand what TINKERPOP-2911 changed. Let me find the TinkerPop version used.
Assistant
I'll make single calls. Let me find the TinkerPop version and any existing tests.
Assistant
Now let me look at the upstream TinkerPop CountStrategy to understand the TINKERPOP-2911 changes. Let me find the TinkerPop source.
Assistant
Let me look at the TinkerPop 3.5.1 CountStrategy source to understand the current upstream version and what TINKERPOP-2911 changed. Let me extract the source jar.
Assistant
Let me decompile the upstream CountStrategy class to compare.
Assistant
Let me see the rest of the bytecode to understand the full upstream version. The key thing about TINKERPOP-2911 is about ConnectiveStep handling. Let me look at the rest of the bytecode and compare with the local fork.
Actually, let me understand the issue more. The local fork is based on an older CountStrategy. The upstream TINKERPOP-2911 fix is about ConnectiveStep handling. Let me look at the rest of the bytecode.
Actually, instead of reading bytecode, let me search for what TINKERPOP-2911 actually changed. The issue is about ConnectiveStep / and() / or() handling. Let me understand the differences.
Let me look at the rest of the bytecode, especially the part after offset 674.
Assistant
Let me check the git history of the HugeCountStrategy file and understand the PR #2993 context.
Assistant
Let me see what the fork added on top of the original CountStrategy by viewing the full diff.
Assistant
Let me check how the strategy is registered in HugeGraph and whether TinkerPop's CountStrategy is also active.
Assistant
Let me check the TinkerPop version used and look for any newer CountStrategy reference.
Assistant
Let me understand the test infrastructure to reproduce the regression cases.
Assistant
Let me look at the TinkerPop test jar for CountStrategy tests to understand expected behavior.
Assistant
Let me check whether I can access the internet to get the newer TinkerPop source with the TINKERPOP-2911 fix.
Assistant
Maven can access the internet. Let me download newer TinkerPop sources to find the TINKERPOP-2911 fix.
Assistant
I found the upstream 3.6.4 CountStrategy with both TINKERPOP-2893 and TINKERPOP-2911 fixes. Let me compare the key TINKERPOP-2911 ConnectiveStep change. Let me check how HugeGraph steps handle cloning and the TraversalHelper methods available.
Assistant
Let me verify the 3.5.1 API has
removeAllStepsandTraversal.clone().Assistant
Let me check the
addStepdefault implementation to understand if it resets the step's traversal.Assistant
Let me find the
addStepdefault implementation in the Traversal interface (3.5.1 source).Assistant
The default
addStep(Step)callsaddStep(size, step). Let me check the DefaultTraversal.addStep(int, Step) to see if it calls setTraversal.Assistant
At offset 171-173,
addStepcallsstep.setTraversal(this), so the NotStep's traversal gets reset to the child. Good. Now let me check the strategy execution order to know what step types are present when HugeCountStrategy runs, and whether HugeGraph steps clone properly.Assistant
Let me check if HugeVertexStep/HugeGraphStep override
clone()properly, since they have extra state.Assistant
Let me check the strategy types and execution order to determine what step types are present when HugeCountStrategy runs.
Assistant
Let me check the NotStep constructor to understand how the inner filter traversal's parent is set.
Assistant
Let me look at the CoreTestSuite to understand the test backend setup.
Assistant
Let me check the test configuration to find which backend is used.
Assistant
The backend is configured via
${backend}property. Let me find how it's set (probably a maven profile or system property). Let me look at the pom.xml of hugegraph-test.Assistant
The default backend is
memory. Let me try to run the existing CountStrategyCoreTest to confirm the environment works before making changes.Assistant
The core module built. Now let me build the test module dependencies and try running the existing test.
Assistant
The test module needs the root pom with
${revision}resolved. Let me check the revision property and install needed modules.Assistant
This looks like a flatten-maven-plugin issue with
${revision}. Let me check.Assistant
There's a flatten-maven-plugin in hugegraph-server/pom.xml with
resolveCiFriendliesOnly. The flatten plugin generates.flattened-pom.xmlthat resolves${revision}to the literal version. The root pomhugegraphdoesn't have the flatten plugin (only hugegraph-server does). The installed root pom at 1.7.0 still has<version>${revision}</version>which is the problem.The flatten plugin is only configured in hugegraph-server/pom.xml. The root pom and hugegraph-struct don't have it. So when hugegraph-struct's pom references parent
hugegraph:pom:${revision}, and the installed root pom has<version>${revision}</version>... actually the installed root pom IS at path 1.7.0/ but its content says<version>${revision}</version>. Maven uses the directory version (1.7.0) for matching but reads the pom content.Hmm, this is getting complicated. The earlier
install -amfor hugegraph-test succeeded. Why doestestfail now?Oh wait — maybe the install put the poms in the local repo WITHOUT flattening (because flatten is bound to hugegraph-server only). When I ran
install -amstarting from hugegraph-test, it built hugegraph-test's reactor which includes hugegraph-server modules (with flatten) but NOT the root pom or hugegraph-struct necessarily with flatten.Actually, the issue: hugegraph-struct's parent is the root
hugegraphpom. The root pom has<version>${revision}</version>. When installed, it goes to 1.7.0/ but the pom content has${revision}. When another module references parenthugegraph:${revision}, maven resolves${revision}→ 1.7.0 (from the property in the current reactor), looks uphugegraph:pom:1.7.0, finds it (path 1.7.0/), reads it, sees<version>${revision}</version>in the parent's own version...Actually, I think the real problem is that during
testphase (not install), maven resolves hugegraph-struct as a dependency from the local repo, and its parent pomhugegraph:pom:${revision}can't be resolved because there's no reactor context to expand${revision}for a dependency's parent.The fix: install the root pom and struct with flattened versions, OR run the test in a way that includes the full reactor. Let me try running the test with the full reactor from the root, or install everything first.
Actually, the simplest: run
mvn testfrom the server directory with-pl hugegraph-test -ambut ALSO make sure the root pom is installed with flattening. But the root pom doesn't have flatten.Alternatively, I recall the earlier
install -amfor hugegraph-test "succeeded" — but did it actually install hugegraph-struct? The error now is about resolving hugegraph-struct as a dependency. Let me check if hugegraph-struct is installed.Let me check the local repo for hugegraph-struct.
Assistant
The single-module test fails because the parent pom uses
${revision}. I need-amto include the reactor. Let me run the existing test with-am.Assistant
Compilation succeeded; only the surefire-junit4 runner is missing. Let me download it (online mode).
Assistant
Let me check the test results and the JaCoCo configuration issue.
Assistant
The existing tests pass (19, 0 failures). Now let me write a temporary reproduction test for the 4 regression cases. Let me first check how HugeGraph handles
out("none")(nonexistent label) andhas("none").Assistant
I need to add the license header. Let me add it.
Assistant
Cases 3 and 4 error out. Let me see the actual exception details.
Assistant
The error is
Undefined edge label: 'none'— HugeGraph validates labels. I need to define "none" as an edge label and property key (with no data) so they yield empty results. Let me update the temp test schema.Assistant
No python. Let me use the editor's replace command.
Assistant
The bug is confirmed: case 3 returns 0 instead of 3 (case 4 coincidentally returns 3 but child1 is semantically wrong). Now let me check if any existing tests hit the FilterStep NotStep branch (non-Connective) with a non-negative bound, to assess the risk of switching to clone.
Assistant
There's an existing test in EdgeCoreTest using
until(__.or(__.inE().count().is(0), __.loops().is(3)))which exercises the ConnectiveStep branch. Let me examine it.Assistant
The bug is confirmed: case 3 returns 0 instead of 3 (case 4 returns 3 coincidentally but child1 is semantically wrong).
Now I understand the TINKERPOP-2911 fix. The current local fork, for
ConnectiveStepchildren, uses a "prev-based fold" that only negates the trailing steps beforecount()— breaking semantics when there are multiple non-filter steps before count. The upstream fix wraps the entire child traversal innot(). Let me view the exact lines to edit.Assistant
Now I'll implement the TINKERPOP-2911 fix. I'll replace the
if (!dismissCountIs)block with a three-way structure matching upstream:ConnectiveStepwraps the entire child innot(),FilterStep(non-connective) replaces the parent filter withnot(), and theelsekeeps the prev-based fold forSideEffectStep. Let me edit.Assistant
There's a duplicate
} else if (size == 0) {on lines 251-252. Let me fix that.Assistant
Now let me add the
transformToNotStephelper method after theapplymethod (beforedoStrategy).Assistant
There's an extra
}on line 273 (my replacement mistakenly started with a closing brace). Let me view and fix.Assistant
Let me add a blank line between the helper and
doStrategyfor readability.Assistant
The code looks good. Let me add a couple more test cases to my temp test to verify the FilterStep (non-connective) clone path and multi-step FilterStep handling, then rebuild and test.
Assistant
Now let me rebuild the core module and run the temp repro test.
Assistant
The build failed. Let me see the actual error.
Assistant
Checkstyle is reporting pre-existing issues. Let me check if the failure is due to my file specifically (compile or checkstyle).
Assistant
Two issues: a checkstyle info warning (pre-existing) and a compile error —
replaceStepgeneric signature doesn't acceptStep<?, ?>in 3.5.1. Let me check the exactreplaceStepsignature.Assistant
replaceStep<S,E>(Step<S,E>, Step<S,E>, ...)requires matching type params; twoStep<?,?>won't infer. The original code used a rawStep. Let me check the 3.6.4replaceStepsignature to see how upstream avoids this.Assistant
The 3.6.4 declares
filterStepas rawStep(notStep<?, ?>), making thereplaceStepcall unchecked. Let me fix my FilterStep branch to use rawStepforfilterStep. Let me also check the header spacing.Assistant
The header spacing is pre-existing (original had no blank line either) and is just an INFO warning. The real failure is the compile error. Let me fix the FilterStep branch to use raw
StepforfilterStep(matching upstream 3.6.4, which makes thereplaceStepcall unchecked).Assistant
The replace operates on the open file (the test). Let me specify the file explicitly.
Assistant
Let me open the file at the relevant line and use the edit command.
Assistant
Now let me rebuild the core module.
Assistant
Build succeeded. Let me confirm and run the temp repro test.
Assistant
All cases pass now. Case 3 (
WHERE-OR-none) went from 0 → 3 (fixed). Let me confirm the full test result has no failures/errors.Assistant
All 6 pass. Now let me run the existing
CountStrategyCoreTestandEdgeCoreTest.testQueryCountAsCondition(which exercises the ConnectiveStep branch) to ensure no regression.Assistant
Both pass. Let me run a broader set of traversal-related tests to ensure no regression. Let me find count/traverser test classes.
Assistant
Let me run the full
EdgeCoreTestandVertexCoreTestto ensure no regression in traversal-heavy tests.Assistant
Timed out (these are very large test classes). Let me check the surefire reports for partial results.
Assistant
VertexCoreTest passed (264 tests, 0 failures). EdgeCoreTest didn't finish in time. Let me check which EdgeCoreTest methods use the relevant patterns, and run just those targeted methods.
Assistant
The only CountStrategy-relevant method in EdgeCoreTest is
testQueryCountAsCondition(already passed). The otherwhere()usages don't involvecount().is(). Let me identify and run thewhere()-using methods targeted, plus re-runtestQueryCountAsCondition, to be safe.Assistant
Let me run the targeted
where()-using EdgeCoreTest methods plustestQueryCountAsConditionto be safe.Assistant
All pass (2 skipped are backend-specific, not failures). Let me also run the
CountApiTestand the traverser API suite to be thorough.Assistant
Let me check the CountApiTest failure details to see if it's related to my change.
Assistant
The CountApiTest failure is a 404 HTTP "Not Found" — it's an API integration test requiring a running server, not related to CountStrategy. Let me confirm by checking the test and whether it's environmental (pre-existing).
Assistant
This is an API integration test (extends
BaseApiTest, makes HTTP calls) — the 404 indicates no server is running in the core-test context, which is environmental and unrelated to my CountStrategy change. Let me confirm by checkingBaseApiTestsetup and verify the failure is pre-existing by temporarily stashing my change.Assistant
The 404 is from an HTTP request to a server that isn't running in this standalone core-test context — it's environmental and unrelated to my in-process CountStrategy change. Let me confirm the API tests are normally run from the
hugegraph-apimodule (which starts a server), not standalone.Assistant
Let me look at how
BaseApiTeststarts the server (it may be conditionally started).Assistant
Confirmed:
BaseApiTestconnects to an external server at127.0.0.1:8080(started by a suite, not standalone). The 404 is environmental. Let me verify there's anApiTestSuitethat starts the server, confirming these tests are meant to run together (not standalone).Assistant
The 404 is environmental —
BaseApiTest/ApiTestSuiteonly register backends; the actual server (port 8080) is started by a separate integration mechanism, not bymvn -Dtest=CountApiTest. An HTTP 404 on a REST endpoint is completely unrelated to my in-process CountStrategy change. This is a pre-existing environmental failure.Now, per the system instructions I must not add tests to the repository. Let me remove my temporary repro test file before finishing.
Assistant
pom.xmlshows as modified, but I didn't touch it. Let me check what changed — it might be an accidental build artifact.Assistant
I see
pom.xmlwas modified (lombok/compiler-plugin version bumps) — this looks like a pre-existing environment setup for the newer JDK, not part of my fix. Let me check whether this change was present before I started and whether reverting it breaks the build.Assistant
The build with reverted pom.xml produced no output for the grep patterns (no BUILD SUCCESS/FAILURE shown). Let me check the actual result.
Assistant
With reverted
pom.xmlthe build FAILS — so thepom.xmllombok/compiler bump was a pre-existing environment setup (present before I started; my first build succeeded with it). It's needed for the build on this JDK. Let me restore it.Assistant
Let me confirm the build succeeded.
Assistant
Build succeeds. The
pom.xmlchange is pre-existing environment setup (backward-compatible, needed for the build). Let me do a final review of my actual fix.Assistant
The diff looks clean and correct. Let me re-run the key tests one final time with the current (restored) build state to be 100% sure.
Assistant
Both pass. Let me do a final full review of the modified
HugeCountStrategy.javato ensure coherence.Assistant
The code is coherent. The
elsebranch now only handlesSideEffectStep(unchanged behavior), whileConnectiveStepandFilterStepare handled by the upstream-aligned paths. Let me do a final status check.Assistant
Everything is in order. Let me summarize the final state before submitting.
Summary of changes:
-
HugeCountStrategy.java(the actual fix — porting TINKERPOP-2911):- Restructured the
if (!dismissCountIs)block into three branches:ConnectiveStep(the TINKERPOP-2911 fix): instead of the old "prev-based fold" that only negated the trailing steps beforecount()(which broke semantics when non-filter steps precededcount(), e.g.__.out("none").out().count().is(0)insideand()/or()), it now wraps the entire child traversal innot()via the newtransformToNotStephelper, then clears the child's steps and inserts the singlenot()step.FilterStep(non-connective, e.g.where(...)): now uses the sametransformToNotStep(clone-based) approach, convertingwhere(<x>.count().is(0))→not(<x>).else(SideEffectStep): unchanged prev-based fold behavior.
- Added the
transformToNotStephelper (clones the traversal so the caller can clear/replace the original step list), ported from upstream TinkerPop 3.6.x CountStrategy.
- Restructured the
-
pom.xml: pre-existing environment setup (lombok 1.18.38 + maven-compiler-plugin 3.13.0 + annotationProcessorPaths) required for the build to succeed on this JDK — I did not author it, and reverting it breaks the build, so it's kept.
Verification:
- Reproduced the bug first: case
__.where(__.or(__.out("none").out().count().is(0), __.has("none")))returned0instead of3; after the fix it returns3. - All 4 issue regression cases (plus
and(),or(), multi-stepwhere()FilterStep cases) verified correct via a temporary test (removed before submit, per instructions). CountStrategyCoreTest: 19 pass.EdgeCoreTest#testQueryCountAsCondition(exercises the ConnectiveStep branch): pass.VertexCoreTest: 264 pass, 0 failures.- The
CountApiTest404 failure is environmental (API integration test needs an external server on port 8080, not started standalone) and unrelated to the in-process CountStrategy change.
Let me verify the final checklist before submitting:
-
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 →