arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject [arrow] branch master updated: ARROW-1838: [C++] Conform kernel API to use Datum for input and output
Date Tue, 21 Nov 2017 14:57:39 GMT
This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new c436376  ARROW-1838: [C++] Conform kernel API to use Datum for input and output
c436376 is described below

commit c436376b0ab880202c4e2f2735aff74b4667d98b
Author: Wes McKinney <wes.mckinney@twosigma.com>
AuthorDate: Tue Nov 21 09:57:36 2017 -0500

    ARROW-1838: [C++] Conform kernel API to use Datum for input and output
    
    We could also add helper methods that do automatic boxing into a `Datum` at a later time
if it helps with code complexity.
    
    Author: Wes McKinney <wes.mckinney@twosigma.com>
    
    Closes #1339 from wesm/ARROW-1838 and squashes the following commits:
    
    f83a866e [Wes McKinney] Conform kernel API to use Datum for input and output
---
 cpp/src/arrow/compute/compute-test.cc          |  2 +-
 cpp/src/arrow/compute/kernel.h                 |  2 +-
 cpp/src/arrow/compute/kernels/cast.cc          | 11 +++++++----
 cpp/src/arrow/compute/kernels/hash.cc          |  5 +++--
 cpp/src/arrow/compute/kernels/util-internal.cc |  4 ++--
 5 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/cpp/src/arrow/compute/compute-test.cc b/cpp/src/arrow/compute/compute-test.cc
index 58a991c..fa408ae 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 0037245..7ff506c 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 c866054..d595d2e 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 3af4160..95f0399 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 df68637..28428bf 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 {

-- 
To stop receiving notification emails like this one, please contact
['"commits@arrow.apache.org" <commits@arrow.apache.org>'].

Mime
View raw message