Skip to content
Snippets Groups Projects
Unverified Commit 3a800956 authored by kyle.cao's avatar kyle.cao Committed by GitHub
Browse files

fix update/upsert (#772)


* fix update/upsert when clause

fix non bool col filter

add test cases

fix ut

fix tck

* fix copy elision

Co-authored-by: default avatarjie.wang <38901892+jievince@users.noreply.github.com>
Co-authored-by: default avatarYee <2520865+yixinglu@users.noreply.github.com>
parent 7d913900
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
......
......@@ -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}));
}
......
......@@ -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:
"""
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment