From cabcdc6774c3ede4c12760ea239a9f33c7dafbc4 Mon Sep 17 00:00:00 2001 From: spasserby <569078986@qq.com> Date: Mon, 25 Sep 2023 16:56:21 +0800 Subject: [PATCH] cypher bug fix --- src/cypher/execution_plan/ops/op_expand_all.h | 3 +++ .../execution_plan/ops/op_produce_results.h | 8 +++++-- .../optimization/pass_manager.h | 3 ++- src/cypher/filter/iterator.h | 3 +++ src/lgraph_api/lgraph_result.cpp | 6 ++--- test/cypher_plan_validate.json | 22 ------------------- 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/cypher/execution_plan/ops/op_expand_all.h b/src/cypher/execution_plan/ops/op_expand_all.h index 976467a473..04ca410de9 100644 --- a/src/cypher/execution_plan/ops/op_expand_all.h +++ b/src/cypher/execution_plan/ops/op_expand_all.h @@ -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) { diff --git a/src/cypher/execution_plan/ops/op_produce_results.h b/src/cypher/execution_plan/ops/op_produce_results.h index a7ea732f52..c3bcda263c 100644 --- a/src/cypher/execution_plan/ops/op_produce_results.h +++ b/src/cypher/execution_plan/ops/op_produce_results.h @@ -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( diff --git a/src/cypher/execution_plan/optimization/pass_manager.h b/src/cypher/execution_plan/optimization/pass_manager.h index 0673f1f5c0..948d68f720 100644 --- a/src/cypher/execution_plan/optimization/pass_manager.h +++ b/src/cypher/execution_plan/optimization/pass_manager.h @@ -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() { diff --git a/src/cypher/filter/iterator.h b/src/cypher/filter/iterator.h index 2c7fac2484..9d21c79f18 100644 --- a/src/cypher/filter/iterator.h +++ b/src/cypher/filter/iterator.h @@ -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()); diff --git a/src/lgraph_api/lgraph_result.cpp b/src/lgraph_api/lgraph_result.cpp index e53ae4ee49..fd1b9c894d 100644 --- a/src/lgraph_api/lgraph_result.cpp +++ b/src/lgraph_api/lgraph_result.cpp @@ -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(new ResultElement(value, LGraphType::PATH)); - } else if (header[key] == LGraphType::ANY) { - record[key] = - std::shared_ptr(new ResultElement(value, LGraphType::ANY)); + } else if (header[key] == LGraphType::ANY || header[key] == LGraphType::NODE || + header[key] == LGraphType::RELATIONSHIP) { + record[key] = std::shared_ptr(new ResultElement(value, LGraphType::ANY)); } else { throw std::runtime_error("[Result ERROR] type is valid"); } diff --git a/test/cypher_plan_validate.json b/test/cypher_plan_validate.json index eaa6968434..df145bb0d4 100644 --- a/test/cypher_plan_validate.json +++ b/test/cypher_plan_validate.json @@ -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",