You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "skyitachi (via GitHub)" <gi...@apache.org> on 2023/11/10 14:09:45 UTC

[PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

skyitachi opened a new pull request, #1890:
URL: https://github.com/apache/kvrocks/pull/1890

   #1818 #1819 


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#discussion_r1390978603


##########
src/types/json.h:
##########
@@ -446,6 +451,54 @@ struct JsonValue {
     return Status::OK();
   }
 
+  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());

Review Comment:
   IMHO I cannot understand the meaning of `NumOpIncrBy` and `NumOpMulBy`. Could you just use `+` and `*` here?



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#discussion_r1398991434


##########
src/types/json.h:
##########
@@ -39,6 +39,11 @@
 constexpr ssize_t NOT_FOUND_INDEX = -1;
 constexpr ssize_t NOT_ARRAY = -2;
 
+enum class NumOpEnum : uint8_t {
+  Incr = 1,
+  Mul = 2,
+};

Review Comment:
   I think it'd be better to put this enum inside JsonValue to avoid name conflict.



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1824090804

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1890)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [2 Code Smells](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL)
   
   [![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890) No Coverage information  
   [![3.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/5-16px.png '3.6%')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list) [3.6% Duplication](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on code in PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#discussion_r1389597563


##########
src/commands/cmd_json.cc:
##########
@@ -378,6 +420,8 @@ REDIS_REGISTER_COMMANDS(MakeCmdAttr<CommandJsonSet>("json.set", 4, "write", 1, 1
                         MakeCmdAttr<CommandJsonArrLen>("json.arrlen", -2, "read-only", 1, 1, 1),
                         MakeCmdAttr<CommandJsonObjkeys>("json.objkeys", -2, "read-only", 1, 1, 1),
                         MakeCmdAttr<CommandJsonArrPop>("json.arrpop", -2, "write", 1, 1, 1),
-                        MakeCmdAttr<CommanderJsonArrIndex>("json.arrindex", -4, "read-only", 1, 1, 1), );
+                        MakeCmdAttr<CommanderJsonArrIndex>("json.arrindex", -4, "read-only", 1, 1, 1),
+                        MakeCmdAttr<CommandJsonNumIncrBy>("json.numincrby", -4, "write", 1, 1, 1),
+                        MakeCmdAttr<CommandJsonNumMultBy>("json.nummultby", -4, "write", 1, 1, 1), );

Review Comment:
   ```suggestion
                           MakeCmdAttr<CommandJsonNumMultBy>("json.nummultby", 4, "write", 1, 1, 1), );
   ```



##########
src/commands/cmd_json.cc:
##########
@@ -368,6 +368,48 @@ class CommanderJsonArrIndex : public Commander {
   ssize_t end_;
 };
 
+class CommandJsonNumIncrBy : public Commander {
+ public:
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    redis::Json json(svr->storage, conn->GetNamespace());
+
+    if (args_.size() != 4) {
+      return {Status::RedisExecErr, errWrongNumOfArguments};
+    }
+
+    JsonValue result = JsonValue::FromString("[]").GetValue();
+    auto s = json.NumIncrBy(args_[1], args_[2], args_[3], &result);
+    if (!s.ok()) {
+      return {Status::RedisExecErr, s.ToString()};
+    }
+
+    *output = redis::BulkString(result.value.to_string());
+
+    return Status::OK();
+  }
+};
+
+class CommandJsonNumMultBy : public Commander {
+ public:
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    redis::Json json(svr->storage, conn->GetNamespace());
+
+    if (args_.size() != 4) {
+      return {Status::RedisExecErr, errWrongNumOfArguments};
+    }

Review Comment:
   ```suggestion
   ```
   
   Can remove those lines since the command parser has checked this.



##########
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:
   ```suggestion
             if (std::isinf(v)) {
               status = {Status::RedisExecErr, "result is not a number"};
               return;
             }
             
             origin = v;
   ```



##########
src/types/redis_json.cc:
##########
@@ -304,4 +304,38 @@ rocksdb::Status Json::ObjKeys(const std::string &user_key, const std::string &pa
   return rocksdb::Status::OK();
 }
 
+rocksdb::Status Json::NumIncrBy(const std::string &user_key, const std::string &path, const std::string &value,
+                                JsonValue *result) {
+  return numop(NumOpEnum::Incr, user_key, path, value, result);
+}
+
+rocksdb::Status Json::NumMultBy(const std::string &user_key, const std::string &path, const std::string &value,
+                                JsonValue *result) {
+  return numop(NumOpEnum::Mul, user_key, path, value, result);
+}
+
+rocksdb::Status Json::numop(NumOpEnum op, const std::string &user_key, const std::string &path,
+                            const std::string &value, JsonValue *result) {
+  JsonValue number;
+  auto number_res = JsonValue::FromString(value);
+  if (!number_res || !number_res.GetValue().value.is_number()) {
+    return rocksdb::Status::InvalidArgument("should be number");

Review Comment:
   ```suggestion
       return rocksdb::Status::InvalidArgument("should be a number");
   ```



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1817732483

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1890)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [2 Code Smells](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL)
   
   [![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890) No Coverage information  
   [![3.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/5-16px.png '3.6%')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list) [3.6% Duplication](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#discussion_r1390981605


##########
src/types/json.h:
##########
@@ -446,6 +451,54 @@ struct JsonValue {
     return Status::OK();
   }
 
+  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"};

Review Comment:
   I think `inf` actually *is* a number, but `NaN` isn't.



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#discussion_r1403386013


##########
src/types/json.h:
##########
@@ -39,6 +39,11 @@
 constexpr ssize_t NOT_FOUND_INDEX = -1;
 constexpr ssize_t NOT_ARRAY = -2;
 
+enum class NumOpEnum : uint8_t {
+  Incr = 1,
+  Mul = 2,
+};

Review Comment:
   Exactly.



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#discussion_r1395403838


##########
src/types/json.h:
##########
@@ -446,6 +451,54 @@ struct JsonValue {
     return Status::OK();
   }
 
+  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());

Review Comment:
   Exactly.



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1826474691

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1890)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [2 Code Smells](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL)
   
   [![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890) No Coverage information  
   [![3.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/5-16px.png '3.6%')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list) [3.6% Duplication](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk merged PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "skyitachi (via GitHub)" <gi...@apache.org>.
skyitachi commented on code in PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#discussion_r1391896003


##########
src/types/json.h:
##########
@@ -446,6 +451,54 @@ struct JsonValue {
     return Status::OK();
   }
 
+  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());

Review Comment:
   you mean use `v = origin.as_double() + number.value.as_double()` directly?



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1807398816

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1890)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [2 Code Smells](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL)
   
   [![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890) No Coverage information  
   [![3.9%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/5-16px.png '3.9%')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list) [3.9% Duplication](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1807100596

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1890)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [2 Code Smells](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL)
   
   [![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890) No Coverage information  
   [![2.8%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '2.8%')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list) [2.8% Duplication](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1826474518

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1890)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [2 Code Smells](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL)
   
   [![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890) No Coverage information  
   [![3.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/5-16px.png '3.6%')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list) [3.6% Duplication](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1826483638

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1890)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [2 Code Smells](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL)
   
   [![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890) No Coverage information  
   [![3.5%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/5-16px.png '3.5%')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list) [3.5% Duplication](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1806629433

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1890)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [2 Code Smells](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL)
   
   [![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890) No Coverage information  
   [![1.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '1.6%')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list) [1.6% Duplication](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1807135024

   @skyitachi Can you help to resolve conflicts before merging?


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "skyitachi (via GitHub)" <gi...@apache.org>.
skyitachi commented on code in PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#discussion_r1398315514


##########
src/types/json.h:
##########
@@ -446,6 +451,54 @@ struct JsonValue {
     return Status::OK();
   }
 
+  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());

Review Comment:
   fixed



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1827871991

   Could you check the clang-tidy report in CI and try to fix it?


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "skyitachi (via GitHub)" <gi...@apache.org>.
skyitachi commented on code in PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#discussion_r1403141897


##########
src/types/json.h:
##########
@@ -39,6 +39,11 @@
 constexpr ssize_t NOT_FOUND_INDEX = -1;
 constexpr ssize_t NOT_ARRAY = -2;
 
+enum class NumOpEnum : uint8_t {
+  Incr = 1,
+  Mul = 2,
+};

Review Comment:
   is that put the definition in the JsonValue?
   
   ```
   struct JsonValue {
   
     enum class NumOpEnum : uint8_t {
       Incr = 1,
       Mul = 2,
     };
   }
   ```



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1835516203

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1890)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [2 Code Smells](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL)
   
   [![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890) No Coverage information  
   [![3.4%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/5-16px.png '3.4%')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list) [3.4% Duplication](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1805812843

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1890)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [2 Code Smells](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL)
   
   [![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890) No Coverage information  
   [![1.8%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '1.8%')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list) [1.8% Duplication](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1816527279

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1890)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1890&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL) [2 Code Smells](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1890&resolved=false&types=CODE_SMELL)
   
   [![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890) No Coverage information  
   [![3.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/5-16px.png '3.6%')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list) [3.6% Duplication](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1890&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "skyitachi (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.NUMINCRBY and JSON.NUMMULTBY command [kvrocks]

Posted by "skyitachi (via GitHub)" <gi...@apache.org>.
skyitachi commented on PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#issuecomment-1806628672

   > Overall looks good, left some comments.
   > 
   > @skyitachi It's good to add Go tests only if codes can be covered. C++ tests only required when some critical codes cannot be tested by Go tests.
   
   got it


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org