Skip to content

Commit

Permalink
fix test error
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Nov 22, 2021
1 parent f6a2e54 commit c02c2ca
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 62 deletions.
18 changes: 10 additions & 8 deletions src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Status MatchValidator::buildNodeInfo(const MatchPath *path,
}
Expression *filter = nullptr;
if (props != nullptr) {
auto result = makeNodeSubFilter(props, "*");
auto result = makeNodeSubFilter(const_cast<MapExpression *>(props), "*");
NG_RETURN_IF_ERROR(result);
filter = result.value();
} else if (node->labels() != nullptr && !node->labels()->labels().empty()) {
Expand Down Expand Up @@ -248,7 +248,7 @@ Status MatchValidator::buildEdgeInfo(const MatchPath *path,
}
Expression *filter = nullptr;
if (props != nullptr) {
auto result = makeEdgeSubFilter(props);
auto result = makeEdgeSubFilter(const_cast<MapExpression *>(props));
NG_RETURN_IF_ERROR(result);
filter = result.value();
}
Expand Down Expand Up @@ -519,7 +519,7 @@ Status MatchValidator::validateUnwind(const UnwindClause *unwindClause,
return Status::OK();
}

StatusOr<Expression *> MatchValidator::makeEdgeSubFilter(const MapExpression *map) const {
StatusOr<Expression *> MatchValidator::makeEdgeSubFilter(MapExpression *map) const {
auto *pool = qctx_->objPool();
DCHECK(map != nullptr);
auto &items = map->items();
Expand All @@ -529,19 +529,21 @@ StatusOr<Expression *> MatchValidator::makeEdgeSubFilter(const MapExpression *ma
NG_RETURN_IF_ERROR(foldStatus);
auto foldExpr = foldStatus.value();
if (!ExpressionUtils::isEvaluableExpr(foldExpr)) {
return Status::SemanticError("Props must be constant: `%s'",
return Status::SemanticError("Props must be evaluable: `%s'",
items[0].second->toString().c_str());
}
map->setItem(0, std::make_pair(items[0].first, foldExpr));
Expression *root = RelationalExpression::makeEQ(
pool, EdgePropertyExpression::make(pool, "*", items[0].first), foldExpr);
for (auto i = 1u; i < items.size(); i++) {
foldStatus = ExpressionUtils::foldConstantExpr(items[i].second);
NG_RETURN_IF_ERROR(foldStatus);
foldExpr = foldStatus.value();
if (!ExpressionUtils::isEvaluableExpr(foldExpr)) {
return Status::SemanticError("Props must be constant: `%s'",
return Status::SemanticError("Props must be evaluable: `%s'",
items[i].second->toString().c_str());
}
map->setItem(0, std::make_pair(items[i].first, foldExpr));
auto *left = root;
auto *right = RelationalExpression::makeEQ(
pool, EdgePropertyExpression::make(pool, "*", items[i].first), foldExpr);
Expand All @@ -550,7 +552,7 @@ StatusOr<Expression *> MatchValidator::makeEdgeSubFilter(const MapExpression *ma
return root;
}

StatusOr<Expression *> MatchValidator::makeNodeSubFilter(const MapExpression *map,
StatusOr<Expression *> MatchValidator::makeNodeSubFilter(MapExpression *map,
const std::string &label) const {
auto *pool = qctx_->objPool();
// Node has tag without property
Expand All @@ -573,7 +575,7 @@ StatusOr<Expression *> MatchValidator::makeNodeSubFilter(const MapExpression *ma
return Status::SemanticError("Props must be evaluable: `%s'",
items[0].second->toString().c_str());
}
// map->setItem(0, std::make_pair(items[0].first, foldExpr));
map->setItem(0, std::make_pair(items[0].first, foldExpr));
Expression *root = RelationalExpression::makeEQ(
pool, TagPropertyExpression::make(pool, label, items[0].first), foldExpr);
for (auto i = 1u; i < items.size(); i++) {
Expand All @@ -584,7 +586,7 @@ StatusOr<Expression *> MatchValidator::makeNodeSubFilter(const MapExpression *ma
return Status::SemanticError("Props must be evaluable: `%s'",
items[i].second->toString().c_str());
}
// map->setItem(i, std::make_pair(items[i].first, foldExpr));
map->setItem(i, std::make_pair(items[i].first, foldExpr));
auto *left = root;
auto *right = RelationalExpression::makeEQ(
pool, TagPropertyExpression::make(pool, label, items[i].first), foldExpr);
Expand Down
5 changes: 2 additions & 3 deletions src/graph/validator/MatchValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ class MatchValidator final : public Validator {

Status buildOutputs(const YieldColumns *yields);

StatusOr<Expression *> makeEdgeSubFilter(const MapExpression *map) const;
StatusOr<Expression *> makeEdgeSubFilter(MapExpression *map) const;

StatusOr<Expression *> makeNodeSubFilter(const MapExpression *map,
const std::string &label) const;
StatusOr<Expression *> makeNodeSubFilter(MapExpression *map, const std::string &label) const;

private:
std::unique_ptr<MatchAstContext> matchCtx_;
Expand Down
12 changes: 6 additions & 6 deletions src/graph/visitor/test/FilterTransformTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST_F(FilterTransformTest, TestCalculationOverflow) {
auto expr =
ltExpr(minusExpr(laExpr("v", "age"), constantExpr(1)), constantExpr(9223372036854775807));
auto res = ExpressionUtils::filterTransform(expr);
auto expected = Status::Error(
auto expected = Status::SemanticError(
"result of (9223372036854775807+1) cannot be represented as an "
"integer");
ASSERT(!res.status().ok());
Expand All @@ -39,7 +39,7 @@ TEST_F(FilterTransformTest, TestCalculationOverflow) {
{
auto expr = ltExpr(addExpr(laExpr("v", "age"), constantExpr(1)), constantExpr(INT64_MIN));
auto res = ExpressionUtils::filterTransform(expr);
auto expected = Status::Error(
auto expected = Status::SemanticError(
"result of (-9223372036854775808-1) cannot be represented as an "
"integer");
ASSERT(!res.status().ok());
Expand All @@ -50,7 +50,7 @@ TEST_F(FilterTransformTest, TestCalculationOverflow) {
auto expr = ltExpr(minusExpr(laExpr("v", "age"), constantExpr(1)),
addExpr(constantExpr(9223372036854775807), constantExpr(1)));
auto res = ExpressionUtils::filterTransform(expr);
auto expected = Status::Error(
auto expected = Status::SemanticError(
"result of (9223372036854775807+1) cannot be represented as an "
"integer");
ASSERT(!res.status().ok());
Expand All @@ -61,7 +61,7 @@ TEST_F(FilterTransformTest, TestCalculationOverflow) {
auto expr = ltExpr(addExpr(laExpr("v", "age"), constantExpr(1)),
minusExpr(constantExpr(INT64_MIN), constantExpr(1)));
auto res = ExpressionUtils::filterTransform(expr);
auto expected = Status::Error(
auto expected = Status::SemanticError(
"result of (-9223372036854775808-1) cannot be represented as an "
"integer");
ASSERT(!res.status().ok());
Expand All @@ -72,7 +72,7 @@ TEST_F(FilterTransformTest, TestCalculationOverflow) {
auto expr = notExpr(notExpr(notExpr(ltExpr(minusExpr(laExpr("v", "age"), constantExpr(1)),
constantExpr(9223372036854775807)))));
auto res = ExpressionUtils::filterTransform(expr);
auto expected = Status::Error(
auto expected = Status::SemanticError(
"result of (9223372036854775807+1) cannot be represented as an "
"integer");
ASSERT(!res.status().ok());
Expand All @@ -83,7 +83,7 @@ TEST_F(FilterTransformTest, TestCalculationOverflow) {
auto expr = notExpr(notExpr(
notExpr(ltExpr(addExpr(laExpr("v", "age"), constantExpr(1)), constantExpr(INT64_MIN)))));
auto res = ExpressionUtils::filterTransform(expr);
auto expected = Status::Error(
auto expected = Status::SemanticError(
"result of (-9223372036854775808-1) cannot be represented as an "
"integer");
ASSERT(!res.status().ok());
Expand Down
12 changes: 6 additions & 6 deletions tests/tck/features/expression/Null.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ Feature: NULL related operations
| NULL | NULL | NULL | NULL | NULL |
When executing query:
"""
RETURN cos(NULL) AS value1, acos(NULL) AS value2, tan(NULL) AS value3, atan(NULL) AS value4, rand32(NULL) AS value5
RETURN cos(NULL) AS value1, acos(NULL) AS value2, tan(NULL) AS value3, atan(NULL) AS value4
"""
Then the result should be, in any order:
| value1 | value2 | value3 | value4 | value5 |
| NULL | NULL | NULL | NULL | BAD_TYPE |
| value1 | value2 | value3 | value4 |
| NULL | NULL | NULL | NULL |
When executing query:
"""
RETURN collect(NULL) AS value1, avg(NULL) AS value2, count(NULL) AS value3, max(NULL) AS value4, rand64(NULL,NULL) AS value5
RETURN collect(NULL) AS value1, avg(NULL) AS value2, count(NULL) AS value3, max(NULL) AS value4
"""
Then the result should be, in any order:
| value1 | value2 | value3 | value4 | value5 |
| [] | NULL | 0 | NULL | BAD_TYPE |
| value1 | value2 | value3 | value4 |
| [] | NULL | 0 | NULL |
When executing query:
"""
RETURN min(NULL) AS value1, std(NULL) AS value2, sum(NULL) AS value3, bit_and(NULL) AS value4, bit_or(NULL,NULL) AS value5
Expand Down
8 changes: 2 additions & 6 deletions tests/tck/features/expression/StartsWith.feature
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ Feature: Starts With Expression
"""
YIELD 123 STARTS WITH 1
"""
Then the result should be, in any order:
| (123 STARTS WITH 1) |
| BAD_TYPE |
Then a SemanticError should be raised at runtime: Type error `(123 STARTS WITH 1)'
Scenario: yield not starts with
When executing query:
Expand Down Expand Up @@ -90,9 +88,7 @@ Feature: Starts With Expression
"""
YIELD 123 NOT STARTS WITH 1
"""
Then the result should be, in any order:
| (123 NOT STARTS WITH 1) |
| BAD_TYPE |
Then a SemanticError should be raised at runtime: Type error `(123 NOT STARTS WITH 1)'
Scenario: starts with go
When executing query:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Feature: Mathematical function Expression
"""
return [bit_and(5,true),bit_or(2,1.3),bit_xor("5",1)] as error_test
"""
Then a SemanticError should be raised at runtime: Type error Type error `bit_and(5,true)'
Then a SemanticError should be raised at runtime: Type error `bit_and(5,true)'
45 changes: 27 additions & 18 deletions tests/tck/features/expression/function/TypeConversion.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,81 @@ Feature: TypeConversion Expression
Scenario: toBoolean
When executing query:
"""
YIELD [toBoolean(true), toBoolean(false), toBoolean(1), toBoolean(3.14),
YIELD [toBoolean(true), toBoolean(false),
toBoolean("trUe"), toBoolean("3.14"), toBoolean(null)] AS yield_toBoolean
"""
Then the result should be, in any order:
| yield_toBoolean |
| [true, false, BAD_TYPE, BAD_TYPE, true, NULL, NULL] |
| yield_toBoolean |
| [true, false, true, NULL, NULL] |
When executing query:
"""
UNWIND [true, false, 1, 3.14, "trUe", "3.14", null] AS b
UNWIND [true, false, "trUe", "3.14", null] AS b
RETURN toBoolean(b) AS unwind_toBoolean
"""
Then the result should be, in any order:
| unwind_toBoolean |
| true |
| false |
| BAD_TYPE |
| BAD_TYPE |
| true |
| NULL |
| NULL |
When executing query:
"""
YIELD [toBoolean(1), toBoolean(3.14)] AS yield_toBoolean
"""
Then a SemanticError should be raised at runtime: Type error `toBoolean(1)'
Scenario: toFloat
When executing query:
"""
YIELD [toFloat(true), toFloat(false), toFloat(1), toFloat(3.14),
YIELD [toFloat(1), toFloat(3.14),
toFloat("trUe"), toFloat("3.14"), toFloat(null)] AS yield_toFloat
"""
Then the result should be, in any order:
| yield_toFloat |
| [BAD_TYPE, BAD_TYPE, 1.0, 3.14, NULL, 3.14, NULL] |
| yield_toFloat |
| [1.0, 3.14, NULL, 3.14, NULL] |
When executing query:
"""
UNWIND [true, false, 1, 3.14, "trUe", "3.14", null] AS b
UNWIND [1, 3.14, "trUe", "3.14", null] AS b
RETURN toFloat(b) AS unwind_toFloat
"""
Then the result should be, in any order:
| unwind_toFloat |
| BAD_TYPE |
| BAD_TYPE |
| 1.0 |
| 3.14 |
| NULL |
| 3.14 |
| NULL |
When executing query:
"""
YIELD [toFloat(true), toFloat(false)] AS yield_toFloat
"""
Then a SemanticError should be raised at runtime: Type error `toFloat(true)'

Scenario: toInteger
When executing query:
"""
YIELD [toInteger(true), toInteger(false), toInteger(1), toInteger(3.14),
YIELD [toInteger(1), toInteger(3.14),
toInteger("trUe"), toInteger("3.14"), toInteger(null), toInteger("1e3"),
toInteger("1E3"), toInteger("1.5E4")] AS yield_toInteger
"""
Then the result should be, in any order:
| yield_toInteger |
| [BAD_TYPE, BAD_TYPE, 1, 3, NULL, 3, NULL, 1000, 1000, 15000] |
| yield_toInteger |
| [1, 3, NULL, 3, NULL, 1000, 1000, 15000] |
When executing query:
"""
UNWIND [true, false, 1, 3.14, "trUe", "3.14", null] AS b
UNWIND [1, 3.14, "trUe", "3.14", null] AS b
RETURN toInteger(b) AS unwind_toInteger
"""
Then the result should be, in any order:
| unwind_toInteger |
| BAD_TYPE |
| BAD_TYPE |
| 1 |
| 3 |
| NULL |
| 3 |
| NULL |
When executing query:
"""
YIELD [toInteger(true), toInteger(false)] AS yield_toInteger
"""
Then a SemanticError should be raised at runtime: Type error `toInteger(true)'
4 changes: 2 additions & 2 deletions tests/tck/features/lookup/ByIndex.feature
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ Feature: Lookup by index itself
"""
LOOKUP ON player WHERE player.age > 9223372036854775807+1
"""
Then a ExecutionError should be raised at runtime: result of (9223372036854775807+1) cannot be represented as an integer
Then a SemanticError should be raised at runtime: result of (9223372036854775807+1) cannot be represented as an integer
When executing query:
"""
LOOKUP ON player WHERE player.age > -9223372036854775808-1
"""
Then a ExecutionError should be raised at runtime: result of (-9223372036854775808-1) cannot be represented as an integer
Then a SemanticError should be raised at runtime: result of (-9223372036854775808-1) cannot be represented as an integer

Scenario: [2] edge index
Given a graph with space named "nba"
Expand Down
4 changes: 2 additions & 2 deletions tests/tck/features/lookup/ByIndex.intVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ Feature: Lookup by index itself in integer vid
"""
LOOKUP ON player WHERE player.age > 9223372036854775807+1
"""
Then a ExecutionError should be raised at runtime: result of (9223372036854775807+1) cannot be represented as an integer
Then a SemanticError should be raised at runtime: result of (9223372036854775807+1) cannot be represented as an integer
When executing query:
"""
LOOKUP ON player WHERE player.age > -9223372036854775808-1
"""
Then a ExecutionError should be raised at runtime: result of (-9223372036854775808-1) cannot be represented as an integer
Then a SemanticError should be raised at runtime: result of (-9223372036854775808-1) cannot be represented as an integer

Scenario: [2] edge index
Given a graph with space named "nba_int_vid"
Expand Down
9 changes: 3 additions & 6 deletions tests/tck/features/match/Base.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,9 @@ Feature: Basic match
match (v:player)-[e:like{likeness:4*20+5}]->() return e
"""
Then the result should be, in any order, with relax comparison:
| e |
| [:like "Tim Duncan"->"Manu Ginobili" @0 {likeness: 95}] |
| [:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}] |
| [:like "Paul George"->"Russell Westbrook" @0 {likeness: 95}] |
| [:like "Tony Parker"->"Manu Ginobili" @0 {likeness: 95}] |
| [:like "Tony Parker"->"Tim Duncan" @0 {likeness: 95}] |
| e |
| [:like "Jason Kidd"->"Dirk Nowitzki"@0{likeness:85}] |
| [:like "Steve Nash"->"Jason Kidd"@0{likeness:85}] |
When executing query:
"""
match (v:player)-[e:like{likeness:"99"}]->() return e
Expand Down
4 changes: 2 additions & 2 deletions tests/tck/features/match/Base.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2020 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
@jmq
Feature: Basic match

Background:
Expand Down Expand Up @@ -577,8 +578,7 @@ Feature: Basic match
"""
match (v:player{age:"24"-1}) return v
"""
Then the result should be, in any order, with relax comparison:
| v |
Then a SemanticError should be raised at runtime: Type error `("24"-1)'
Scenario: No return
When executing query:
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/schema/Schema.feature
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ Feature: Insert string vid of vertex and edge
"""
CREATE TAG bad_null_default_value(name string DEFAULT "N/A", age int DEFAULT 1%0)
"""
Then a ExecutionError should be raised at runtime: / by zero
Then a SemanticError should be raised at runtime: Divide by 0
# test alter tag with wrong type default value of string when add
When executing query:
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/yield/yield.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ Feature: Yield Sentence
"""
YIELD --9223372036854775808
"""
Then a ExecutionError should be raised at runtime: result of -(-9223372036854775808) cannot be represented as an integer
Then a SemanticError should be raised at runtime: result of -(-9223372036854775808) cannot be represented as an integer
When executing query:
"""
YIELD -9223372036854775809
Expand Down

0 comments on commit c02c2ca

Please sign in to comment.