Skip to content

Commit

Permalink
add unit test case
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Mar 14, 2022
1 parent 11ab0dd commit fef2893
Show file tree
Hide file tree
Showing 8 changed files with 1,071 additions and 601 deletions.
8 changes: 3 additions & 5 deletions src/graph/executor/algo/FindPathExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void FindPathExecutor::init() {
}
}

void FindPathExecutor::setNextStepVidFromPath(Interims& paths, const string& var) {
void FindPathExecutor::setNextStepVid(Interims& paths, const string& var) {
DataSet Ds;
for (const auto& path : paths) {
Row row;
Expand Down Expand Up @@ -174,10 +174,8 @@ folly::Future<Status> FindPathExecutor::execute() {
conjunctPath(leftPaths, rightPaths, ds);
}

auto leftVidVar = path->leftVidVar();
auto rightVidVar = path->rightVidVar();
setNextStepVidFromPath(leftPaths, leftVidVar);
setNextStepVidFromPath(rightPaths, rightVidVar);
setNextStepVid(leftPaths, path->leftVidVar());
setNextStepVid(rightPaths, path->rightVidVar());
// update history
preLeftPaths_.swap(leftPaths);
preRightPaths_.swap(rightPaths);
Expand Down
40 changes: 32 additions & 8 deletions src/graph/executor/algo/FindPathExecutor.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
/* Copyright (c) 2022 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/
// Copyright (c) 2022 vesoft inc. All rights reserved.
//
// This source code is licensed under Apache 2.0 License.

#ifndef GRAPH_EXECUTOR_ALGO_FIND_PATH_EXECUTOR_H_
#define GRAPH_EXECUTOR_ALGO_FIND_PATH_EXECUTOR_H_

#include "graph/executor/Executor.h"
// 1、keep path
// 2 extract dst
// 3 conjunct path

// FindPath has two inputs. GetNeighbors(From) & GetNeighbors(To)
// There are two Main functions
// First : Get the next vid for GetNeighbors to expand
// Second: Delete previously visited edges and save the result(iter) to the variable `resultVar`
//
// Member:
// `preLeftPaths_` : is hash table
// KEY : the VID of the visited destination Vertex
// VALUE : the number of steps to visit the KEY (starting vertex is 0)
// since each vertex will only be visited once, if it is a one-way edge expansion, there will be no
// duplicate edges. we only need to focus on the case of two-way expansion
//
// How to delete edges:
// determine whether a loop is formed by the number of steps. If the destination vid has been
// visited, and the number of steps of the destination vid differs by 2 from the current steps, it
// is judged that a loop is formed, the edge needs to be deleted
//
// For example: Topology is below
// a->c, a->b, b->a, b->c
// statement: get subgraph from 'a' both edge yield vertices as nodes, edges as relationships
// first steps : a->b, a->c, a<-b, all edges need to save
// second steps: b->a, b<-a, b->c, c<-a
// since it is a two-way expansion, the negative edge has already been visited,
// so b<-a & c<-a are deleted
// b->a : the number of steps of the destination vid `a` is 0, and the current steps is 2. it can be
// determined that a loop is formed, so this edge also needs to be deleted.
// b->c : determined by the number of steps that no loop is formed, so keep it
namespace nebula {
namespace graph {
class FindPathExecutor final : public Executor {
Expand All @@ -24,7 +48,7 @@ class FindPathExecutor final : public Executor {
private:
void init();
bool conjunctPath(Interims& leftPaths, Interims& rightPaths, DataSet& ds);
void setNextStepVidFromPath(Interims& paths, const std::string& var);
void setNextStepVid(Interims& paths, const std::string& var);
void buildPath(Iterator* iter, Interims& currentPath, bool reverse);

private:
Expand Down
5 changes: 1 addition & 4 deletions src/graph/executor/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ nebula_add_test(
TopNTest.cpp
AggregateTest.cpp
JoinTest.cpp
BFSShortestTest.cpp
ConjunctPathTest.cpp
ProduceSemiShortestPathTest.cpp
ProduceAllPathsTest.cpp
FindPathTest.cpp
CartesianProductTest.cpp
AssignTest.cpp
ShowQueriesTest.cpp
Expand Down
12 changes: 6 additions & 6 deletions src/graph/executor/test/ConjunctPathTest.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* Copyright (c) 2020 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/
// Copyright (c) 2022 vesoft inc. All rights reserved.
//
// This source code is licensed under Apache 2.0 License.
//

#include <gtest/gtest.h>

#include "graph/context/QueryContext.h"
#include "graph/executor/algo/ConjunctPathExecutor.h"
#include "graph/executor/algo/FindPathExecutor.h"
#include "graph/planner/plan/Algo.h"
#include "graph/planner/plan/Logic.h"

namespace nebula {
namespace graph {
class ConjunctPathTest : public testing::Test {
class FindPathTest : public testing::Test {
protected:
Path createPath(const std::string& src, const std::vector<std::string>& steps, int type) {
Path path;
Expand Down
Loading

0 comments on commit fef2893

Please sign in to comment.