apache / apache/hugegraph

[Bug] Incorrect comparison of a counted value and a negative value

Open
#2,135 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
3.2k
Forks
636
Avg merge
3d 11h
Merged PRs (30d)
14

Description

### Bug Type (问题类型)

gremlin (结果不合预期)

### Before submit

- [X] 我已经确认现有的 [Issues](https://github.com/apache/hugegraph/issues) 与 [FAQ](https://hugegraph.apache.org/docs/guides/faq/) 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)

### Environment (环境信息)

- Server Version: 1.0.0 (Apache Release Version)
- Backend: in memory
- OS: xx CPUs, xx G RAM, Ubuntu 2x.x / CentOS 7.x
- Data Size: xx vertices, xx edges

### Expected & Actual behavior (期望与实际表现)

I compare a counted value with a predicate `gt(-3)`. Since the counted value should be larger or equal to 0, I think HugeGraph can still compare the counted value with a negative value, e.g., `gt(-3)`. But, it throws an exception.

However, if I remove the CountStrategy, or compare with a negtiva value `-2` or `-1` (like [HugeGraph#2133](https://github.com/apache/incubator-hugegraph/issues/2133)), I can get the expected result.

```
gremlin> :> g.V().where(__.in('teach').count().is(gt(-3)))
java.lang.IllegalArgumentException: Not a legal range: [0, -2]

gremlin> :> g.withoutStrategies(CountStrategy.class).V().where(__.in('teach').count().is(gt(-3)))
==>[id:695284911031975936,label:person,type:vertex,properties:[age:12]]
==>[id:695284911036170241,label:person,type:vertex,properties:[age:24]]
==>[id:695284911036170240,label:person,type:vertex,properties:[age:23]]

gremlin> :> g.V().where(__.in('teach').count().is(gt(-2)))
==>[id:695284911031975936,label:person,type:vertex,properties:[age:12]]
==>[id:695284911036170241,label:person,type:vertex,properties:[age:24]]
==>[id:695284911036170240,label:person,type:vertex,properties:[age:23]]
```

The example consists of three vertices and two edges.
```
Vertex person1 = new Vertex("person").property("age", 12);
Vertex person2 = new Vertex("person").property("age", 23);
Vertex person3 = new Vertex("person").property("age", 24);
Edge edge1 = new Edge("knows").source(person2).target(person1).property("year", 1);
Edge edge2 = new Edge("teach").source(person3).target(person1).property("year", 2);
```

### Vertex/Edge example (问题点 / 边数据举例)

_No response_

### Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.