Skip to content

Commit

Permalink
cypher bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
spasserby authored and tugraph committed Sep 25, 2023
1 parent 3496458 commit cabcdc6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 28 deletions.
3 changes: 3 additions & 0 deletions src/cypher/execution_plan/ops/op_expand_all.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ class ExpandAll : public OpBase {
CYPHER_THROW_ASSERT(!children.empty());
auto child = children[0];
while (state_ == ExpandAllUninitialized || Next(ctx) == OP_REFRESH) {
if (!expand_into_) {
ResetImpl(true);
}
auto res = child->Consume(ctx);
state_ = ExpandAllResetted;
if (res != OP_OK) {
Expand Down
8 changes: 6 additions & 2 deletions src/cypher/execution_plan/ops/op_produce_results.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@ 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 {
record.Insert(header[index].first, lgraph_api::FieldData());
}
continue;
} else {
throw lgraph::CypherException(
Expand Down
3 changes: 2 additions & 1 deletion src/cypher/execution_plan/optimization/pass_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class PassManager {
all_passes_.emplace_back(new PassVarLenExpandWithLimit());
all_passes_.emplace_back(new LocateNodeByVid());
all_passes_.emplace_back(new LocateNodeByIndexedProp());
all_passes_.emplace_back(new ParallelTraversal());
// todo(kehuang): ParallelTraversal will cause a crash, temporarily disabling it.
// all_passes_.emplace_back(new ParallelTraversal());
}

~PassManager() {
Expand Down
3 changes: 3 additions & 0 deletions src/cypher/filter/iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,9 @@ class EIter {
bool Undirected() const { return _type >= BI_EDGE && _type < NA; }

bool IsValid() const {
if (!_CheckItPtr()) {
return false;
}
switch (_type) {
case OUT_EDGE:
return (_oeit && _oeit->IsValid());
Expand Down
6 changes: 3 additions & 3 deletions src/lgraph_api/lgraph_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ void Record::Insert(const std::string &key, const FieldData &value) {
} else if (header[key] == LGraphType::PATH && value.type == FieldType::STRING) {
record[key] =
std::shared_ptr<ResultElement>(new ResultElement(value, LGraphType::PATH));
} else if (header[key] == LGraphType::ANY) {
record[key] =
std::shared_ptr<ResultElement>(new ResultElement(value, LGraphType::ANY));
} else if (header[key] == LGraphType::ANY || header[key] == LGraphType::NODE ||
header[key] == LGraphType::RELATIONSHIP) {
record[key] = std::shared_ptr<ResultElement>(new ResultElement(value, LGraphType::ANY));
} else {
throw std::runtime_error("[Result ERROR] type is valid");
}
Expand Down
22 changes: 0 additions & 22 deletions test/cypher_plan_validate.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,6 @@
"res": 21
}
],
"parallel_traversal": [
{
"query": "MATCH (n:Person) return count(n)",
"plan": "Execution Plan:\nProduce Results\n Traversal [n]\n",
"res": 1
},
{
"query": "MATCH (n:Person) where n.birthyear > 1900 and n.birthyear < 2000 return count(n) ",
"plan": "Execution Plan:\nProduce Results\n Traversal [n]\n",
"res": 1
},
{
"query": "MATCH (n:Person) return n.birthyear, count(n)",
"plan": "Execution Plan:\nProduce Results\n Traversal [n]\n",
"res": 13
},
{
"query": "MATCH (f:Film)<-[:ACTED_IN]-(p:Person)-[:BORN_IN]->(c:City) return c.name, count(f)",
"plan": "Execution Plan:\nProduce Results\n Traversal [f<--p-->c]\n",
"res": 3
}
],
"issue148": [
{
"query": "WITH 'a' as a UNWIND ['a', 'b'] as k RETURN a, k",
Expand Down

0 comments on commit cabcdc6

Please sign in to comment.