Skip to content

Commit

Permalink
delete labeltagpropertyexpression file
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Dec 6, 2021
1 parent 6e6ffc0 commit 0f5d679
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 211 deletions.
1 change: 0 additions & 1 deletion src/common/expression/ExprVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "common/expression/FunctionCallExpression.h"
#include "common/expression/LabelAttributeExpression.h"
#include "common/expression/LabelExpression.h"
#include "common/expression/LabelTagPropertyExpression.h"
#include "common/expression/ListComprehensionExpression.h"
#include "common/expression/LogicalExpression.h"
#include "common/expression/PathBuildExpression.h"
Expand Down
2 changes: 0 additions & 2 deletions src/common/expression/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "common/expression/FunctionCallExpression.h"
#include "common/expression/LabelAttributeExpression.h"
#include "common/expression/LabelExpression.h"
#include "common/expression/LabelTagPropertyExpression.h"
#include "common/expression/ListComprehensionExpression.h"
#include "common/expression/LogicalExpression.h"
#include "common/expression/PathBuildExpression.h"
Expand Down Expand Up @@ -390,7 +389,6 @@ Expression* Expression::decode(ObjectPool* pool, Expression::Decoder& decoder) {
return exp;
}
case Expression::Kind::kVarProperty: {
// LOG(FATAL) << "Should not decode variable property expression";
exp = VariablePropertyExpression::make(pool);
exp->resetFrom(decoder);
return exp;
Expand Down
55 changes: 0 additions & 55 deletions src/common/expression/LabelTagPropertyExpression.cpp

This file was deleted.

65 changes: 0 additions & 65 deletions src/common/expression/LabelTagPropertyExpression.h

This file was deleted.

2 changes: 2 additions & 0 deletions src/common/expression/PropertyExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class LabelTagPropertyExpression final : public PropertyExpression {

const Expression* label() const { return label_; }

Expression* label() { return label_; }

private:
LabelTagPropertyExpression(ObjectPool* pool,
Expression* label = nullptr,
Expand Down
11 changes: 5 additions & 6 deletions src/graph/planner/match/LabelIndexSeek.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ StatusOr<SubPlan> LabelIndexSeek::transformNode(NodeContext* nodeCtx) {
const auto& nodeAlias = nodeCtx->info->alias;

if (filter->kind() == Expression::Kind::kLogicalOr) {
auto labelExprs = ExpressionUtils::collectAll(filter, {Expression::Kind::kLabel});
auto exprs = ExpressionUtils::collectAll(filter, {Expression::Kind::kLabelTagProperty});
bool labelMatched = true;
for (auto* labelExpr : labelExprs) {
DCHECK_EQ(labelExpr->kind(), Expression::Kind::kLabel);
if (static_cast<const LabelExpression*>(labelExpr)->name() != nodeAlias) {
for (auto* expr : exprs) {
auto tagPropExpr = static_cast<const LabelTagPropertyExpression*>(expr);
if (static_cast<const PropertyExpression*>(tagPropExpr->label())->prop() != nodeAlias) {
labelMatched = false;
break;
}
Expand All @@ -117,9 +117,8 @@ StatusOr<SubPlan> LabelIndexSeek::transformNode(NodeContext* nodeCtx) {
}
}
if (canBeEmbedded2IndexScan) {
auto* srcFilter = ExpressionUtils::rewriteAttr2LabelTagProp(flattenFilter);
storage::cpp2::IndexQueryContext ctx;
ctx.set_filter(Expression::encode(*srcFilter));
ctx.set_filter(Expression::encode(*flattenFilter));
scan->setIndexQueryContext({ctx});
whereCtx.reset();
}
Expand Down
23 changes: 9 additions & 14 deletions src/graph/planner/match/MatchSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ Expression* MatchSolver::doRewrite(QueryContext* qctx,
auto alias = aliases.find(labelExpr->name());
DCHECK(alias != aliases.end());
}
auto res = ExpressionUtils::rewriteAttr2LabelTagProp(expr);
return rewriteLabel2VarProp(qctx, res);
return rewriteLabel2VarProp(qctx, expr);
}

Expression* MatchSolver::makeIndexFilter(const std::string& label,
Expand Down Expand Up @@ -162,27 +161,23 @@ Expression* MatchSolver::makeIndexFilter(const std::string& label,
}
propName = la->right()->value().getStr();
} else {
const AttributeExpression* la = nullptr;
if (left->kind() == Expression::Kind::kAttribute &&
const LabelTagPropertyExpression* la = nullptr;
if (left->kind() == Expression::Kind::kLabelTagProperty &&
right->kind() == Expression::Kind::kConstant) {
la = static_cast<const AttributeExpression*>(left);
la = static_cast<const LabelTagPropertyExpression*>(left);
constant = static_cast<const ConstantExpression*>(right);
} else if (right->kind() == Expression::Kind::kAttribute &&
} else if (right->kind() == Expression::Kind::kLabelTagProperty &&
left->kind() == Expression::Kind::kConstant) {
la = static_cast<const AttributeExpression*>(right);
la = static_cast<const LabelTagPropertyExpression*>(right);
constant = static_cast<const ConstantExpression*>(left);
} else {
continue;
}
if (la->left()->kind() != Expression::Kind::kLabelAttribute) {
if (static_cast<const PropertyExpression*>(la->label())->prop() != alias ||
la->sym() != label) {
continue;
}
auto labelAttExpr = static_cast<const LabelAttributeExpression*>(la->left());
if (labelAttExpr->left()->name() != alias ||
labelAttExpr->right()->value().getStr() != label) {
continue;
}
propName = static_cast<const ConstantExpression*>(la->right())->value().getStr();
propName = la->prop();
}

auto* tpExpr =
Expand Down
35 changes: 12 additions & 23 deletions src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Status MatchValidator::validateFilter(const Expression *filter,
auto transformRes = ExpressionUtils::filterTransform(filter);
NG_RETURN_IF_ERROR(transformRes);
// rewrite Attribute to LabelTagProperty
whereClauseCtx.filter = transformRes.value();
whereClauseCtx.filter = ExpressionUtils::rewriteAttr2LabelTagProp(transformRes.value());

auto typeStatus = deduceExprType(whereClauseCtx.filter);
NG_RETURN_IF_ERROR(typeStatus);
Expand Down Expand Up @@ -364,7 +364,7 @@ Status MatchValidator::validateReturn(MatchReturn *ret,
ExpressionUtils::hasAny(column->expr(), {Expression::Kind::kAggregate})) {
retClauseCtx.yield->hasAgg_ = true;
}
// column->setExpr(ExpressionUtils::rewriteAttr2LabelTagProp(column->expr()));
column->setExpr(ExpressionUtils::rewriteAttr2LabelTagProp(column->expr()));
exprs.push_back(column->expr());
columns->addColumn(column->clone().release());
}
Expand Down Expand Up @@ -397,7 +397,6 @@ Status MatchValidator::validateAliases(
static const std::unordered_set<Expression::Kind> kinds = {Expression::Kind::kLabel,
Expression::Kind::kLabelAttribute,
Expression::Kind::kLabelTagProperty,
Expression::Kind::kAttribute,
// primitive props
Expression::Kind::kEdgeSrc,
Expression::Kind::kEdgeDst,
Expand Down Expand Up @@ -452,11 +451,13 @@ Status MatchValidator::validateWith(const WithClause *with,
exprs.reserve(withClauseCtx.yield->yieldColumns->size());
for (auto *col : withClauseCtx.yield->yieldColumns->columns()) {
auto labelExprs = ExpressionUtils::collectAll(col->expr(), {Expression::Kind::kLabel});
auto aliasType = AliasType::kDefault;
for (auto *labelExpr : labelExprs) {
auto label = static_cast<const LabelExpression *>(labelExpr)->name();
if (!withClauseCtx.yield->aliasesUsed || !withClauseCtx.yield->aliasesUsed->count(label)) {
return Status::SemanticError("Variable `%s` not defined", label.c_str());
}
aliasType = withClauseCtx.yield->aliasesUsed->at(label);
}
if (col->alias().empty()) {
if (col->expr()->kind() == Expression::Kind::kLabel) {
Expand All @@ -465,7 +466,7 @@ Status MatchValidator::validateWith(const WithClause *with,
return Status::SemanticError("Expression in WITH must be aliased (use AS)");
}
}
if (!withClauseCtx.aliasesGenerated.emplace(col->alias(), AliasType::kDefault).second) {
if (!withClauseCtx.aliasesGenerated.emplace(col->alias(), aliasType).second) {
return Status::SemanticError("`%s': Redefined alias", col->alias().c_str());
}
if (!withClauseCtx.yield->hasAgg_ &&
Expand Down Expand Up @@ -795,25 +796,13 @@ Status MatchValidator::checkAlias(
NG_RETURN_IF_ERROR(res);
return Status::OK();
}
// case Expression::Kind::kLabelTagProperty: {
// auto labelExpr = static_cast<const LabelTagPropertyExpression *>(refExpr)->label();
// auto name = static_cast<const VariablePropertyExpression *>(labelExpr)->prop();
// auto res = getAliasType(aliasesUsed, name);
// NG_RETURN_IF_ERROR(res);
// if (res.value() != AliasType::kNode) {
// return Status::SemanticError("The type of `%s' must be tag", name.c_str());
// }
// return Status::OK();
// }
case Expression::Kind::kAttribute: {
auto leftExpr = static_cast<const AttributeExpression *>(refExpr)->left();
if (leftExpr->kind() == Expression::Kind::kLabelAttribute) {
auto name = static_cast<const LabelAttributeExpression *>(leftExpr)->left()->name();
auto res = getAliasType(aliasesUsed, name);
NG_RETURN_IF_ERROR(res);
if (res.value() != AliasType::kNode) {
return Status::SemanticError("The type of `%s' should be tag", name.c_str());
}
case Expression::Kind::kLabelTagProperty: {
auto labelExpr = static_cast<const LabelTagPropertyExpression *>(refExpr)->label();
auto name = static_cast<const VariablePropertyExpression *>(labelExpr)->prop();
auto res = getAliasType(aliasesUsed, name);
NG_RETURN_IF_ERROR(res);
if (res.value() != AliasType::kNode) {
return Status::SemanticError("The type of `%s' should be tag", name.c_str());
}
return Status::OK();
}
Expand Down
8 changes: 6 additions & 2 deletions src/graph/visitor/FindVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ void FindVisitor::visit(EdgePropertyExpression* expr) { findInCurrentExpr(expr);

void FindVisitor::visit(TagPropertyExpression* expr) { findInCurrentExpr(expr); }

void FindVisitor::visit(LabelTagPropertyExpression* expr) { findInCurrentExpr(expr); }

void FindVisitor::visit(InputPropertyExpression* expr) { findInCurrentExpr(expr); }

void FindVisitor::visit(VariablePropertyExpression* expr) { findInCurrentExpr(expr); }
Expand Down Expand Up @@ -169,6 +167,12 @@ void FindVisitor::visit(LabelAttributeExpression* expr) {
expr->right()->accept(this);
}

void FindVisitor::visit(LabelTagPropertyExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && !foundExprs_.empty()) return;
expr->label()->accept(this);
}

void FindVisitor::visit(VertexExpression* expr) { findInCurrentExpr(expr); }

void FindVisitor::visit(EdgeExpression* expr) { findInCurrentExpr(expr); }
Expand Down
8 changes: 6 additions & 2 deletions tests/tck/features/expression/Attribute.feature
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ Feature: Attribute
"""
MATCH (v) WHERE id(v) == 'Tim Duncan' RETURN v.name.not_exists_attr
"""
Then a ExecutionError should be raised at runtime: TagName `name' is nonexistent
Then the result should be, in any order:
| v.name.not_exists_attr |
| NULL |
When executing query:
"""
MATCH (v) WHERE id(v) == 'Tim Duncan' RETURN v.player.name.test
"""
Then a SemanticError should be raised at runtime: `v.player.name.ab', expected type with attribute like Date, Time, DateTime, Map, Vertex or Edge but was STRING: v.player.name
Then the result should be, in any order:
| v.player.name.test |
| BAD_TYPE |
6 changes: 4 additions & 2 deletions tests/tck/features/match/SameTagPropname.feature
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,12 @@ Feature: Same Tag Propname
"""
match (v:player) where v.student.height > 190 return v
"""
Then a SemanticError should be raised at runtime: `v.student.height', not found the property `height'
Then the result should be, in any order:
| v |
When executing query:
"""
match (v:player) where v.abc.height > 190 return v.player.name
"""
Then a ExecutionError should be raised at runtime: TagName `abc' is nonexistent
Then the result should be, in any order:
| v.player.name |
Then drop the used space
Loading

0 comments on commit 0f5d679

Please sign in to comment.