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



##########
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) {

Review comment:
       - So, this was the basic structure I was thinking of,
   ```cpp
     template <typename KeyType>
     struct MapArrayLookupFunctor {
     .
     .
     .
     const KeyType query_key = UnboxScalar<KeyType>::Unbox(*options.query_key);
     ...
     const std::shared_ptr<Array> keys = struct_array.field(0);
     ...
     
     VisitArrayValuesInline<KeyType>(
       *keys->data(),
       [&](KeyType key) -> Status {
         if (key == query_key) {
           if (occurrence == FIRST) {
             ...
             return Status::Cancelled("Found key");
           } else /*occurrence == ALL*/ { 
               ...
               return Status::OK(); 
           }
         } else { return Status::OK(); }
        },
       [&]() -> Status {
         ...
         return Status::OK();
       }
     );
     ``` 
   - But as the values are visited _inline_, how would we deal with the `LAST` 
option (iterating from the back)?
   - And just so I'm clear, when you say templating the kernel, you mean 
templating for the `KeyType`, right?
   




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