Skip to content

Commit

Permalink
split new visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
heroicNeZha committed Dec 13, 2021
1 parent 80073ab commit 090a758
Show file tree
Hide file tree
Showing 17 changed files with 377 additions and 101 deletions.
1 change: 1 addition & 0 deletions src/graph/validator/FetchEdgesValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Status FetchEdgesValidator::validateYield(const YieldClause *yield) {
}
col->setExpr(ExpressionUtils::rewriteLabelAttr2EdgeProp(col->expr()));
NG_RETURN_IF_ERROR(ValidateUtil::invalidLabelIdentifiers(col->expr()));
NG_RETURN_IF_ERROR(checkExprDepth(col->expr()));

auto colExpr = col->expr();
auto typeStatus = deduceExprType(colExpr);
Expand Down
1 change: 1 addition & 0 deletions src/graph/validator/FetchVerticesValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Status FetchVerticesValidator::validateYield(YieldClause *yield) {
}
col->setExpr(ExpressionUtils::rewriteLabelAttr2TagProp(col->expr()));
NG_RETURN_IF_ERROR(ValidateUtil::invalidLabelIdentifiers(col->expr()));
NG_RETURN_IF_ERROR(checkExprDepth(col->expr()));

auto colExpr = col->expr();
auto typeStatus = deduceExprType(colExpr);
Expand Down
1 change: 1 addition & 0 deletions src/graph/validator/FindPathValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Status FindPathValidator::validateWhere(WhereClause* where) {
}
where->setFilter(ExpressionUtils::rewriteLabelAttr2EdgeProp(expr));
auto filter = where->filter();
NG_RETURN_IF_ERROR(checkExprDepth(filter));

