Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple MATCH works is incorrect #278

Closed
mad opened this issue May 21, 2019 · 4 comments · Fixed by #288
Closed

Multiple MATCH works is incorrect #278

mad opened this issue May 21, 2019 · 4 comments · Fixed by #288
Labels
bug Something isn't working

Comments

@mad
Copy link
Contributor

mad commented May 21, 2019

Example of graph

        graph.traversal()
             .addV("Org").property("Name", "Org1").as("org1")
             .addV("Org").property("Name", "Org2").as("org2")
             .addV("Person").property("Name", "Foo").as("p1")
             .addV("Person").property("Name", "Boo").as("p2")
             .addV("Doc").property("Title", "Doc1").as("doc")
             .addE("E").from("org1").to("p1")
             .addE("E").from("org1").to("p2")
             .addE("E").from("org2").to("p1")
             .addE("E").from("org2").to("p2")
             .addE("E").from("org1").to("doc")
             .addE("E").from("org2").to("doc")

And cypher query

MATCH (org1:Org)--(p:Person)--(org2:Org)
MATCH (org1:Org)--(doc:Doc)--(org2:Org)
WHERE id(org1) IN [{nID}] AND id(org1) <> id(org2)
RETURN p.Name AS personName, org2.Name AS orgName

Expected result is:

[{personName=Boo, orgName=Org2}, {personName=Foo, orgName=Org2}]

But actual is:

[{personName=Foo, orgName=Org2}]
@dwitry
Copy link
Contributor

dwitry commented May 27, 2019

Hello @mad,

thank you for reporting this.

As Cypher query is translated to a single Gremlin traversal, there are some limitations for multiple MATCH clauses. First MATCH clause returns 2 records. Second MATCH clause returns 1 record. As these are in the same traversal, result count gets limited by the second clause, and only 1st record is returned (query will work correctly if MATCH clauses are swapped).

You are right, this should be improved, but currently, I can't think of better translation for this case.

@dwitry dwitry added the enhancement New feature or request label May 27, 2019
@mad
Copy link
Contributor Author

mad commented Jun 3, 2019

Hello @dwitry

I think multiple match should be prevent for avoid bugs until new translation method introduced

@dwitry
Copy link
Contributor

dwitry commented Jun 4, 2019

Hello @mad,

Agree, it makes sense to throw an exception on multiple MATCH clauses instead of returning an incorrect result. However, there are a lot of cases where multiple MATCH queries work as expected, for example:

MATCH (m:person {name: "marko"})
MATCH (m:person {age: 29})
MATCH (m:person)-[r1:created]->(lop:software {name: "lop"})
RETURN m

I will take a look if it is possible to distinguish queries that will provide an incorrect result.

dwitry added a commit to dwitry/cypher-for-gremlin that referenced this issue Jun 7, 2019
Fixes opencypher#278

Signed-off-by: Dwitry dwitry@users.noreply.github.com
dwitry added a commit that referenced this issue Jun 7, 2019
Fixes #278

Signed-off-by: Dwitry dwitry@users.noreply.github.com
@dwitry dwitry added bug Something isn't working and removed enhancement New feature or request labels Jun 7, 2019
@dwitry
Copy link
Contributor

dwitry commented Jun 7, 2019

Hello @mad,

actually, I was wrong about multiple MATCH. Multiple MATCH feature is working correctly. The actual cause of this bug was incorrect handling of undirected paths.

Fix pushed to master and tinkerpop334.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants