Open NobleMathews opened 2 months ago
To address the issue with Kùzu's output for a Cypher query involving an OPTIONAL MATCH
that is missing expected tuples, follow these steps:
OPTIONAL MATCH
in third_party/antlr4_cypher/cypher_parser.cpp
. Ensure that the parser correctly recognizes and handles OPTIONAL MATCH
clauses. If it does not, adjust the grammar and parsing logic accordingly.// Adjust the grammar and parsing logic for OPTIONAL MATCH in cypher_parser.cpp
RelPattern
class in src/include/parser/query/graph_pattern/rel_pattern.h
. Modify its logic if it is not accounting for optional relationships, ensuring that it correctly represents the semantics of an OPTIONAL MATCH
.// Modify the logic in RelPattern class to handle optional relationships
RecursiveJoin
operator's implementation in src/processor/operator/recursive_extend/recursive_join.cpp
. Update the logic if necessary to ensure that optional relationships are included in the result set.// Update RecursiveJoin logic to correctly process optional relationships
QueryGraphLabelAnalyzer
in src/binder/query/query_graph_label_analyzer.cpp
. If it is found to be pruning optional relationships incorrectly, adjust the pruning logic to preserve optional relationships during analysis.// Adjust the pruning logic in QueryGraphLabelAnalyzer to preserve optional relationships
By following these steps, you should be able to identify and resolve the issue with the missing tuple in Kùzu's output for the OPTIONAL MATCH
Cypher query.
src/processor/operator/recursive_extend/recursive_join.cpp:10-89 | This snippet contains logic for handling variable length and shortest path queries which may affect optional match results.
src/binder/query/query_graph_label_analyzer.cpp:77-127 | Pruning logic for relationships could be relevant to the issue with optional match results not including certain tuples.
third_party/antlr4_cypher/cypher_parser.cpp:2864-14367 | Parser implementation for creating node and relationship tables may impact how optional matches are processed.
src/common/types/value/recursive_rel.cpp:1-31 | Handles recursive relationships, which are part of the issue, but may need review for handling optional matches.
CREATE NODE TABLE V (id STRING, PRIMARY KEY(id)); CREATE NODE TABLE R (id STRING, PRIMARY KEY(id)); CREATE REL TABLE childof (FROM V TO V); CREATE REL TABLE relatedto (FROM R TO V);
CREATE (v1:V {id:"v1"}),(v11:V {id:"v11"}),(v12:V {id:"v12"}),(v111:V {id:"v111"}), (r1:R {id:"r1"}), (r12:R {id:"r12"}), (v111)-[:childof]->(v11),(v11)-[:childof]->(v1),(v12)-[:childof]->(v1), (r1)-[:relatedto]->(v1), (r12)-[:relatedto]->(v12); MATCH (v1:V {id: "v1"}) WITH v1 MATCH (v:V)-[e:childof*]->(v1) OPTIONAL MATCH (r)-[:relatedto]->(v) RETURN r, v; screenshot
What Kuzu returns:
| r | v |
| | {_ID: 0:3, _LABEL: V, id: v111} |
| | {_ID: 0:2, _LABEL: V, id: v12} |
| | {_ID: 0:1, _LABEL: V, id: v11} |
(3 tuples) (2 columns) What Neo4j returns (and what is expected here):
╒════════════════╤═════════════════╕ │r │v │ ╞════════════════╪═════════════════╡ │null │(:V {id: "v11"}) │ ├────────────────┼─────────────────┤ │null │(:V {id: "v111"})│ ├────────────────┼─────────────────┤ │(:R {id: "r12"})│(:V {id: "v12"}) │ └────────────────┴─────────────────┘ Why does Kuzu omit the existing optional match (:R {id: "r12"}) for v12 here?