Skip to content

Two relationship variables in one pattern can bind the same edge #59

Closed

Description

@prrao87

Problem

openCypher matches each relationship at most once within one pattern (relationship isomorphism). Here, two relationship variables in the same pattern can bind the same edge.

Reproduction

import pyarrow as pa
from lance_csr import CypherEngine, GraphConfig

config = (
    GraphConfig.builder()
    .node_table("Person", "id")
    .rel_table("KNOWS", "Person", "Person", "src", "dst")
    .build()
)
people = pa.table({"id": [1, 2, 3, 4], "name": ["A", "B", "C", "D"]})
engine = CypherEngine(config, {"Person": people, "KNOWS": pa.table({"src": [1, 3], "dst": [2, 2]})})
engine.execute(
    "MATCH (a:Person)-[r1:KNOWS]->(b:Person)<-[r2:KNOWS]-(c:Person) "
    "RETURN a.name AS a, c.name AS c ORDER BY a, c"
).to_pylist()

This returns 4 rows, including {'a': 'A', 'c': 'A'} and {'a': 'C', 'c': 'C'}, where r1 and r2 are the same edge. openCypher returns 2 rows (A, C and C, A). The result is the same with and without use_csr=True. Named paths are not affected: the path operator from #55 already enforces it.

Suggested fix

For each pair of relationship variables of compatible types in one pattern, add a filter that their identities differ, as the path operator does.

Activity

  1. added a commit that references this issue on Oct 28, 2026
    92c5353
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions