Skip to content

Commit

Permalink
Find path validator. (vesoft-inc#245)
Browse files Browse the repository at this point in the history
* Add find path validator.

* Implement validate.

* Remove useless vlog.

* Add test.

* Refactor.

* Address comment.

* Rebase and address comment.

* Rebase.

Co-authored-by: dutor <[email protected]>
  • Loading branch information
CPWstatic and dutor authored Sep 2, 2020
1 parent 9a0d808 commit 4dc93bb
Show file tree
Hide file tree
Showing 11 changed files with 425 additions and 273 deletions.
4 changes: 2 additions & 2 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,9 @@ find_path_sentence
;

find_path_upto_clause
: %empty { $$ = new StepClause(5, true); }
: %empty { $$ = new StepClause(5); }
| KW_UPTO legal_integer KW_STEPS {
$$ = new StepClause($2, true);
$$ = new StepClause($2);
}
;

Expand Down
1 change: 1 addition & 0 deletions src/validator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ nebula_add_library(
TraversalValidator.cpp
ExplainValidator.cpp
GroupByValidator.cpp
FindPathValidator.cpp
)

nebula_add_subdirectory(test)
31 changes: 31 additions & 0 deletions src/validator/FindPathValidator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Copyright (c) 2020 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/

#include "validator/FindPathValidator.h"
#include "planner/Logic.h"

namespace nebula {
namespace graph {
Status FindPathValidator::validateImpl() {
auto fpSentence = static_cast<FindPathSentence*>(sentence_);
isShortest_ = fpSentence->isShortest();

NG_RETURN_IF_ERROR(validateStarts(fpSentence->from(), from_));
NG_RETURN_IF_ERROR(validateStarts(fpSentence->to(), to_));
NG_RETURN_IF_ERROR(validateOver(fpSentence->over(), over_));
NG_RETURN_IF_ERROR(validateStep(fpSentence->step(), steps_));
return Status::OK();
}

Status FindPathValidator::toPlan() {
// TODO: Implement the path plan.
auto* passThrough = PassThroughNode::make(qctx_, nullptr);
tail_ = passThrough;
root_ = tail_;
return Status::OK();
}
} // namespace graph
} // namespace nebula
36 changes: 36 additions & 0 deletions src/validator/FindPathValidator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright (c) 2020 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/

#ifndef VALIDATOR_FINDPATHVALIDATOR_H_
#define VALIDATOR_FINDPATHVALIDATOR_H_

#include "common/base/Base.h"
#include "validator/TraversalValidator.h"

namespace nebula {
namespace graph {


class FindPathValidator final : public TraversalValidator {
public:
FindPathValidator(Sentence* sentence, QueryContext* context)
: TraversalValidator(sentence, context) {}

private:
Status validateImpl() override;

Status toPlan() override;

private:
bool isShortest_{false};
Starts from_;
Starts to_;
Over over_;
Steps steps_;
};
} // namespace graph
} // namespace nebula
#endif
8 changes: 4 additions & 4 deletions src/validator/GetSubgraphValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ Status GetSubgraphValidator::validateImpl() {
Status status;
auto* gsSentence = static_cast<GetSubgraphSentence*>(sentence_);
do {
status = validateStep(gsSentence->step());
status = validateStep(gsSentence->step(), steps_);
if (!status.ok()) {
break;
}

status = validateFrom(gsSentence->from());
status = validateStarts(gsSentence->from(), from_);
if (!status.ok()) {
return status;
}
Expand Down Expand Up @@ -136,7 +136,7 @@ Status GetSubgraphValidator::toPlan() {

std::string startVidsVar;
PlanNode* projectStartVid = nullptr;
if (!starts_.empty() && srcRef_ == nullptr) {
if (!from_.vids.empty() && from_.srcRef == nullptr) {
startVidsVar = buildConstantInput();
} else {
projectStartVid = buildRuntimeInput();
Expand All @@ -162,7 +162,7 @@ Status GetSubgraphValidator::toPlan() {

// ++counter{0} <= steps
// TODO(shylock) add condition when gn get empty result
auto* condition = buildNStepLoopCondition(steps_);
auto* condition = buildNStepLoopCondition(steps_.steps);
// The input of loop will set by father validator.
auto* loop = Loop::make(qctx_, nullptr, projectVids, condition);

Expand Down
Loading

0 comments on commit 4dc93bb

Please sign in to comment.