Skip to content

Commit

Permalink
Fix DML with parameters (#5328)
Browse files Browse the repository at this point in the history
add tck

small comment

Co-authored-by: Sophie <[email protected]>
  • Loading branch information
czpmango and Sophie-Xie authored Feb 10, 2023
1 parent d0b1464 commit a6d31b3
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/codec/RowWriterV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,13 @@ WriteResult RowWriterV2::setValue(ssize_t index, const Value& val) {
}

switch (val.type()) {
case Value::Type::NULLVALUE:
case Value::Type::NULLVALUE: {
if (val.isBadNull()) {
// Property value never be bad null
return WriteResult::TYPE_MISMATCH;
}
return setNull(index);
}
case Value::Type::BOOL:
return write(index, val.getBool());
case Value::Type::INT:
Expand Down
6 changes: 3 additions & 3 deletions src/graph/util/SchemaUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ StatusOr<Value> SchemaUtil::toVertexID(Expression *expr, Value::Type vidType) {
}

// static
StatusOr<std::vector<Value>> SchemaUtil::toValueVec(std::vector<Expression *> exprs) {
StatusOr<std::vector<Value>> SchemaUtil::toValueVec(QueryContext *qctx,
std::vector<Expression *> exprs) {
std::vector<Value> values;
values.reserve(exprs.size());
QueryExpressionContext ctx;
for (auto *expr : exprs) {
auto value = expr->eval(ctx(nullptr));
auto value = expr->eval(QueryExpressionContext(qctx->ectx())());
if (value.isNull() && value.getNull() != NullType::__NULL__) {
LOG(ERROR) << expr->toString() << " is the wrong value type: " << value.typeName();
return Status::Error("Wrong value type: %s", expr->toString().c_str());
Expand Down
3 changes: 2 additions & 1 deletion src/graph/util/SchemaUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class SchemaUtil final {
static StatusOr<Value> toVertexID(Expression* expr, Value::Type vidType);

// Iterate exprs and calculate each element's value and return them as a vector.
static StatusOr<std::vector<Value>> toValueVec(std::vector<Expression*> exprs);
static StatusOr<std::vector<Value>> toValueVec(QueryContext* qctx,
std::vector<Expression*> exprs);

// Returns the "Field", "Type", "Null", "Default", "Comment" of the schema as a dataset
static StatusOr<DataSet> toDescSchema(const meta::cpp2::Schema& schema);
Expand Down
12 changes: 7 additions & 5 deletions src/graph/validator/MutateValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Status InsertVerticesValidator::prepareVertices() {
return Status::SemanticError("Insert wrong value: `%s'.", value->toString().c_str());
}
}
auto valsRet = SchemaUtil::toValueVec(row->values());
auto valsRet = SchemaUtil::toValueVec(qctx_, row->values());
NG_RETURN_IF_ERROR(valsRet);
auto values = std::move(valsRet).value();

Expand Down Expand Up @@ -252,7 +252,7 @@ Status InsertEdgesValidator::prepareEdges() {
}
}

auto valsRet = SchemaUtil::toValueVec(row->values());
auto valsRet = SchemaUtil::toValueVec(qctx_, row->values());
NG_RETURN_IF_ERROR(valsRet);
auto props = std::move(valsRet).value();

Expand Down Expand Up @@ -755,9 +755,7 @@ Expression *UpdateValidator::rewriteSymExpr(Expression *expr,
Expression::Kind::kVersionedVar,
Expression::Kind::kVarProperty,
Expression::Kind::kInputProperty,
Expression::Kind::kVar,
// Expression::Kind::kLabelAttribute, valid only for update edge
Expression::Kind::kAttribute,
Expression::Kind::kSubscript,
Expression::Kind::kUUID,
Expression::Kind::kTagProperty,
Expand All @@ -774,6 +772,10 @@ Expression *UpdateValidator::rewriteSymExpr(Expression *expr,
invalidExprs.emplace(Expression::Kind::kLabelAttribute);
invalidExprs.emplace(Expression::Kind::kEdgeProperty);
}
if (ExpressionUtils::checkVarExprIfExist(expr, qctx_)) {
hasWrongType = true;
return nullptr;
}
auto *r = ExpressionUtils::findAny(expr, invalidExprs);
if (r != nullptr) {
hasWrongType = true;
Expand Down Expand Up @@ -814,7 +816,7 @@ Expression *UpdateValidator::rewriteSymExpr(Expression *expr,
}
};
auto *newExpr = RewriteVisitor::transform(expr, matcher, rewriter);
return newExpr;
return ExpressionUtils::rewriteParameter(newExpr, qctx_);
}

Status UpdateVertexValidator::validateImpl() {
Expand Down
5 changes: 4 additions & 1 deletion src/storage/query/QueryBaseProcessor-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ nebula::cpp2::ErrorCode QueryBaseProcessor<REQ, RESP>::checkExp(
}
return nebula::cpp2::ErrorCode::SUCCEEDED;
}
case Expression::Kind::kAttribute: {
// Skip check for attribute expression
return nebula::cpp2::ErrorCode::SUCCEEDED;
}
case Expression::Kind::kPredicate: {
auto* predExp = static_cast<const PredicateExpression*>(exp);
auto ret = checkExp(predExp->collection(), returned, filtered, updated, allowNoexistentProp);
Expand Down Expand Up @@ -601,7 +605,6 @@ nebula::cpp2::ErrorCode QueryBaseProcessor<REQ, RESP>::checkExp(
}
case Expression::Kind::kInputProperty:
case Expression::Kind::kSubscript:
case Expression::Kind::kAttribute:
case Expression::Kind::kLabelTagProperty:
case Expression::Kind::kLabelAttribute:
case Expression::Kind::kVertex:
Expand Down
59 changes: 59 additions & 0 deletions tests/tck/features/yield/parameter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,62 @@ Feature: Parameter
| v |
| BAD_TYPE |
| BAD_TYPE |
Scenario: [param-test-013] DML
Given an empty graph
And load "nba" csv data to a new space
When executing query:
"""
insert vertex player(name, age) values "1":($p6.c, $p1+40)
"""
Then the execution should be successful
When executing query:
"""
insert vertex player(age, name) values "1":($p6.c, $p1+40)
"""
Then a ExecutionError should be raised at runtime: Storage Error: The data type does not meet the requirements. Use the correct type of data.
When executing query:
"""
insert edge like(likeness) values "1"->"2":($p1+40)
"""
Then the execution should be successful
When executing query:
"""
insert edge like(likeness) values "1"->"2":($p6.c)
"""
Then a ExecutionError should be raised at runtime: Storage Error: The data type does not meet the requirements. Use the correct type of data.
When executing query:
"""
update vertex on player "1" set age=age+$p1 when age>$p1
"""
Then the execution should be successful
When executing query:
"""
update vertex on player "1" set age=age+$p6.c when age>$p1
"""
Then a ExecutionError should be raised at runtime: Storage Error: Invalid data, may be wrong value type.
When executing query:
"""
update edge on like "1"->"2" set likeness=likeness+$p1
"""
Then the execution should be successful
When executing query:
"""
update edge on like "1"->"2" set likeness=likeness+$p6.c when likeness>300
"""
Then the execution should be successful
When executing query:
"""
update edge on like "1"->"2" set likeness=likeness+$p6.c when likeness<300
"""
Then a ExecutionError should be raised at runtime: Storage Error: Invalid data, may be wrong value type.
When executing query:
"""
update edge on like "1"->"2" set likeness=likeness+$p6.c when likeness>$p1
"""
Then a ExecutionError should be raised at runtime: Storage Error: Invalid data, may be wrong value type.
When executing query:
"""
update edge on like "1"->"2" set likeness=likeness+$p6.a when likeness>$p1
"""
Then the execution should be successful

0 comments on commit a6d31b3

Please sign in to comment.