Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Fix cluster getNeightborIter (#922)
Browse files Browse the repository at this point in the history
* fix cluster getNeightborIter

* add test case

Co-authored-by: cpw <13495049+CPWstatic@users.noreply.github.com>
  • Loading branch information
nevermore3 and CPWstatic committed Apr 7, 2021
1 parent e8ad874 commit 8063659
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/context/Iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,15 @@ void GetNeighborsIter::next() {
}

if (noEdge_) {
currentRow_++;
if (++currentRow_ < rowsUpperBound_) {
return;
}

// go to next dataset
if (++currentDs_ < dsIndices_.end()) {
currentRow_ = currentDs_->ds->begin();
rowsUpperBound_ = currentDs_->ds->end();
}
return;
}

Expand Down
67 changes: 67 additions & 0 deletions src/context/test/IteratorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,73 @@ TEST(IteratorTest, Sequential) {
}
}

TEST(IteratorTest, GetNeighborNoEdge) {
DataSet ds1;
ds1.colNames = {kVid, "_stats", "_tag:tag1:prop1:prop2", "_expr"};
for (auto i = 0; i < 10; ++i) {
Row row;
// _vid
row.values.emplace_back(folly::to<std::string>(i));
// _stats = empty
row.values.emplace_back(Value());
// tag
List tag;
tag.values.emplace_back(0);
tag.values.emplace_back(1);
row.values.emplace_back(Value(tag));
// _expr = empty
row.values.emplace_back(Value());
ds1.rows.emplace_back(std::move(row));
}

DataSet ds2;
ds2.colNames = {kVid, "_stats", "_tag:tag2:prop1:prop2", "_expr"};
for (auto i = 10; i < 20; ++i) {
Row row;
// _vid
row.values.emplace_back(folly::to<std::string>(i));
// _stats = empty
row.values.emplace_back(Value());
// tag
List tag;
tag.values.emplace_back(0);
tag.values.emplace_back(1);
row.values.emplace_back(Value(tag));
// _expr = empty
row.values.emplace_back(Value());
ds2.rows.emplace_back(std::move(row));
}

List datasets;
datasets.values.emplace_back(std::move(ds1));
datasets.values.emplace_back(std::move(ds2));
auto val = std::make_shared<Value>(std::move(datasets));

{
GetNeighborsIter iter(val);
std::vector<Value> expected = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19"};
std::vector<Value> result;
for (; iter.valid(); iter.next()) {
result.emplace_back(iter.getColumn(kVid));
}
EXPECT_EQ(expected, result);
}

{
GetNeighborsIter iter(val);
std::vector<Value> expected;
expected.insert(expected.end(), 10, 0);
expected.insert(expected.end(), 10, Value());
std::vector<Value> result;
for (; iter.valid(); iter.next()) {
result.emplace_back(iter.getTagProp("tag1", "prop1"));
}
EXPECT_EQ(result.size(), 20);
EXPECT_EQ(expected, result);
}
}

TEST(IteratorTest, GetNeighbor) {
DataSet ds1;
ds1.colNames = {kVid,
Expand Down

0 comments on commit 8063659

Please sign in to comment.