diff --git a/src/graph/executor/algo/SubgraphExecutor.cpp b/src/graph/executor/algo/SubgraphExecutor.cpp index cb3e9ca7634..b4d547d38cc 100644 --- a/src/graph/executor/algo/SubgraphExecutor.cpp +++ b/src/graph/executor/algo/SubgraphExecutor.cpp @@ -100,17 +100,20 @@ folly::Future SubgraphExecutor::handleResponse(RpcResponse&& resps) { void SubgraphExecutor::filterEdges(int version) { auto iter = ectx_->getVersionedResult(subgraph_->outputVar(), version).iter(); - auto* gnIter = static_cast(iter.get()); - while (gnIter->valid()) { - const auto& dst = gnIter->getEdgeProp("*", nebula::kDst); - if (validVids_.find(dst) == validVids_.end()) { - auto edge = gnIter->getEdge(); - gnIter->erase(); - } else { - gnIter->next(); + auto* iterPtr = iter.get(); + if (iterPtr->isGetNeighborsIter()) { + auto* gnIter = static_cast(iterPtr); + while (gnIter->valid()) { + const auto& dst = gnIter->getEdgeProp("*", nebula::kDst); + if (validVids_.find(dst) == validVids_.end()) { + auto edge = gnIter->getEdge(); + gnIter->erase(); + } else { + gnIter->next(); + } } + gnIter->reset(); } - gnIter->reset(); ResultBuilder builder; builder.iter(std::move(iter)); ectx_->setVersionedResult(subgraph_->outputVar(), builder.build(), version); diff --git a/src/graph/executor/query/DataCollectExecutor.cpp b/src/graph/executor/query/DataCollectExecutor.cpp index 7e15bf23459..0b51e36ee03 100644 --- a/src/graph/executor/query/DataCollectExecutor.cpp +++ b/src/graph/executor/query/DataCollectExecutor.cpp @@ -65,6 +65,9 @@ Status DataCollectExecutor::collectSubgraph(const std::vector& vars ds.colNames = std::move(colNames_); const auto& hist = ectx_->getHistory(vars[0]); for (const auto& result : hist) { + if (!result.iterRef()->isGetNeighborsIter()) { + continue; + } auto iter = result.iter(); auto* gnIter = static_cast(iter.get()); List vertices; diff --git a/tests/tck/features/bugfix/FixIterCrash.feature b/tests/tck/features/bugfix/FixIterCrash.feature new file mode 100644 index 00000000000..b35c3c82a54 --- /dev/null +++ b/tests/tck/features/bugfix/FixIterCrash.feature @@ -0,0 +1,23 @@ +# Copyright (c) 2022 vesoft inc. All rights reserved. +# +# This source code is licensed under Apache 2.0 License. +Feature: FixIterCrash + + Scenario: Fix GetNeighborsIter Crash + Given an empty graph + And having executed: + """ + CREATE SPACE nba_FixIterCrash as nba + """ + And wait 6 seconds + And having executed: + """ + USE nba_FixIterCrash + """ + When executing query: + """ + GO from 'Tim Duncan' OVER serve YIELD serve._src AS id | + GET SUBGRAPH WITH PROP FROM $-.id + YIELD vertices as nodes, edges as relationships + """ + Then the execution should be successful