Skip to content

Commit

Permalink
Merge branch 'master' into version
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole00 authored Jan 5, 2024
2 parents 3e0d091 + 66dfbf5 commit cb40ccd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/graph/validator/AssignmentValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace graph {

Status AssignmentValidator::validateImpl() {
auto *assignSentence = static_cast<AssignmentSentence *>(sentence_);

NG_RETURN_IF_ERROR(validator_->validate());

auto outputs = validator_->outputCols();
Expand Down
1 change: 0 additions & 1 deletion src/graph/validator/SequentialValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace graph {
// Validator of sequential sentences which combine multiple sentences, e.g. GO ...; GO ...;
// Call validator of sub-sentences.
Status SequentialValidator::validateImpl() {
Status status;
if (sentence_->kind() != Sentence::Kind::kSequential) {
return Status::SemanticError(
"Sequential validator validates a SequentialSentences, but %ld is "
Expand Down
31 changes: 22 additions & 9 deletions src/graph/validator/Validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,25 @@
#include "graph/visitor/DeduceTypeVisitor.h"
#include "graph/visitor/EvaluableExprVisitor.h"
#include "parser/Sentence.h"

DEFINE_uint32(max_statements,
1024,
"threshold for maximun number of statements that can be validate");
namespace nebula {
namespace graph {

thread_local uint32_t Validator::maxStatements_ = 0;

Validator::Validator(Sentence* sentence, QueryContext* qctx)
: sentence_(DCHECK_NOTNULL(sentence)),
qctx_(DCHECK_NOTNULL(qctx)),
vctx_(DCHECK_NOTNULL(qctx->vctx())) {}

// Create validator according to sentence type.
std::unique_ptr<Validator> Validator::makeValidator(Sentence* sentence, QueryContext* context) {
if (++maxStatements_ > FLAGS_max_statements * 2) {
throw std::runtime_error(
fmt::format("the number of statements exceeds max_statements : {}", FLAGS_max_statements));
}
auto kind = sentence->kind();
switch (kind) {
case Sentence::Kind::kExplain:
Expand Down Expand Up @@ -273,22 +281,27 @@ std::unique_ptr<Validator> Validator::makeValidator(Sentence* sentence, QueryCon
Status Validator::validate(Sentence* sentence, QueryContext* qctx) {
DCHECK(sentence != nullptr);
DCHECK(qctx != nullptr);

// Check if space chosen from session. if chosen, add it to context.
auto session = qctx->rctx()->session();
if (session->space().id > kInvalidSpaceID) {
auto spaceInfo = session->space();
qctx->vctx()->switchToSpace(std::move(spaceInfo));
}
try {
auto validator = makeValidator(sentence, qctx);
NG_RETURN_IF_ERROR(validator->validate());

auto validator = makeValidator(sentence, qctx);
NG_RETURN_IF_ERROR(validator->validate());

auto root = validator->root();
if (!root) {
return Status::SemanticError("Get null plan from sequential validator");
auto root = validator->root();
if (!root) {
return Status::SemanticError("Get null plan from sequential validator");
}
qctx->plan()->setRoot(root);
// reset maxStatements
maxStatements_ = 0;
} catch (const std::exception& error) {
maxStatements_ = 0;
return Status::SemanticError(std::string(error.what()));
}
qctx->plan()->setRoot(root);
return Status::OK();
}

Expand Down
1 change: 1 addition & 0 deletions src/graph/validator/Validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class Validator {
std::set<std::string> userDefinedVarNameList_;
// vid's Type
Value::Type vidType_;
static thread_local uint32_t maxStatements_;
};

} // namespace graph
Expand Down

0 comments on commit cb40ccd

Please sign in to comment.