Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Sep 28, 2021
1 parent 77c3daa commit 1fd361c
Show file tree
Hide file tree
Showing 13 changed files with 465 additions and 91 deletions.
1 change: 0 additions & 1 deletion src/graph/validator/FindPathValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "graph/validator/FindPathValidator.h"

#include "common/expression/VariableExpression.h"
#include "graph/planner/plan/Algo.h"
#include "graph/planner/plan/Logic.h"
#include "graph/util/ValidateUtil.h"
Expand Down
6 changes: 0 additions & 6 deletions src/graph/validator/GetSubgraphValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@

#include "graph/validator/GetSubgraphValidator.h"

#include <memory>

#include "common/expression/UnaryExpression.h"
#include "common/expression/VariableExpression.h"
#include "common/expression/VertexExpression.h"
#include "graph/context/QueryExpressionContext.h"
#include "graph/planner/plan/Logic.h"
#include "graph/planner/plan/Query.h"
#include "graph/util/ValidateUtil.h"
Expand Down
61 changes: 44 additions & 17 deletions src/graph/validator/test/FindPathValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,34 @@ class FindPathValidatorTest : public ValidatorTestBase {

using PK = nebula::graph::PlanNode::Kind;

TEST_F(FindPathValidatorTest, invalidYield) {
{
std::string query =
"FIND SHORTEST PATH FROM \"Tim Duncan\" TO \"Tony Paker\" OVER * YIELD vertex";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SyntaxError: please add alias when using vertex. near `vertex'");
}
{
std::string query =
"FIND ALL PATH WITH PROP FROM \"Tim Duncan\" TO \"Tony Paker\" OVER like YIELD edge as e";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()), "SemanticError: illegal yield clauses `EDGE AS e'");
}
{
std::string query =
"FIND NOLOOP PATH WITH PROP FROM \"Tim Duncan\" TO \"Yao Ming\" OVER teammate YIELD path";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SyntaxError: please add alias when using path. near `path'");
}
}

TEST_F(FindPathValidatorTest, SinglePairPath) {
{
std::string query = "FIND SHORTEST PATH FROM \"1\" TO \"2\" OVER like UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kStart,
Expand All @@ -38,6 +62,7 @@ TEST_F(FindPathValidatorTest, SinglePairPath) {
{
std::string query = "FIND SHORTEST PATH FROM \"1\" TO \"2\" OVER like, serve UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kStart,
Expand All @@ -57,6 +82,7 @@ TEST_F(FindPathValidatorTest, MultiPairPath) {
{
std::string query = "FIND SHORTEST PATH FROM \"1\" TO \"2\",\"3\" OVER like UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kCartesianProduct,
Expand All @@ -78,6 +104,7 @@ TEST_F(FindPathValidatorTest, MultiPairPath) {
"FIND SHORTEST PATH FROM \"1\",\"2\" TO \"3\",\"4\" OVER like UPTO 5 "
"STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kCartesianProduct,
Expand All @@ -100,6 +127,7 @@ TEST_F(FindPathValidatorTest, ALLPath) {
{
std::string query = "FIND ALL PATH FROM \"1\" TO \"2\" OVER like UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kProject,
Expand All @@ -118,6 +146,7 @@ TEST_F(FindPathValidatorTest, ALLPath) {
{
std::string query = "FIND ALL PATH FROM \"1\" TO \"2\",\"3\" OVER like UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kProject,
Expand All @@ -142,6 +171,7 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
" | FIND SHORTEST PATH FROM $-.src TO $-.dst OVER like, serve UPTO 5 "
"STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kCartesianProduct,
Expand Down Expand Up @@ -169,23 +199,12 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
"GO FROM \"1\" OVER like YIELD like._src AS src, like._dst AS dst "
" | FIND ALL PATH FROM $-.src TO $-.dst OVER like, serve UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kDataCollect,
PK::kLoop,
PK::kProject,
PK::kConjunctPath,
PK::kProject,
PK::kProduceAllPaths,
PK::kProduceAllPaths,
PK::kDedup,
PK::kGetNeighbors,
PK::kGetNeighbors,
PK::kProject,
PK::kPassThrough,
PK::kDedup,
PK::kStart,
PK::kProject,
PK::kProject,
PK::kGetNeighbors,
PK::kProject, PK::kDataCollect, PK::kLoop,
PK::kProject, PK::kConjunctPath, PK::kProject,
PK::kProduceAllPaths, PK::kProduceAllPaths, PK::kDedup,
PK::kGetNeighbors, PK::kGetNeighbors, PK::kProject,
PK::kPassThrough, PK::kDedup, PK::kStart,
PK::kProject, PK::kProject, PK::kGetNeighbors,
PK::kStart,
};
EXPECT_TRUE(checkResult(query, expected));
Expand All @@ -196,6 +215,7 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
" | FIND SHORTEST PATH FROM \"2\" TO $-.dst OVER like, serve UPTO 5 "
"STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kCartesianProduct,
Expand All @@ -222,6 +242,7 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
" | FIND SHORTEST PATH FROM $-.src TO \"2\" OVER like, serve UPTO 5 "
"STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kCartesianProduct,
Expand All @@ -248,6 +269,7 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
"GO FROM \"2\" OVER like yield like._src AS src, like._dst AS dst "
" | FIND SHORTEST PATH FROM $a.src TO $-.dst OVER like UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kCartesianProduct,
Expand Down Expand Up @@ -278,6 +300,7 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
" | FIND SHORTEST PATH FROM $-.src TO $-.dst OVER like, serve UPTO 5 "
"STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kCartesianProduct,
Expand All @@ -304,6 +327,7 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
"YIELD \"1\" AS src, \"2\" AS dst"
" | FIND ALL PATH FROM $-.src TO $-.dst OVER like, serve UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kProject,
Expand Down Expand Up @@ -332,6 +356,7 @@ TEST_F(FindPathValidatorTest, PathWithFilter) {
"FIND ALL PATH FROM \"1\" TO \"2\" OVER like WHERE like.likeness > 30 "
"UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kProject,
Expand All @@ -354,6 +379,7 @@ TEST_F(FindPathValidatorTest, PathWithFilter) {
"FIND SHORTEST PATH FROM \"1\" TO \"2\" OVER like WHERE like.likeness "
"> 30 UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kStart,
Expand All @@ -374,6 +400,7 @@ TEST_F(FindPathValidatorTest, PathWithFilter) {
"FIND SHORTEST PATH FROM \"1\" TO \"2\", \"3\" OVER like WHERE "
"like.likeness > 30 UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
PK::kLoop,
PK::kCartesianProduct,
Expand Down
2 changes: 1 addition & 1 deletion src/graph/validator/test/GetSubgraphValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ TEST_F(GetSubgraphValidatorTest, invalidYield) {
std::string query = "GET SUBGRAPH WITH PROP FROM \"Tim Duncan\" YIELD path";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SemanticError: Get Subgraph only support YIELD vertices OR edges");
"SyntaxError: please add alias when using path. near `path'");
}
{
std::string query = "GET SUBGRAPH WITH PROP FROM \"Tim Duncan\" YIELD 123";
Expand Down
2 changes: 1 addition & 1 deletion src/graph/validator/test/YieldValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ TEST_F(YieldValidatorTest, TypeCastTest) {
{
std::string query = "YIELD (PATH)true";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()), "SyntaxError: syntax error near `true'");
EXPECT_EQ(std::string(result.message()), "SyntaxError: syntax error near `PATH'");
}
{
std::string query = "YIELD (NOEXIST)true";
Expand Down
2 changes: 1 addition & 1 deletion src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ yield_column
}
| KW_PATH {
$$ = nullptr;
throw nebula::GraphParser::syntax_error(@1, "please add alias when using path");
throw nebula::GraphParser::syntax_error(@1, "please add alias when using path.");
}
| KW_PATH KW_AS name_label {
$$ = new YieldColumn(PathBuildExpression::make(qctx->objPool()), *$3);
Expand Down
12 changes: 6 additions & 6 deletions tests/tck/features/match/Unwind.feature
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ Feature: Unwind clause
Scenario: unwind match with
When executing query:
"""
MATCH path=(x:player{name: "Tim Duncan"})-[:like*..2]->(y)
UNWIND nodes(path) as n
WITH path, size(collect(distinct n)) AS testLength
WHERE testLength == length(path) + 1
RETURN path
MATCH p = (x:player{name: "Tim Duncan"})-[:like*..2]->(y)
UNWIND nodes(p) as n
WITH p, size(collect(distinct n)) AS testLength
WHERE testLength == length(p) + 1
RETURN p
"""
Then the result should be, in any order:
| path |
| p |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 95}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 95}]->("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 95}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})-[:like@0 {likeness: 95}]->("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"})> |
Expand Down
Loading

0 comments on commit 1fd361c

Please sign in to comment.