You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "PragmaTwice (via GitHub)" <gi...@apache.org> on 2024/03/18 09:51:54 UTC

[PR] Support value setting for nonexistant paths in JSON.SET [kvrocks]

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

   Close #2176 .
   
   Note:
   
   This is a temporary fix. It only supports simple nonexistant paths (so-called normalized paths in jsoncons).
   
   For a perfect fix, we are contacting jsoncons maintainers here: https://github.com/danielaparker/jsoncons/issues/496.


-- 
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 value setting for nonexistent paths in JSON.SET [kvrocks]

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


##########
src/types/json.h:
##########
@@ -151,11 +151,34 @@ struct JsonValue {
 
   Status Set(std::string_view path, JsonValue &&new_value) {
     try {
-      jsoncons::jsonpath::json_replace(value, path, [&new_value](const std::string & /*path*/, jsoncons::json &origin) {
-        origin = new_value.value;
-      });
+      bool is_set = false;
+      jsoncons::jsonpath::json_replace(value, path,
+                                       [&new_value, &is_set](const std::string & /*path*/, jsoncons::json &origin) {
+                                         origin = new_value.value;
+                                         is_set = true;
+                                       });
+
+      if (!is_set) {
+        // NOTE: this is a workaround since jsonpath doesn't support replace for nonexistent paths in jsoncons
+        // and in this workaround we can only accept normalized path
+        // refer to https://github.com/danielaparker/jsoncons/issues/496
+        jsoncons::jsonpath::json_location location = jsoncons::jsonpath::json_location::parse(path);

Review Comment:
   Because only jsonpointer supports adding value in a nonexistent location.



-- 
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 value setting for nonexistent paths in JSON.SET [kvrocks]

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

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=2178) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=2178&resolved=false&inNewCodePeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=2178&metric=new_accepted_issues&view=list)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=2178&resolved=false&inNewCodePeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [61.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=2178&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [2.1% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=2178&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=2178)
   
   


-- 
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 value setting for nonexistent paths in JSON.SET [kvrocks]

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


##########
src/types/json.h:
##########
@@ -151,11 +151,34 @@ struct JsonValue {
 
   Status Set(std::string_view path, JsonValue &&new_value) {
     try {
-      jsoncons::jsonpath::json_replace(value, path, [&new_value](const std::string & /*path*/, jsoncons::json &origin) {
-        origin = new_value.value;
-      });
+      bool is_set = false;
+      jsoncons::jsonpath::json_replace(value, path,
+                                       [&new_value, &is_set](const std::string & /*path*/, jsoncons::json &origin) {
+                                         origin = new_value.value;
+                                         is_set = true;
+                                       });
+
+      if (!is_set) {
+        // NOTE: this is a workaround since jsonpath doesn't support replace for nonexistent paths in jsoncons
+        // and in this workaround we can only accept normalized path
+        // refer to https://github.com/danielaparker/jsoncons/issues/496
+        jsoncons::jsonpath::json_location location = jsoncons::jsonpath::json_location::parse(path);

Review Comment:
   oh got it, nice patch



-- 
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 value setting for nonexistent paths in JSON.SET [kvrocks]

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


-- 
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 value setting for nonexistent paths in JSON.SET [kvrocks]

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


##########
src/types/json.h:
##########
@@ -151,11 +151,34 @@ struct JsonValue {
 
   Status Set(std::string_view path, JsonValue &&new_value) {
     try {
-      jsoncons::jsonpath::json_replace(value, path, [&new_value](const std::string & /*path*/, jsoncons::json &origin) {
-        origin = new_value.value;
-      });
+      bool is_set = false;
+      jsoncons::jsonpath::json_replace(value, path,
+                                       [&new_value, &is_set](const std::string & /*path*/, jsoncons::json &origin) {
+                                         origin = new_value.value;
+                                         is_set = true;
+                                       });
+
+      if (!is_set) {
+        // NOTE: this is a workaround since jsonpath doesn't support replace for nonexistent paths in jsoncons
+        // and in this workaround we can only accept normalized path
+        // refer to https://github.com/danielaparker/jsoncons/issues/496
+        jsoncons::jsonpath::json_location location = jsoncons::jsonpath::json_location::parse(path);

Review Comment:
   why we mixing json pointer and jsonpath 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