skyitachi commented on code in PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#discussion_r1390088211
##########
src/types/json.h:
##########
@@ -363,6 +368,55 @@ struct JsonValue {
return popped_values;
}
+ template <typename T>
+ static inline T NumOpIncrBy(T origin, T value) {
+ return origin + value;
+ }
+
+ template <typename T>
+ static inline T NumOpMulBy(T origin, T value) {
+ return origin * value;
+ }
+
+ Status NumOp(std::string_view path, const JsonValue &number, NumOpEnum op,
JsonValue *result) {
+ Status status = Status::OK();
+ try {
+ jsoncons::jsonpath::json_replace(value, path, [&](const std::string &
/*path*/, jsoncons::json &origin) {
+ if (!status.IsOK()) {
+ return;
+ }
+ if (!origin.is_number()) {
+ result->value.push_back(jsoncons::json::null());
+ return;
+ }
+ if (number.value.is_double() || origin.is_double()) {
+ double v = 0;
+ if (op == NumOpEnum::Incr) {
+ v = NumOpIncrBy<double>(origin.as_double(),
number.value.as_double());
+ } else if (op == NumOpEnum::Mul) {
+ v = NumOpMulBy<double>(origin.as_double(),
number.value.as_double());
+ }
+ if (std::isinf(v)) {
+ status = {Status::RedisExecErr, "result is not number"};
+ return;
+ } else {
+ origin = v;
+ }
Review Comment:
fix it, please check it later
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]