apache / apache/hugegraph

[Improvement] Incorrect result was returned when use neq() in gremlin (property indexed)

Open
#1,582 4 comments 0 reactions 0 assignees View on GitHub
improvement
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/hugegraph/hugegraph/issues) 与 [FAQ](https://hugegraph.github.io/hugegraph-doc/guides/faq.html) 中没有相同 / 重复问题

### Environment (环境信息)

- Server Version: v0.11.2
- Backend: inmemory
- OS: xx CPUs, xx G RAM, Centos 7.x
- Data Size: 100 vertices, 200 edges

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

**Expected behavior**
We indexed properties for a vertex label, and wanted to query the results according to the property value. For example, we expected the result of query 1 `g.V().has('person', 'age', lt(30)).has('name', neq('person1'))` to be the same as query 2 `g.V().has('person', 'age', lt(30)).where(values('name').is(neq('person1')))`.

**Actual behavior**
Actually, HugeGraph thrown a NoIndexException when we executed query 1.
```
com.baidu.hugegraph.exception.NoIndexException: Don't accept query based on properties [age, name] that are not indexed in label 'person', may not match secondary/range/not-equal condition
```
**Steps to Reproduce**
We can reproduce the problem using the following code.
```
hugegraph.schema().propertyKey("name").asText().ifNotExist().create();
hugegraph.schema().propertyKey("age").asInt().ifNotExist().create();

// vertex
hugegraph.schema().vertexLabel("person").properties("name","age").nullableKeys("name","age").create();
hugegraph.schema().indexLabel("personbyname").onV("person").by("name").shard().ifNotExist().create();
hugegraph.schema().indexLabel("personbyage").onV("person").by("age").shard().ifNotExist().create();

GraphManager graph = hugegraph.graph();

/** create graph data */
Vertex person1 = new Vertex("person").property("name", "person1").property("age", 16);
Vertex person2 = new Vertex("person").property("name", "person2").property("age", 15);
Vertex person3 = new Vertex("person").property("name", "person3").property("age", 23);
Vertex person4 = new Vertex("person").property("name", "person4").property("age", 46);

graph.addVertices(Arrays.asList(person1, person2, person3, person4));

GremlinManager gremlin = hugegraph.gremlin();

String query1 = "g.V().has('person', 'age', lt(30)).has('name', neq('person1'))";
System.out.println("query1 : " + query1);
try{
ResultSet hugeResult = gremlin.gremlin(query1).execute();
Iterator huresult = hugeResult.iterator();
huresult.forEachRemaining(result -> {
Object object = result.getObject();
System.out.println(object);
});
}catch(Exception e){
e.printStackTrace();
}

String query2 = "g.V().has('person', 'age', lt(30)).where(values('name').is(neq('person1')))";
try{
ResultSet hugeResult = gremlin.gremlin(query2).execute();
Iterator huresult = hugeResult.iterator();
huresult.forEachRemaining(result -> {
Object object = result.getObject();
System.out.println(object);
});
}catch(Exception e){
e.printStackTrace();
}
```

### 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.