Mayil-AI-Sandbox / kuzudb_jan15

MIT License
0 stars 0 forks source link

Relation schema does not respect direction / no error on wrong node labels / `CREATE` rewrites user-provided node label (hashtag2675) #55

Open vikramsubramanian opened 7 months ago

vikramsubramanian commented 7 months ago

Version: v0.1.0

Schema:

CREATE NODE TABLE V1 (id STRING, PRIMARY KEY(id));
CREATE NODE TABLE V2 (id STRING, PRIMARY KEY (id));
CREATE REL TABLE E(FROM V1 TO V2);

Case 1:

kuzu> CREATE (v21: V2 {id: "v21"})-[:E]->(v11:V1 {id: "v11"});
-
(0 tuples)

kuzu> MATCH (v:V2) RETURN v;
-----------------------------------
| v                               |
-----------------------------------
| {_ID: 1:0, _LABEL: V2, id: v21} |
-----------------------------------
(1 tuple)

kuzu> MATCH (v:V1) RETURN v;
-----------------------------------
| v                               |
-----------------------------------
| {_ID: 0:0, _LABEL: V1, id: v11} |
-----------------------------------
(1 tuple)

kuzu> MATCH (v2:V2)-[e:E]->(v1:V1) RETURN v2,e,v1;
Error: Binder exception: Cannot find a label for node v2 that connects to all of its neighbour relationships.

kuzu> MATCH (v1:V1)-[e:E]->(v2:V2) RETURN v1,e,v2;
----------------------------------------------------------------------------------------------------------
| v1                              | e                                  | v2                              |
----------------------------------------------------------------------------------------------------------
| {_ID: 0:0, _LABEL: V1, id: v11} | (0:0)-{_LABEL: E, _ID: 2:0}->(1:0) | {_ID: 1:0, _LABEL: V2, id: v21} |
----------------------------------------------------------------------------------------------------------
(1 tuple)

Expected: CREATE errors, as the direction V2 -> V1 is wrong, schema is FROM V1 TO V2. Actual: Both nodes are created with the inverse direction. Querying the actual user-provided direction results in not-understandable Error: Binder exception.

Case 2:

kuzu> CREATE (v22:V2 {id: "v22"})-[:E]->(v23: V2 {id: "v23"});
-
(0 tuples)

kuzu> MATCH (v2a:V2)-[e:E]->(v2b:V2) RETURN v2a,e,v2b;
Error: Binder exception: Cannot find a label for node v2a that connects to all of its neighbour relationships.

Same as case 1, no error from REL schema. But in this case, inproper inverse relation is not created. )

mayil-ai[bot] commented 7 months ago

Summary: The relation schema does not respect direction and does not throw an error on wrong node labels during creation.

Possible Solution

Based on the provided information, the issue seems to be related to the creation and validation of relationships in the graph database schema, which is not correctly enforcing the schema constraints. The error message indicates that there is a problem with finding a label for a node that connects to all of its neighbor relationships, which suggests that either the relationships are being created with incorrect labels or directions, or the schema validation is not working as expected.

To address the issue, consider the following solution:

The relevant code snippets to focus on for implementing the solution are likely to be found in the schema definition and enforcement mechanism, the relationship creation and validation logic, and the error reporting system for schema violations. The provided code snippets do not contain the exact implementation details needed to fix the issue, so you will need to locate the relevant parts of the codebase that handle schema creation, relationship creation, and query validation.

Code snippets to check