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

EXISTS with multiple pattern elements doesn't work as expected #1186

Open
edc-lib opened this issue Mar 1, 2025 · 0 comments
Open

EXISTS with multiple pattern elements doesn't work as expected #1186

edc-lib opened this issue Mar 1, 2025 · 0 comments

Comments

@edc-lib
Copy link

edc-lib commented Mar 1, 2025

Description

I've encountered what appears to be an issue with the Cypher.exists() method when using multiple pattern elements. When I try to create an EXISTS clause with multiple pattern elements using a List, the test fails with an unexpected Cypher output.

Environment

  • Neo4j Cypher DSL version: [2024.5.0]
  • Java version: [17]

Reproduction

I've created the following test case:

@Test
public void testMultiPatternElementExist() {
    final Node user = Cypher.node("user").named("T1");
    final Node dept = Cypher.node("dept").named("T2");
    final Node parentDept = Cypher.node("dept").named("T3");
    final Statement statement = Cypher.match(user)
            .where(Cypher.exists(List.of(user.relationshipTo(dept, "dept_id"), dept.relationshipTo(parentDept, "parent_id"))))
            .returning(user).build();
    Assertions.assertEquals("MATCH (T1:`user`) WHERE EXISTS { (T1)-[:`dept_id`]->(T2:`dept`),(T2)-[:`parent_id`]->(T3:`dept`) } RETURN T1", statement.getCypher());
}

This test fails. However, I can make it work by using the following alternative approach:

Cypher.match(user).where(Cypher.match(user.relationshipTo(dept, "dept_id"), dept.relationshipTo(parentDept, "parent_id")).asCondition())

Question

Is this a bug in the library, or is the Cypher.exists(List<PatternElement>) method intended for a different use case? If it's designed for a specific scenario, could you clarify the intended usage?

Thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant