[ 
https://issues.apache.org/jira/browse/ARROW-1838?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16260851#comment-16260851
 ] 

ASF GitHub Bot commented on ARROW-1838:
---------------------------------------

wesm closed pull request #1339: ARROW-1838: [C++] Conform kernel API to use 
Datum for input and output
URL: https://github.com/apache/arrow/pull/1339
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/cpp/src/arrow/compute/compute-test.cc 
b/cpp/src/arrow/compute/compute-test.cc
index 58a991c60..fa408ae40 100644
--- a/cpp/src/arrow/compute/compute-test.cc
+++ b/cpp/src/arrow/compute/compute-test.cc
@@ -697,7 +697,7 @@ TEST_F(TestCast, PreallocatedMemory) {
   out_data->buffers.push_back(out_values);
 
   Datum out(out_data);
-  ASSERT_OK(kernel->Call(&this->ctx_, *arr->data(), &out));
+  ASSERT_OK(kernel->Call(&this->ctx_, Datum(arr), &out));
 
   // Buffer address unchanged
   ASSERT_EQ(out_values.get(), out_data->buffers[1].get());
diff --git a/cpp/src/arrow/compute/kernel.h b/cpp/src/arrow/compute/kernel.h
index 0037245d6..7ff506ca0 100644
--- a/cpp/src/arrow/compute/kernel.h
+++ b/cpp/src/arrow/compute/kernel.h
@@ -131,7 +131,7 @@ struct ARROW_EXPORT Datum {
 /// \brief An array-valued function of a single input argument
 class ARROW_EXPORT UnaryKernel : public OpKernel {
  public:
-  virtual Status Call(FunctionContext* ctx, const ArrayData& input, Datum* 
out) = 0;
+  virtual Status Call(FunctionContext* ctx, const Datum& input, Datum* out) = 
0;
 };
 
 }  // namespace compute
diff --git a/cpp/src/arrow/compute/kernels/cast.cc 
b/cpp/src/arrow/compute/kernels/cast.cc
index c866054ea..d595d2ea5 100644
--- a/cpp/src/arrow/compute/kernels/cast.cc
+++ b/cpp/src/arrow/compute/kernels/cast.cc
@@ -740,20 +740,23 @@ class CastKernel : public UnaryKernel {
         can_pre_allocate_values_(can_pre_allocate_values),
         out_type_(out_type) {}
 
-  Status Call(FunctionContext* ctx, const ArrayData& input, Datum* out) 
override {
+  Status Call(FunctionContext* ctx, const Datum& input, Datum* out) override {
+    DCHECK_EQ(Datum::ARRAY, input.kind());
+
+    const ArrayData& in_data = *input.array();
     ArrayData* result;
 
     if (out->kind() == Datum::NONE) {
-      out->value = std::make_shared<ArrayData>(out_type_, input.length);
+      out->value = std::make_shared<ArrayData>(out_type_, in_data.length);
     }
 
     result = out->array().get();
 
     if (!is_zero_copy_) {
       RETURN_NOT_OK(
-          AllocateIfNotPreallocated(ctx, input, can_pre_allocate_values_, 
result));
+          AllocateIfNotPreallocated(ctx, in_data, can_pre_allocate_values_, 
result));
     }
-    func_(ctx, options_, input, result);
+    func_(ctx, options_, in_data, result);
 
     RETURN_IF_ERROR(ctx);
     return Status::OK();
diff --git a/cpp/src/arrow/compute/kernels/hash.cc 
b/cpp/src/arrow/compute/kernels/hash.cc
index 3af41609f..95f039932 100644
--- a/cpp/src/arrow/compute/kernels/hash.cc
+++ b/cpp/src/arrow/compute/kernels/hash.cc
@@ -658,8 +658,9 @@ class HashKernelImpl : public HashKernel {
   explicit HashKernelImpl(std::unique_ptr<HashTable> hasher)
       : hasher_(std::move(hasher)) {}
 
-  Status Call(FunctionContext* ctx, const ArrayData& input, Datum* out) 
override {
-    RETURN_NOT_OK(Append(ctx, input));
+  Status Call(FunctionContext* ctx, const Datum& input, Datum* out) override {
+    DCHECK_EQ(Datum::ARRAY, input.kind());
+    RETURN_NOT_OK(Append(ctx, *input.array()));
     return Flush(out);
   }
 
diff --git a/cpp/src/arrow/compute/kernels/util-internal.cc 
b/cpp/src/arrow/compute/kernels/util-internal.cc
index df68637e0..28428bfcb 100644
--- a/cpp/src/arrow/compute/kernels/util-internal.cc
+++ b/cpp/src/arrow/compute/kernels/util-internal.cc
@@ -34,13 +34,13 @@ Status InvokeUnaryArrayKernel(FunctionContext* ctx, 
UnaryKernel* kernel,
                               const Datum& value, std::vector<Datum>* outputs) 
{
   if (value.kind() == Datum::ARRAY) {
     Datum output;
-    RETURN_NOT_OK(kernel->Call(ctx, *value.array(), &output));
+    RETURN_NOT_OK(kernel->Call(ctx, value, &output));
     outputs->push_back(output);
   } else if (value.kind() == Datum::CHUNKED_ARRAY) {
     const ChunkedArray& array = *value.chunked_array();
     for (int i = 0; i < array.num_chunks(); i++) {
       Datum output;
-      RETURN_NOT_OK(kernel->Call(ctx, *(array.chunk(i)->data()), &output));
+      RETURN_NOT_OK(kernel->Call(ctx, Datum(array.chunk(i)), &output));
       outputs->push_back(output);
     }
   } else {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> [C++] Use compute::Datum uniformly for input argument to kernels
> ----------------------------------------------------------------
>
>                 Key: ARROW-1838
>                 URL: https://issues.apache.org/jira/browse/ARROW-1838
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: C++
>            Reporter: Wes McKinney
>            Assignee: Wes McKinney
>              Labels: pull-request-available
>             Fix For: 0.8.0
>
>
> This is some API tidying after ARROW-1559. Some kernel APIs are still using 
> {{ArrayData}} for the input argument



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to