From 3ebc3050b5f686651d5f37b97976bd18a6f3ae71 Mon Sep 17 00:00:00 2001 From: jimingquan Date: Tue, 23 Mar 2021 16:41:34 +0800 Subject: [PATCH] fix getNeighborIter (#859) * fix getNeighborIter * add test case * add noEdge_ indicate without Edge in getNeighborExecutor response Co-authored-by: Yee <2520865+yixinglu@users.noreply.github.com> --- src/context/Iterator.cpp | 14 +++++++++++++- src/context/Iterator.h | 1 + tests/tck/features/go/GO.IntVid.feature | 15 +++++++++++++++ tests/tck/features/go/GO.feature | 15 +++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/context/Iterator.cpp b/src/context/Iterator.cpp index c790017c1..4d7636221 100644 --- a/src/context/Iterator.cpp +++ b/src/context/Iterator.cpp @@ -30,6 +30,11 @@ GetNeighborsIter::GetNeighborsIter(std::shared_ptr value) void GetNeighborsIter::goToFirstEdge() { // Go to first edge for (currentDs_ = dsIndices_.begin(); currentDs_ < dsIndices_.end(); ++currentDs_) { + if (noEdge_) { + currentRow_ = currentDs_->ds->rows.begin(); + valid_ = true; + break; + } for (currentRow_ = currentDs_->ds->rows.begin(); currentRow_ < currentDs_->ds->rows.end(); ++currentRow_) { colIdx_ = currentDs_->colLowerBound + 1; @@ -126,7 +131,9 @@ StatusOr GetNeighborsIter::buildIndex(DataSetIndex* dsIndex) { // It is "_vid", "_stats", "_expr" in this situation. } } - + if (edgeStartIndex == -1) { + noEdge_ = true; + } dsIndex->colLowerBound = edgeStartIndex - 1; dsIndex->colUpperBound = colNames.size() - 1; return edgeStartIndex; @@ -181,6 +188,11 @@ void GetNeighborsIter::next() { return; } + if (noEdge_) { + currentRow_++; + return; + } + while (++edgeIdx_ > -1) { if (edgeIdx_ < edgeIdxUpperBound_) { const auto& currentEdge = currentCol_->operator[](edgeIdx_); diff --git a/src/context/Iterator.h b/src/context/Iterator.h index e1a83ad07..c0372752b 100644 --- a/src/context/Iterator.h +++ b/src/context/Iterator.h @@ -340,6 +340,7 @@ class GetNeighborsIter final : public Iterator { int64_t colIdx_{-1}; const List* currentCol_{nullptr}; + bool noEdge_{false}; int64_t edgeIdx_{-1}; int64_t edgeIdxUpperBound_{-1}; const List* currentEdge_{nullptr}; diff --git a/tests/tck/features/go/GO.IntVid.feature b/tests/tck/features/go/GO.IntVid.feature index 348b47a28..1a3643b2a 100644 --- a/tests/tck/features/go/GO.IntVid.feature +++ b/tests/tck/features/go/GO.IntVid.feature @@ -15,6 +15,21 @@ Feature: IntegerVid Go Sentence Then the result should be, in any order, with relax comparison, and the columns 0 should be hashed: | serve._dst | | "Spurs" | + When executing query: + """ + GO FROM hash("Tim Duncan") OVER like YIELD $^.player.name as name, $^.player.age as age + """ + Then the result should be, in any order, with relax comparison: + | name | age | + | "Tim Duncan" | 42 | + When executing query: + """ + GO FROM hash("Tim Duncan"), hash("Tony Parker") OVER like YIELD $^.player.name as name, $^.player.age as age + """ + Then the result should be, in any order, with relax comparison: + | name | age | + | "Tim Duncan" | 42 | + | "Tony Parker" | 36 | When executing query: """ GO FROM hash("Tim Duncan"), hash("Tim Duncan") OVER serve diff --git a/tests/tck/features/go/GO.feature b/tests/tck/features/go/GO.feature index f5f52a479..7b17c4dd0 100644 --- a/tests/tck/features/go/GO.feature +++ b/tests/tck/features/go/GO.feature @@ -15,6 +15,21 @@ Feature: Go Sentence Then the result should be, in any order, with relax comparison: | serve._dst | | "Spurs" | + When executing query: + """ + GO FROM "Tim Duncan" OVER like YIELD $^.player.name as name, $^.player.age as age + """ + Then the result should be, in any order, with relax comparison: + | name | age | + | "Tim Duncan" | 42 | + When executing query: + """ + GO FROM "Tim Duncan", "Tony Parker" OVER like YIELD $^.player.name as name, $^.player.age as age + """ + Then the result should be, in any order, with relax comparison: + | name | age | + | "Tim Duncan" | 42 | + | "Tony Parker" | 36 | When executing query: """ GO FROM "Tim Duncan", "Tim Duncan" OVER serve