You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/06/07 19:52:17 UTC

[GitHub] [arrow] bkietz commented on a change in pull request #10472: ARROW-12975: [C++][Python] if_else kernel doesn't support upcasting

bkietz commented on a change in pull request #10472:
URL: https://github.com/apache/arrow/pull/10472#discussion_r646894778



##########
File path: cpp/src/arrow/compute/kernels/scalar_if_else.cc
##########
@@ -543,7 +543,37 @@ struct ResolveIfElseExec {
   }
 };
 
-void AddPrimitiveIfElseKernels(const std::shared_ptr<ScalarFunction>& scalar_function,
+struct IfElseFunction : ScalarFunction {
+  using ScalarFunction::ScalarFunction;
+
+  Result<const Kernel*> DispatchBest(std::vector<ValueDescr>* values) const override {
+    RETURN_NOT_OK(CheckArity(*values));
+
+    // if-else 0'th descriptor is bool
+    std::vector<ValueDescr> left_right{(*values)[1], (*values)[2]};
+
+    using arrow::compute::detail::DispatchExactImpl;
+    if (auto kernel = DispatchExactImpl(this, *values)) return kernel;
+
+    //    internal::EnsureDictionaryDecoded(values);
+
+    if (values->size() == 3) {
+      internal::ReplaceNullWithOtherType(&left_right);
+
+      if (auto type = internal::CommonNumeric(left_right)) {
+        internal::ReplaceTypes(type, &left_right);
+      }
+    }
+
+    if (auto kernel =
+            DispatchExactImpl(this, {(*values)[0], left_right[0], left_right[1]})) {
+      return kernel;
+    }

Review comment:
       ```suggestion
       using arrow::compute::detail::DispatchExactImpl;
       if (auto kernel = DispatchExactImpl(this, *values)) return kernel;
   
       internal::EnsureDictionaryDecoded(values);
   
       // condition argument must be bool
       auto cond_shape = values->at(0).shape();
       values->pop_front();
   
       internal::ReplaceNullWithOtherType(values);
       if (auto type = internal::CommonNumeric(*values)) {
         internal::ReplaceTypes(type, values);
       }
       values->push_front(ValueDescr{boolean(), cond_shape});
   
       if (auto kernel = DispatchExactImpl(this, *values)) {
         return kernel;
       }
   ```




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

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