git-hulk commented on code in PR #1852:
URL: https://github.com/apache/kvrocks/pull/1852#discussion_r1374412975


##########
src/types/json.h:
##########
@@ -215,6 +218,80 @@ struct JsonValue {
     return Status::OK();
   }
 
+  StatusOr<bool> Merge(const std::string_view path, const std::string 
&merge_value) {
+    bool is_updated = false;
+    const std::string json_root_path = "$";
+    try {
+      jsoncons::json patch_value = jsoncons::json::parse(merge_value);
+      bool not_exists = jsoncons::jsonpath::json_query(value, path).empty();
+
+      if (path == json_root_path || not_exists) {

Review Comment:
   I guess the meaning of `non-existing keys the path must be $` is when the 
key is NOT found instead of path. That said:
   
   ```
   // Bad
   $ JSON.MERGE no_exists_key $.a '{}'
   // Good, will create key `no_exists_key`
   $ JSON.MERGE no_exists_key $ '{}'
   // Good if the object path is missing
   $ JSON.MERGE exists_key $.a '1'
   
   ```



##########
src/types/json.h:
##########
@@ -224,4 +301,4 @@ struct JsonValue {
   ~JsonValue() = default;
 
   jsoncons::json value;
-};
+};

Review Comment:
   ```suggestion
   };
   
   ```



-- 
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]

Reply via email to