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

Fix wrong result for optional match #523

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/cypher/execution_plan/ops/op_produce_results.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ static void RRecordToURecord(
if (header_type == lgraph_api::LGraphType::RELATIONSHIP ||
header_type == lgraph_api::LGraphType::ANY) {
auto uit = v.relationship->ItRef();
auto uid = uit->GetUid();
record.Insert(header[index].first, uid, txn);
if (uit->IsValid()) {
auto uid = uit->GetUid();
record.Insert(header[index].first, uid, txn);
} else {
lgraph::EdgeUid euid;
euid.eid = -1;
record.InsertEdgeByID(header[index].first, euid);
}
continue;
} else {
throw lgraph::CypherException(
Expand Down
6 changes: 6 additions & 0 deletions src/lgraph_api/lgraph_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ void Record::Insert(const std::string &key, const lgraph_api::OutEdgeIterator &o
void Record::Insert(const std::string &key, const int64_t vid, lgraph_api::Transaction *txn) {
auto core_txn = txn->GetTxn().get();
auto vit = core_txn->GetVertexIterator(vid);
if (!vit.IsValid()) {
THROW_CODE(InternalError, "invalid vid {} for creating record", vid);
}
lgraph_result::Node node;
node.id = vid;
node.label = core_txn->GetVertexLabel(vit);
Expand All @@ -206,6 +209,9 @@ void Record::InsertVertexByID(const std::string &key, int64_t node_id) {
void Record::Insert(const std::string &key, EdgeUid &uid, lgraph_api::Transaction *txn) {
auto core_txn = txn->GetTxn().get();
auto eit = core_txn->GetOutEdgeIterator(uid, false);
if (!eit.IsValid()) {
THROW_CODE(InternalError, "invalid euid {} for creating record", uid.ToString());
}
lgraph_result::Relationship repl;
repl.id = uid.eid;
repl.src = uid.src;
Expand Down
15 changes: 13 additions & 2 deletions src/lgraph_api/result_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ bolt::Node Node::ToBolt() {
}

nlohmann::json Relationship::ToJson() {
if (id == -1) {
return json("__null__");;
}
json result;
std::map<std::string, json> j_properties;
result["identity"] = id;
Expand Down Expand Up @@ -417,9 +420,17 @@ std::any ResultElement::ToBolt(int64_t* v_eid) {
}
return ret;*/
} else if (type_ == LGraphType::NODE) {
return v.node->ToBolt();
if (v.node->id == -1) {
return {};
} else {
return v.node->ToBolt();
}
} else if (type_ == LGraphType::RELATIONSHIP) {
return v.repl->ToBolt(v_eid);
if (v.repl->id == -1) {
return {};
} else {
return v.repl->ToBolt(v_eid);
}
} else if (type_ == LGraphType::PATH) {
bolt::InternalPath path;
for (size_t i = 0; i < v.path->size(); i++) {
Expand Down
2 changes: 2 additions & 0 deletions test/resource/cases/suite/cypher/base.result
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ with '123dfd\\fd45a\'bcd' as a return a;
[{"a":"123dfd\\fd45a'bcd"}]
with "123dfd\\fd\"45a'bcd" as a return a;
[{"a":"123dfd\\fd\"45a'bcd"}]
optional MATCH (n:City {name:'London'})-[r]->(m) RETURN n.name,r,m;
[{"m":"__null__","n.name":null,"r":"__null__"}]
3 changes: 2 additions & 1 deletion test/resource/cases/suite/cypher/base.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ RETURN s,r,r.weight,d
ORDER BY r.weight
LIMIT 2;
with '123dfd\\fd45a\'bcd' as a return a;
with "123dfd\\fd\"45a'bcd" as a return a;
with "123dfd\\fd\"45a'bcd" as a return a;
optional MATCH (n:City {name:'London'})-[r]->(m) RETURN n.name,r,m;
Loading