diff --git a/src/validator/MutateValidator.cpp b/src/validator/MutateValidator.cpp index 1c6c69c2214a205c4279fadd6015f962624521dc..3a0b3f32c369c73dc06bc150c58469240ba48b85 100644 --- a/src/validator/MutateValidator.cpp +++ b/src/validator/MutateValidator.cpp @@ -489,15 +489,28 @@ Status UpdateValidator::initProps() { Status UpdateValidator::getCondition() { auto *clause = sentence_->whenClause(); - if (clause != nullptr) { - auto filter = clause->filter(); - if (filter != nullptr) { - std::string encodeStr; - auto copyFilterExpr = filter->clone(); - NG_LOG_AND_RETURN_IF_ERROR( - checkAndResetSymExpr(copyFilterExpr.get(), name_, encodeStr)); - condition_ = std::move(encodeStr); + if (clause && clause->filter()) { + auto filter = clause->filter()->clone(); + bool hasWrongType = false; + auto symExpr = rewriteSymExpr(filter.get(), name_, hasWrongType, isEdge_); + if (hasWrongType) { + return Status::SemanticError("Has wrong expr in `%s'", + filter->toString().c_str()); + } + if (symExpr != nullptr) { + filter.reset(symExpr.release()); + } + auto typeStatus = deduceExprType(filter.get()); + NG_RETURN_IF_ERROR(typeStatus); + auto type = typeStatus.value(); + if (type != Value::Type::BOOL + && type != Value::Type::NULLVALUE + && type != Value::Type::__EMPTY__) { + std::stringstream ss; + ss << "`" << filter->toString() << "', expected Boolean, but was `" << type << "'"; + return Status::SemanticError(ss.str()); } + condition_ = filter->encode(); } return Status::OK(); } diff --git a/src/validator/test/MutateValidatorTest.cpp b/src/validator/test/MutateValidatorTest.cpp index 357373874f4133eb16c3bbd0b92180638a9ecc46..1e2e4df3f47dac767d56a53061755964b29e3b3e 100644 --- a/src/validator/test/MutateValidatorTest.cpp +++ b/src/validator/test/MutateValidatorTest.cpp @@ -164,7 +164,7 @@ TEST_F(MutateValidatorTest, UpdateVertexTest) { { auto cmd = "UPDATE VERTEX ON person \"Tom\"" "SET age = age + 1 " - "WHEN page == 18 " + "WHEN age == 18 " "YIELD name AS name, age AS age"; ASSERT_TRUE(checkResult(cmd, {PK::kUpdateVertex, PK::kStart})); } diff --git a/tests/tck/features/update/Update.feature b/tests/tck/features/update/Update.feature index 781e66bce6e09898ac337a1e015cdd14aed8ff63..c1dbc72730950e3edce007a8c7974bef58f46025 100644 --- a/tests/tck/features/update/Update.feature +++ b/tests/tck/features/update/Update.feature @@ -226,6 +226,54 @@ Feature: Update string vid of vertex and edge YIELD $^.course.name AS Name, $^.course.credits AS Credits, $$.building.name """ Then a SemanticError should be raised at runtime: Has wrong expr in `($$.course.credits+1)' + When executing query: + """ + UPDATE VERTEX "101" + SET course.credits = 1 + WHEN 123 + YIELD $^.course.name AS Name, $^.course.credits AS Credits + """ + Then a SemanticError should be raised at runtime: `123', expected Boolean, but was `INT' + When executing query: + """ + UPDATE VERTEX "101" + SET course.credits = 1 + WHEN credits + YIELD $^.course.name AS Name, $^.course.credits AS Credits + """ + Then a SemanticError should be raised at runtime: `$^.course.credits', expected Boolean, but was `INT' + When executing query: + """ + UPSERT VERTEX "101" + SET course.credits = 1 + WHEN credits + YIELD $^.course.name AS Name, $^.course.credits AS Credits + """ + Then a SemanticError should be raised at runtime: `$^.course.credits', expected Boolean, but was `INT' + When executing query: + """ + UPSERT VERTEX "101" + SET course.credits = 1 + WHEN "xyz" + YIELD $^.course.name AS Name, $^.course.credits AS Credits + """ + Then a SemanticError should be raised at runtime: `xyz', expected Boolean, but was `STRING' + When executing query: + """ + UPDATE VERTEX ON course "101" + SET credits = 1 + WHEN credits + YIELD $^.course.name AS Name, $^.course.credits AS Credits + """ + Then a SemanticError should be raised at runtime: `$^.course.credits', expected Boolean, but was `INT' + When executing query: + """ + UPSERT VERTEX ON course "101" + SET credits = 1 + WHEN "xyz" + YIELD $^.course.name AS Name, $^.course.credits AS Credits + """ + Then a SemanticError should be raised at runtime: `xyz', expected Boolean, but was `STRING' # make sure TagName and PropertyName must exist in all clauses When executing query: """ @@ -986,7 +1034,7 @@ Feature: Update string vid of vertex and edge WHEN grade > 4 AND age > 15 YIELD grade AS Grade, year AS Year """ - Then a ExecutionError should be raised at runtime: Storage Error: Edge prop not found + Then a SemanticError should be raised at runtime: `select.age', not found the property `age'. # make sure the edge(src, ranking, dst) must not exist When executing query: """