Skip to content

Commit

Permalink
hack a fix for ListComprehensionExpression.
Browse files Browse the repository at this point in the history
  • Loading branch information
xtcyclist committed Dec 15, 2022
1 parent dffa71f commit 5c6de3b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/common/expression/AttributeExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,28 @@ const Value &AttributeExpression::eval(ExpressionContext &ctx) {
result_ = lvalue.getVertex().vid;
return result_;
}
LOG(ERROR) << "Var.tar.prop cannot be evaluated as an attribute expression.";
/*
* WARNING: the following code snippet is a hardcode to address the legacy
* problem of treating LabelTagProperty expressions as Attribute expressions.
* It is needed to allow users to write ver.tag.prop in ListComprehensionExpression.
*/
if (left()->kind() == Expression::Kind::kVar) {
return lvalue;
} else if (left()->kind() == Expression::Kind::kAttribute &&
dynamic_cast<AttributeExpression *>(left())->right()->kind() ==
Expression::Kind::kConstant) {
auto &tagName = dynamic_cast<AttributeExpression *>(left())->right()->eval(ctx).getStr();
for (auto &tag : lvalue.getVertex().tags) {
if (tagName.compare(tag.name) != 0) {
continue;
} else {
auto iter = tag.props.find(rvalue.getStr());
if (iter != tag.props.end()) {
return iter->second;
}
}
}
}
return Value::kNullBadType;
}
case Value::Type::EDGE: {
Expand Down
1 change: 1 addition & 0 deletions src/graph/util/ParserUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "common/base/ObjectPool.h"
#include "common/base/Status.h"
#include "common/base/StatusOr.h"
#include "graph/util/ExpressionUtils.h"

namespace nebula {
namespace graph {
Expand Down
13 changes: 11 additions & 2 deletions src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,17 @@ Status MatchValidator::validateReturn(MatchReturn *ret,
ExpressionUtils::hasAny(column->expr(), {Expression::Kind::kAggregate})) {
retClauseCtx.yield->hasAgg_ = true;
}
column->setExpr(ExpressionUtils::rewriteAttr2LabelTagProp(
column->expr(), retClauseCtx.yield->aliasesAvailable));
if (column->expr()->kind() == Expression::Kind::kListComprehension) {
auto expr = dynamic_cast<ListComprehensionExpression *>(column->expr());
if (expr->hasMapping()) {
expr->setMapping(ExpressionUtils::rewriteAttr2LabelTagProp(
expr->mapping(), retClauseCtx.yield->aliasesAvailable));
column->setExpr(expr);
}
} else {
column->setExpr(ExpressionUtils::rewriteAttr2LabelTagProp(
column->expr(), retClauseCtx.yield->aliasesAvailable));
}
exprs.push_back(column->expr());
columns->addColumn(column->clone().release());
}
Expand Down

0 comments on commit 5c6de3b

Please sign in to comment.