PragmaTwice commented on code in PR #1865:
URL: https://github.com/apache/kvrocks/pull/1865#discussion_r1379797021


##########
src/types/json.h:
##########
@@ -134,6 +134,34 @@ struct JsonValue {
     return result_count;
   }
 
+  StatusOr<std::vector<ssize_t>> ArrIndex(std::string_view path, const 
jsoncons::json &needle, int start,
+                                          int end) const {
+    std::vector<ssize_t> result;
+    try {
+      jsoncons::jsonpath::json_query(value, path, [&](const std::string & 
/*path*/, const jsoncons::json &val) {
+        if (!val.is_array()) {
+          result.emplace_back(-2);
+          return;
+        }
+        int pstart = std::max<int>(start, 0);
+        int pend = std::max(std::min(static_cast<int>(val.size()), end), 0);
+        auto arr_begin = val.array_range().begin();
+        auto begin_it = arr_begin + pstart;
+
+        auto end_it = arr_begin + pend;
+        auto it = std::find(begin_it, end_it, needle);
+        if (it != end_it) {
+          result.emplace_back(it - arr_begin);
+          return;
+        }

Review Comment:
   > Negative values are interpreted as starting from the end.
   
   From the document, I think we need to calculate the real pos while `end` is 
negative.



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