jyf111 commented on code in PR #1874:
URL: https://github.com/apache/kvrocks/pull/1874#discussion_r1382384651


##########
src/types/json.h:
##########
@@ -215,6 +215,32 @@ struct JsonValue {
     return Status::OK();
   }
 
+  StatusOr<std::vector<std::optional<JsonValue>>> ArrPop(std::string_view 
path, int64_t index = -1) {
+    std::vector<std::optional<JsonValue>> popped_values;
+
+    try {
+      jsoncons::jsonpath::json_replace(value, path,
+                                       [&popped_values, index](const 
std::string & /*path*/, jsoncons::json &val) {
+                                         if (val.is_array() && !val.empty()) {
+                                           auto popped_iter = 
val.array_range().begin();
+                                           if (index == -1 || index >= 
static_cast<int64_t>(val.size())) {
+                                             popped_iter = 
val.array_range().end() - 1;
+                                           } else if (index > 0) {
+                                             popped_iter += index;
+                                           }

Review Comment:
   I'm sorry I misunderstood `Out-of-range indexes round to their respective 
array ends` stated in the doc.
   
   I've fixed it based on the below code in RedisJson.
   
   ```rust
   impl ArrayIndex for i64 {
       fn normalize(self, len: i64) -> usize {
           let index = if self < 0 {
               len - len.min(-self)
           } else if len > 0 {
               (len - 1).min(self)
           } else {
               0
           };
           index as usize
       }
   }
   ```



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