Skip to content

Commit

Permalink
Fix checking update filter expression. (#5076)
Browse files Browse the repository at this point in the history
* Fix checking update filter expression.

* Remove comments.

Co-authored-by: Yichen Wang <[email protected]>
  • Loading branch information
Shylock-Hg and Aiee authored Dec 27, 2022
1 parent 4c0f4b5 commit 45f5bfd
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 454 deletions.
72 changes: 67 additions & 5 deletions src/graph/validator/MutateValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
*/
#include "graph/validator/MutateValidator.h"

#include "common/datatypes/Value.h"
#include "common/expression/Expression.h"
#include "common/expression/LabelAttributeExpression.h"
#include "graph/planner/plan/Mutate.h"
#include "graph/planner/plan/Query.h"
#include "graph/util/ExpressionUtils.h"
#include "graph/util/SchemaUtil.h"
#include "graph/visitor/RewriteSymExprVisitor.h"
#include "graph/visitor/RewriteVisitor.h"

namespace nebula {
namespace graph {
Expand Down Expand Up @@ -750,10 +752,70 @@ Expression *UpdateValidator::rewriteSymExpr(Expression *expr,
const std::string &sym,
bool &hasWrongType,
bool isEdge) {
RewriteSymExprVisitor visitor(qctx_->objPool(), sym, isEdge);
expr->accept(&visitor);
hasWrongType = visitor.hasWrongType();
return std::move(visitor).expr();
std::unordered_set<Expression::Kind> invalidExprs{
Expression::Kind::kVersionedVar,
Expression::Kind::kVarProperty,
Expression::Kind::kInputProperty,
Expression::Kind::kVar,
// Expression::Kind::kLabelAttribute, valid only for update edge
Expression::Kind::kAttribute,
Expression::Kind::kSubscript,
Expression::Kind::kUUID,
Expression::Kind::kTagProperty,
Expression::Kind::kLabelTagProperty,
Expression::Kind::kDstProperty,
Expression::Kind::kEdgeSrc,
Expression::Kind::kEdgeType,
Expression::Kind::kEdgeRank,
Expression::Kind::kEdgeDst,
};
if (isEdge) {
invalidExprs.emplace(Expression::Kind::kSrcProperty);
} else {
invalidExprs.emplace(Expression::Kind::kLabelAttribute);
invalidExprs.emplace(Expression::Kind::kEdgeProperty);
}
auto *r = ExpressionUtils::findAny(expr, invalidExprs);
if (r != nullptr) {
hasWrongType = true;
return nullptr;
}

auto *pool = qctx_->objPool();
RewriteVisitor::Matcher matcher = [](const Expression *e) -> bool {
switch (e->kind()) {
case Expression::Kind::kLabel:
case Expression::Kind::kLabelAttribute:
return true;
default:
return false;
}
};
RewriteVisitor::Rewriter rewriter = [pool, sym, isEdge](const Expression *e) -> Expression * {
switch (e->kind()) {
case Expression::Kind::kLabel: {
auto laExpr = static_cast<const LabelExpression *>(e);
if (isEdge) {
return EdgePropertyExpression::make(pool, sym, laExpr->name());
} else {
return SourcePropertyExpression::make(pool, sym, laExpr->name());
}
}
case Expression::Kind::kLabelAttribute: {
auto laExpr = static_cast<const LabelAttributeExpression *>(e);
if (isEdge) {
return EdgePropertyExpression::make(
pool, laExpr->left()->name(), laExpr->right()->value().getStr());
} else {
return nullptr;
}
}
default:
return nullptr;
}
};
auto *newExpr = RewriteVisitor::transform(expr, matcher, rewriter);
return newExpr;
}

Status UpdateVertexValidator::validateImpl() {
Expand Down
1 change: 0 additions & 1 deletion src/graph/visitor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ nebula_add_library(
ExtractPropExprVisitor.cpp
ExtractFilterExprVisitor.cpp
FoldConstantExprVisitor.cpp
RewriteSymExprVisitor.cpp
RewriteVisitor.cpp
FindVisitor.cpp
VidExtractVisitor.cpp
Expand Down
Loading

0 comments on commit 45f5bfd

Please sign in to comment.