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

RuntimeError: Binder exception: Variable __existence already exists. #3510

Open
sapalli2989 opened this issue May 17, 2024 · 2 comments
Open
Assignees

Comments

@sapalli2989
Copy link
Contributor

Hi, above error can be reproduced by following snippet:

import kuzu
from uuid import uuid4
import tempfile

with tempfile.TemporaryDirectory() as dbpath:
    conn = kuzu.Connection(kuzu.Database(dbpath))
    conn.execute(
        """
        CREATE NODE TABLE T (id UUID, PRIMARY KEY(id));
        CREATE NODE TABLE U (id UUID, name STRING, PRIMARY KEY(id));
        CREATE REL TABLE has (FROM T TO U);
        """,
    )
    # Prerequirement: existing :T
    tid = uuid4()
    conn.execute("CREATE (t:T {id: $id}) RETURN t;", {"id": tid})

    # Merge :U from memory (new here, but might already exist)
    uid = uuid4()
    conn.execute(
        """
        MATCH (t:T {id: $tid}) // (1)
        MERGE (u:U {id: $uid}) // (2)
        SET u.name = $name     // (3)
        MERGE (t)-[e:has]->(u)
        RETURN t,u,e;
        """,
        {"tid": tid, "uid": uid, "name": "foo"},
    )

Some background for clarification:
Goal was to construct a simple kind of object graph mapper (OGM) with MERGE: Given entities T,U with composite relation (:T)-[:has]->(:U), try to merge a new or existing U from memory.
(1) ensures :T exists
(2) merges an :U by its identifier (otherwise MERGE would try to create a new entity, if any property has changed)
(3) update all :U properties in database (assuming object memory has most recent version or creates new entity)

Kuzu 0.4.2

@andyfengHKU
Copy link
Contributor

Hi @sapalli2989,

I can confirm this is bug on our side and working on it. Meanwhile, I wonder if the following workaround works for u?

# Create :T
tid = uuid4()
conn.execute(
"""
CREATE (t:T {id: $tid}) RETURN t;
""", ....) 

# Create :U if not exist
uid = uuid4()
conn.execute(
"""
MERGE (u:U {id: $uid}) 
SET u.name = $name
""", ...)

# Create :has if not exist
conn.execute(
"""
MATCH (t:T {id: $tid}), (u:U {id: $uid}) 
MERGE (t)-[e:has]->(u)
RETURN t, u, e
""", ...)

Essentially we split merge into multiple statements instead of one.

@sapalli2989
Copy link
Contributor Author

Great, thanks!

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

2 participants