Skip to content

Commit

Permalink
[cypher] fix parameter error in cypher plugin call (TuGraph-family#436)
Browse files Browse the repository at this point in the history
* fix parameter error in cypher plugin call

* fix blank line

* add ut

* revert lgraph_standalone.json

* remove repeated test
  • Loading branch information
ljcui authored Mar 15, 2024
1 parent d1220bc commit 1718461
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/lgraph/lgraph_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ X(ParserException, "Parser exception.") \
X(EvaluationException, "Evaluation exception.") \
X(TxnCommitException, "Txn commit exception.") \
X(ReminderException, "Reminder exception.") \
X(GraphCreateException, "Graph create exception.")

X(GraphCreateException, "Graph create exception.") \
X(CypherParameterTypeError, "Cypher parameter type error.")

enum class ErrorCode {
#define X(code, msg) code,
Expand Down
28 changes: 28 additions & 0 deletions src/cypher/execution_plan/ops/op_standalone_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,34 @@ cypher::OpBase::OpResult cypher::StandaloneCall::RealConsume(RTContext *ctx) {
std::vector<std::string> _yield_items;
std::transform(yield_items.cbegin(), yield_items.cend(), std::back_inserter(_yield_items),
[](const auto &item) { return item.first; });
for (auto& p : parameters) {
if (p.type == parser::Expression::DataType::PARAMETER) {
auto it = ctx->param_tab_.find(p.String());
if (it == ctx->param_tab_.end())
throw lgraph::CypherException("invalid parameter: " + p.String());
if (it->second.type != cypher::FieldData::SCALAR) {
throw lgraph::CypherException("parameter with wrong type: " + p.String());
}
if (it->second.scalar.IsInt64()) {
p.type = parser::Expression::DataType::INT;
p.data = it->second.scalar.AsInt64();
} else if (it->second.scalar.IsString()) {
p.type = parser::Expression::DataType::STRING;
p.data = std::make_shared<std::string>(it->second.scalar.AsString());
} else if (it->second.scalar.IsBool()) {
p.type = parser::Expression::DataType::BOOL;
p.data = it->second.scalar.AsBool();
} else if (it->second.scalar.IsDouble()) {
p.type = parser::Expression::DataType::DOUBLE;
p.data = it->second.scalar.AsDouble();
} else {
THROW_CODE(
CypherParameterTypeError,
"Call procedure, unexpected parameter type, parameter: {}, type: {}",
it->first, it->second.scalar.GetType());
}
}
}
procedure_->function(ctx, nullptr, parameters, _yield_items, &records);
auto &header = ctx->result_->Header();
for (auto &r : records) {
Expand Down
2 changes: 2 additions & 0 deletions test/test_cypher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ using namespace antlr4;

static const cypher::PARAM_TAB g_param_tab = {
{"$name", cypher::FieldData(lgraph::FieldData("Lindsay Lohan"))},
{"$plugin_type", cypher::FieldData(lgraph::FieldData("CPP"))},
{"$new_name", cypher::FieldData(lgraph::FieldData("new name"))},
{"$personId", cypher::FieldData(lgraph::FieldData(1))},
{"$personIds", cypher::FieldData(std::vector<lgraph::FieldData>{
Expand Down Expand Up @@ -505,6 +506,7 @@ int test_parameter(cypher::RTContext *ctx) {
{"MATCH (n:Person {name:$name}) RETURN n", 1},
{"CREATE (n:Person {name:$new_name}) RETURN n", 1},
{"MATCH (n:Person {name:$new_name}) DELETE n", 1},
{"CALL db.plugin.listPlugin($plugin_type, 'any')", 0}
};
std::vector<std::string> scripts;
std::vector<int> check;
Expand Down

0 comments on commit 1718461

Please sign in to comment.