dhruv9vats commented on a change in pull request #12162:
URL: https://github.com/apache/arrow/pull/12162#discussion_r789862690



##########
File path: cpp/src/arrow/compute/kernels/scalar_nested.cc
##########
@@ -429,6 +429,169 @@ const FunctionDoc make_struct_doc{"Wrap Arrays into a 
StructArray",
                                   {"*args"},
                                   "MakeStructOptions"};
 
+struct MapArrayLookupFunctor {
+  static Result<int64_t> FindOneMapValueIndex(const Array& keys, const Scalar& 
query_key,
+                                              const int64_t start, const 
int64_t end,
+                                              const bool from_back = false) {
+    if (!from_back) {
+      for (int64_t idx = start; idx < end; ++idx) {
+        ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Scalar> key, 
keys.GetScalar(idx));
+
+        if (key->Equals(query_key)) return idx;
+      }
+    } else {
+      for (int64_t idx = end - 1; idx >= start; --idx) {
+        ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Scalar> key, 
keys.GetScalar(idx));
+
+        if (key->Equals(query_key)) return idx;
+      }
+    }
+    return -1;
+  }
+
+  static Result<std::shared_ptr<Scalar>> GetScalarOutput(KernelContext* ctx,
+                                                         const MapScalar 
map_scalar) {
+    const auto& options = OptionsWrapper<MapArrayLookupOptions>::Get(ctx);
+    const std::shared_ptr<Scalar>& query_key = options.query_key;
+    const auto& occurrence = options.occurrence;
+
+    const auto& struct_array = checked_cast<const 
StructArray&>(*map_scalar.value);
+    const std::shared_ptr<Array> keys = struct_array.field(0);
+    const std::shared_ptr<Array> items = struct_array.field(1);

Review comment:
       Note how we no longer have to deal with `offsets()` as before. This does 
seem to return only the required parts of the `Array`, which I now recall you 
initially pointed out in the JIRA. But does this incur some performance penalty?
   What would be the correct way to do this? 




-- 
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: github-unsubscr...@arrow.apache.org

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


Reply via email to