auto typeStatus = deduceExprType(filter);
NG_RETURN_IF_ERROR(typeStatus);
Expand Down
2 changes: 2 additions & 0 deletions src/graph/validator/GoValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Status GoValidator::validateWhere(WhereClause* where) {
NG_RETURN_IF_ERROR(foldRes);

auto filter = foldRes.value();
NG_RETURN_IF_ERROR(checkExprDepth(filter));
auto typeStatus = deduceExprType(filter);
NG_RETURN_IF_ERROR(typeStatus);
auto type = typeStatus.value();
Expand Down Expand Up @@ -141,6 +142,7 @@ Status GoValidator::validateYield(YieldClause* yield) {

col->setExpr(ExpressionUtils::rewriteLabelAttr2EdgeProp(col->expr()));
NG_RETURN_IF_ERROR(ValidateUtil::invalidLabelIdentifiers(col->expr()));
NG_RETURN_IF_ERROR(checkExprDepth(col->expr()));

auto* colExpr = col->expr();
if (ExpressionUtils::hasAny(colExpr, {Expression::Kind::kEdge})) {
Expand Down
2 changes: 2 additions & 0 deletions src/graph/validator/GroupByValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Status GroupByValidator::validateGroup(const GroupClause* groupClause) {
return Status::SemanticError("Group `%s' invalid", col->expr()->toString().c_str());
}

NG_RETURN_IF_ERROR(checkExprDepth(col->expr()));
NG_RETURN_IF_ERROR(deduceExprType(col->expr()));
NG_RETURN_IF_ERROR(deduceProps(col->expr(), exprProps_));

Expand Down Expand Up @@ -145,6 +146,7 @@ Status GroupByValidator::groupClauseSemanticCheck() {
// deduce group items and build outputs_
DCHECK_EQ(aggOutputColNames_.size(), groupItems_.size());
for (auto i = 0u; i < groupItems_.size(); ++i) {
NG_RETURN_IF_ERROR(checkExprDepth(groupItems_[i]));
auto type = deduceExprType(groupItems_[i]);
NG_RETURN_IF_ERROR(type);
outputs_.emplace_back(aggOutputColNames_[i], std::move(type).value());
Expand Down
3 changes: 3 additions & 0 deletions src/graph/validator/LookupValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Status LookupValidator::validateYieldEdge() {
}
col->setExpr(ExpressionUtils::rewriteLabelAttr2EdgeProp(col->expr()));
NG_RETURN_IF_ERROR(ValidateUtil::invalidLabelIdentifiers(col->expr()));
NG_RETURN_IF_ERROR(checkExprDepth(col->expr()));

auto colExpr = col->expr();
auto typeStatus = deduceExprType(colExpr);
Expand Down Expand Up @@ -148,6 +149,7 @@ Status LookupValidator::validateYieldTag() {
}
col->setExpr(ExpressionUtils::rewriteLabelAttr2TagProp(col->expr()));
NG_RETURN_IF_ERROR(ValidateUtil::invalidLabelIdentifiers(col->expr()));
NG_RETURN_IF_ERROR(checkExprDepth(col->expr()));

auto colExpr = col->expr();
auto typeStatus = deduceExprType(colExpr);
Expand Down Expand Up @@ -209,6 +211,7 @@ Status LookupValidator::validateFilter() {
NG_RETURN_IF_ERROR(ret);
lookupCtx_->filter = std::move(ret).value();
// Make sure the type of the rewritted filter expr is right
NG_RETURN_IF_ERROR(checkExprDepth(lookupCtx_->filter));
NG_RETURN_IF_ERROR(deduceExprType(lookupCtx_->filter));
}
NG_RETURN_IF_ERROR(deduceProps(lookupCtx_->filter, exprProps_));
Expand Down
2 changes: 2 additions & 0 deletions src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ Status MatchValidator::validateFilter(const Expression *filter,
auto transformRes = ExpressionUtils::filterTransform(filter);
NG_RETURN_IF_ERROR(transformRes);
whereClauseCtx.filter = transformRes.value();
NG_RETURN_IF_ERROR(checkExprDepth(whereClauseCtx.filter));

auto typeStatus = deduceExprType(whereClauseCtx.filter);
NG_RETURN_IF_ERROR(typeStatus);
Expand Down Expand Up @@ -899,6 +900,7 @@ Status MatchValidator::checkAlias(
Status MatchValidator::buildOutputs(const YieldColumns *yields) {
for (auto *col : yields->columns()) {
auto colName = col->name();
NG_RETURN_IF_ERROR(checkExprDepth(col->expr()));
auto typeStatus = deduceExprType(col->expr());
NG_RETURN_IF_ERROR(typeStatus);
auto type = typeStatus.value();
Expand Down
1 change: 1 addition & 0 deletions src/graph/validator/MutateValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ Status UpdateValidator::getCondition() {
if (symExpr != nullptr) {
filter = symExpr;
}
NG_RETURN_IF_ERROR(checkExprDepth(filter));
auto typeStatus = deduceExprType(filter);
NG_RETURN_IF_ERROR(typeStatus);
auto type = typeStatus.value();
Expand Down
7 changes: 7 additions & 0 deletions src/graph/validator/Validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "graph/validator/SetValidator.h"
#include "graph/validator/UseValidator.h"
#include "graph/validator/YieldValidator.h"
#include "graph/visitor/CheckDepthVisitor.h"
#include "graph/visitor/DeduceTypeVisitor.h"
#include "graph/visitor/EvaluableExprVisitor.h"
#include "parser/Sentence.h"
Expand Down Expand Up @@ -352,6 +353,12 @@ StatusOr<Value::Type> Validator::deduceExprType(const Expression* expr) const {
return visitor.type();
}

Status Validator::checkExprDepth(const Expression* expr) const {
CheckDepthVisitor visitor;
const_cast<Expression*>(expr)->accept(&visitor);
return std::move(visitor).status();
}

Status Validator::deduceProps(const Expression* expr, ExpressionProps& exprProps) {
DeducePropsVisitor visitor(qctx_, space_.id, &exprProps, &userDefinedVarNameList_);
const_cast<Expression*>(expr)->accept(&visitor);
Expand Down
2 changes: 2 additions & 0 deletions src/graph/validator/Validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class Validator {

StatusOr<Value::Type> deduceExprType(const Expression* expr) const;

Status checkExprDepth(const Expression* expr) const;

Status deduceProps(const Expression* expr, ExpressionProps& exprProps);

static StatusOr<size_t> checkPropNonexistOrDuplicate(const ColsDef& cols,
Expand Down
1 change: 1 addition & 0 deletions src/graph/validator/YieldValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Status YieldValidator::makeOutputColumn(YieldColumn *column) {
DCHECK(colExpr != nullptr);

auto expr = colExpr->clone();
NG_RETURN_IF_ERROR(checkExprDepth(expr));
NG_RETURN_IF_ERROR(deduceProps(expr, exprProps_));

auto status = deduceExprType(expr);
Expand Down
1 change: 1 addition & 0 deletions src/graph/visitor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ nebula_add_library(
RewriteVisitor.cpp
FindVisitor.cpp
VidExtractVisitor.cpp
CheckDepthVisitor.cpp
)

nebula_add_subdirectory(test)
Loading

0 comments on commit 090a758

Please sign in to comment.