Skip to content

Commit

Permalink
rebase and add or logic testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Dec 29, 2021
1 parent 2dafe3f commit ec492a5
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 80 deletions.
26 changes: 8 additions & 18 deletions src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,16 +391,6 @@ Status MatchValidator::validateReturn(MatchReturn *ret,
DCHECK(!columns->empty());
retClauseCtx.yield->yieldColumns = columns;

// Check all referencing expressions are valid
std::vector<const Expression *> exprs;
exprs.reserve(retClauseCtx.yield->yieldColumns->size());
for (auto *col : retClauseCtx.yield->yieldColumns->columns()) {
if (!retClauseCtx.yield->hasAgg_ &&
ExpressionUtils::hasAny(col->expr(), {Expression::Kind::kAggregate})) {
retClauseCtx.yield->hasAgg_ = true;
}
exprs.push_back(col->expr());
}
NG_RETURN_IF_ERROR(validateAliases(exprs, retClauseCtx.yield->aliasesAvailable));
NG_RETURN_IF_ERROR(validateYield(*retClauseCtx.yield));

Expand Down Expand Up @@ -486,7 +476,7 @@ Status MatchValidator::validateWith(const WithClause *with,
if (!withClauseCtx.yield->aliasesAvailable.count(label)) {
return Status::SemanticError("Alias `%s` not defined", label.c_str());
}
aliasType = withClauseCtx.yield->aliasesUsed->at(label);
aliasType = withClauseCtx.yield->aliasesAvailable.at(label);
}
if (col->alias().empty()) {
if (col->expr()->kind() == Expression::Kind::kLabel) {
Expand Down Expand Up @@ -820,14 +810,14 @@ Status MatchValidator::checkAlias(
switch (kind) {
case Expression::Kind::kLabel: {
auto name = static_cast<const LabelExpression *>(refExpr)->name();
auto res = getAliasType(aliasesUsed, name);
auto res = getAliasType(aliasesAvailable, name);
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);
auto res = getAliasType(aliasesAvailable, name);
NG_RETURN_IF_ERROR(res);
if (res.value() != AliasType::kNode) {
return Status::SemanticError("The type of `%s' should be tag", name.c_str());
Expand All @@ -836,7 +826,7 @@ Status MatchValidator::checkAlias(
}
case Expression::Kind::kLabelAttribute: {
auto name = static_cast<const LabelAttributeExpression *>(refExpr)->left()->name();
auto res = getAliasType(aliasesUsed, name);
auto res = getAliasType(aliasesAvailable, name);
NG_RETURN_IF_ERROR(res);
if (res.value() == AliasType::kNode) {
return Status::SemanticError(
Expand All @@ -847,7 +837,7 @@ Status MatchValidator::checkAlias(
}
case Expression::Kind::kEdgeSrc: {
auto name = static_cast<const EdgeSrcIdExpression *>(refExpr)->sym();
auto res = getAliasType(aliasesUsed, name);
auto res = getAliasType(aliasesAvailable, name);
NG_RETURN_IF_ERROR(res);
aliasType = res.value();
switch (aliasType) {
Expand All @@ -865,7 +855,7 @@ Status MatchValidator::checkAlias(
}
case Expression::Kind::kEdgeDst: {
auto name = static_cast<const EdgeDstIdExpression *>(refExpr)->sym();
auto res = getAliasType(aliasesUsed, name);
auto res = getAliasType(aliasesAvailable, name);
NG_RETURN_IF_ERROR(res);
aliasType = res.value();
switch (aliasType) {
Expand All @@ -883,7 +873,7 @@ Status MatchValidator::checkAlias(
}
case Expression::Kind::kEdgeRank: {
auto name = static_cast<const EdgeRankExpression *>(refExpr)->sym();
auto res = getAliasType(aliasesUsed, name);
auto res = getAliasType(aliasesAvailable, name);
NG_RETURN_IF_ERROR(res);
aliasType = res.value();
switch (aliasType) {
Expand All @@ -903,7 +893,7 @@ Status MatchValidator::checkAlias(
}
case Expression::Kind::kEdgeType: {
auto name = static_cast<const EdgeTypeExpression *>(refExpr)->sym();
auto res = getAliasType(aliasesUsed, name);
auto res = getAliasType(aliasesAvailable, name);
NG_RETURN_IF_ERROR(res);
aliasType = res.value();
switch (aliasType) {
Expand Down
36 changes: 22 additions & 14 deletions tests/tck/features/match/MultiQueryParts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Feature: Multi Query Parts
When executing query:
"""
MATCH (m)-[]-(n), (n)-[]-(l) WHERE id(m)=="Tim Duncan"
RETURN m.name AS n1, n.name AS n2, l.name AS n3 ORDER BY n1, n2, n3 LIMIT 10
RETURN m.player.name AS n1, n.player.name AS n2,
CASE WHEN l.team.name is not null THEN l.team.name
WHEN l.player.name is not null THEN l.player.name ELSE "null" END AS n3 ORDER BY n1, n2, n3 LIMIT 10
"""
Then the result should be, in order:
| n1 | n2 | n3 |
Expand All @@ -27,7 +29,9 @@ Feature: Multi Query Parts
When executing query:
"""
MATCH (m)-[]-(n), (l)-[]-(n) WHERE id(m)=="Tim Duncan"
RETURN m.name AS n1, n.name AS n2, l.name AS n3 ORDER BY n1, n2, n3 LIMIT 10
RETURN m.player.name AS n1, n.player.name AS n2,
CASE WHEN l.team.name is not null THEN l.team.name
WHEN l.player.name is not null THEN l.player.name ELSE "null" END AS n3 ORDER BY n1, n2, n3 LIMIT 10
"""
Then the result should be, in order:
| n1 | n2 | n3 |
Expand All @@ -44,7 +48,7 @@ Feature: Multi Query Parts
When executing query:
"""
MATCH (m)-[]-(n), (n)-[]-(l) WHERE id(n)=="Tim Duncan"
RETURN m.name AS n1, n.name AS n2, l.name AS n3 ORDER BY n1, n2, n3 LIMIT 10
RETURN m.player.name AS n1, n.player.name AS n2, l.player.name AS n3 ORDER BY n1, n2, n3 LIMIT 10
"""
Then the result should be, in order:
| n1 | n2 | n3 |
Expand All @@ -61,7 +65,7 @@ Feature: Multi Query Parts
When executing query:
"""
MATCH (m)-[]-(n), (n)-[]-(l), (l)-[]-(h) WHERE id(m)=="Tim Duncan"
RETURN m.name AS n1, n.name AS n2, l.name AS n3, h.name AS n4
RETURN m.player.name AS n1, n.player.name AS n2, l.team.name AS n3, h.player.name AS n4
ORDER BY n1, n2, n3, n4 LIMIT 10
"""
Then the result should be, in order:
Expand Down Expand Up @@ -89,7 +93,9 @@ Feature: Multi Query Parts
"""
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
MATCH (n)-[]-(l)
RETURN m.name AS n1, n.name AS n2, l.name AS n3 ORDER BY n1, n2, n3 LIMIT 10
RETURN m.player.name AS n1, n.player.name AS n2,
CASE WHEN l.player.name is not null THEN l.player.name
WHEN l.team.name is not null THEN l.team.name ELSE "null" END AS n3 ORDER BY n1, n2, n3 LIMIT 10
"""
Then the result should be, in order:
| n1 | n2 | n3 |
Expand All @@ -107,7 +113,7 @@ Feature: Multi Query Parts
"""
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
MATCH (n)-[]-(l), (l)-[]-(h)
RETURN m.name AS n1, n.name AS n2, l.name AS n3, h.name AS n4
RETURN m.player.name AS n1, n.player.name AS n2, l.team.name AS n3, h.player.name AS n4
ORDER BY n1, n2, n3, n4 LIMIT 10
"""
Then the result should be, in order:
Expand All @@ -127,7 +133,7 @@ Feature: Multi Query Parts
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
MATCH (n)-[]-(l)
MATCH (l)-[]-(h)
RETURN m.name AS n1, n.name AS n2, l.name AS n3, h.name AS n4
RETURN m.player.name AS n1, n.player.name AS n2, l.team.name AS n3, h.player.name AS n4
ORDER BY n1, n2, n3, n4 LIMIT 10
"""
Then the result should be, in order:
Expand All @@ -148,7 +154,7 @@ Feature: Multi Query Parts
"""
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
OPTIONAL MATCH (n)<-[:serve]-(l)
RETURN m.name AS n1, n.name AS n2, l AS n3 ORDER BY n1, n2, n3 LIMIT 10
RETURN m.player.name AS n1, n.player.name AS n2, l AS n3 ORDER BY n1, n2, n3 LIMIT 10
"""
Then the result should be, in order:
| n1 | n2 | n3 |
Expand All @@ -167,17 +173,19 @@ Feature: Multi Query Parts
"""
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
OPTIONAL MATCH (a)<-[]-(b)
RETURN m.name AS n1, n.name AS n2, a.name AS n3 ORDER BY n1, n2, n3 LIMIT 10
RETURN m.player.name AS n1, n.player.name AS n2, a.player.name AS n3 ORDER BY n1, n2, n3 LIMIT 10
"""
Then a ExecutionError should be raised at runtime: Scan vertices or edges need to specify a limit number, or limit number can not push down.

Scenario: Multi Query Parts
When executing query:
"""
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
WITH n, n.name AS n1 ORDER BY n1 LIMIT 10
WITH n, n.player.name AS n1 ORDER BY n1 LIMIT 10
MATCH (n)-[]-(l)
RETURN n.name AS n1, l.name AS n2 ORDER BY n1, n2 LIMIT 10
RETURN n.player.name AS n1,
CASE WHEN l.player.name is not null THEN l.player.name
WHEN l.team.name is not null THEN l.team.name ELSE "null" END AS n2 ORDER BY n1, n2 LIMIT 10
"""
Then the result should be, in order:
| n1 | n2 |
Expand Down Expand Up @@ -215,17 +223,17 @@ Feature: Multi Query Parts
When executing query:
"""
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
WITH n, n.name AS n1 ORDER BY n1 LIMIT 10
WITH n, n.player.name AS n1 ORDER BY n1 LIMIT 10
MATCH (a)-[]-(b)
RETURN a.name AS n1, b.name AS n2 ORDER BY n1, n2 LIMIT 10
RETURN a.player.name AS n1, b.player.name AS n2 ORDER BY n1, n2 LIMIT 10
"""
Then a ExecutionError should be raised at runtime: Scan vertices or edges need to specify a limit number, or limit number can not push down.

Scenario: Some Erros
When executing query:
"""
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
WITH n, n.name AS n1 ORDER BY n1 LIMIT 10
WITH n, n.player.name AS n1 ORDER BY n1 LIMIT 10
RETURN m
"""
Then a SemanticError should be raised at runtime: Alias used but not defined: `m'
Expand Down
60 changes: 37 additions & 23 deletions tests/tck/features/match/SeekById.feature
Original file line number Diff line number Diff line change
Expand Up @@ -147,29 +147,6 @@ Feature: Match seek by id
Then the result should be, in any order:
| Name |
| 'James Harden' |
When executing query:
"""
MATCH (v)
WHERE id(v) IN ['James Harden', 'Jonathon Simmons', 'Klay Thompson', 'Dejounte Murray']
OR v.player.age == 23
RETURN v.player.name AS Name
"""
Then the result should be, in any order:
| Name |
| 'James Harden' |
| 'Jonathon Simmons' |
| 'Klay Thompson' |
| 'Dejounte Murray' |
When executing query:
"""
MATCH (v)
WHERE id(v) == 'James Harden'
OR v.player.age == 23
RETURN v.player.name AS Name
"""
Then the result should be, in any order:
| Name |
| 'James Harden' |

Scenario: complicate logical
When executing query:
Expand Down Expand Up @@ -275,6 +252,43 @@ Feature: Match seek by id
"""
Then a ExecutionError should be raised at runtime: Scan vertices or edges need to specify a limit number, or limit number can not push down.

@skip (reason = "optimizer or logic error")
Scenario: test OR logic
When executing query:
"""
MATCH (v)
WHERE id(v) IN ['James Harden', 'Jonathon Simmons', 'Klay Thompson', 'Dejounte Murray']
OR v.player.age == 23
RETURN v.player.name AS Name
"""
Then the result should be, in any order:
| Name |
| 'James Harden' |
| 'Jonathon Simmons' |
| 'Klay Thompson' |
| 'Dejounte Murray' |
| 'Kristaps Porzingis' |
When executing query:
"""
MATCH (v)
WHERE id(v) == 'James Harden'
OR v.player.age == 23
RETURN v.player.name AS Name
"""
Then the result should be, in any order:
| Name |
| 'James Harden' |
| 'Kristaps Porzingis' |
When executing query:
"""
MATCH (v)
WHERE id(v) == 'James Harden'
OR v.player.age != 23
RETURN v.player.name AS Name
"""
Then the result should be, in any order:
| Name |

Scenario: Start from end
When executing query:
"""
Expand Down
60 changes: 37 additions & 23 deletions tests/tck/features/match/SeekById.intVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,6 @@ Feature: Match seek by id
| 'Jonathon Simmons' |
| 'Klay Thompson' |
| 'Dejounte Murray' |
When executing query:
"""
MATCH (v)
WHERE id(v) IN [hash('James Harden'), hash('Jonathon Simmons'), hash('Klay Thompson'), hash('Dejounte Murray')]
OR v.player.age == 23
RETURN v.player.name AS Name
"""
Then the result should be, in any order:
| Name |
| 'James Harden' |
| 'Jonathon Simmons' |
| 'Klay Thompson' |
| 'Dejounte Murray' |
When executing query:
"""
MATCH (v)
WHERE id(v) == hash('James Harden')
OR v.player.age == 23
RETURN v.player.name AS Name
"""
Then the result should be, in any order:
| Name |
| 'James Harden' |

Scenario: basic logical with noise
When executing query:
Expand Down Expand Up @@ -268,6 +245,43 @@ Feature: Match seek by id
"""
Then a ExecutionError should be raised at runtime: Scan vertices or edges need to specify a limit number, or limit number can not push down.

@skip (reason = "optimizer or logic error")
Scenario: test OR logic
When executing query:
"""
MATCH (v)
WHERE id(v) IN [hash('James Harden'), hash('Jonathon Simmons'), hash('Klay Thompson'), hash('Dejounte Murray')]
OR v.player.age == 23
RETURN v.player.name AS Name
"""
Then the result should be, in any order:
| Name |
| 'James Harden' |
| 'Jonathon Simmons' |
| 'Klay Thompson' |
| 'Dejounte Murray' |
| 'Kristaps Porzingis' |
When executing query:
"""
MATCH (v)
WHERE id(v) == hash('James Harden')
OR v.player.age == 23
RETURN v.player.name AS Name
"""
Then the result should be, in any order:
| Name |
| 'James Harden' |
| 'Kristaps Porzingis' |
When executing query:
"""
MATCH (v)
WHERE id(v) == hash('James Harden')
OR v.player.age != 23
RETURN v.player.name AS Name
"""
Then the result should be, in any order:
| Name |

Scenario: with arithmetic
When executing query:
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/tck/features/match/With.feature
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ Feature: With clause
RETURN *, v2.player.name
"""
Then the result should be, in any order, with relax comparison:
| v | v2 | age | v2.name |
| ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | 136 | "Tim Duncan" |
| v | v2 | age | v2.player.name |
| ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | 136 | "Tim Duncan" |
When executing query:
"""
MATCH (:player)-[:like]->()
Expand Down

0 comments on commit ec492a5

Please sign in to comment.