This is an automated email from the ASF dual-hosted git repository.

kou 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 2bdf203  ARROW-9341: [GLib] Use arrow::Datum version Take()
2bdf203 is described below

commit 2bdf20393c429772bb2f642bc20e2ff3121930c7
Author: Sutou Kouhei <[email protected]>
AuthorDate: Wed Jul 8 05:19:45 2020 +0900

    ARROW-9341: [GLib] Use arrow::Datum version Take()
    
    Closes #7652 from kou/glib-take
    
    Authored-by: Sutou Kouhei <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 c_glib/arrow-glib/compute.cpp             | 220 +++++++++++++-----------------
 c_glib/parquet-glib/arrow-file-reader.cpp |   4 -
 cpp/src/arrow/compute/api_vector.h        |   9 +-
 3 files changed, 102 insertions(+), 131 deletions(-)

diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp
index 9069465..d8d0bdc 100644
--- a/c_glib/arrow-glib/compute.cpp
+++ b/c_glib/arrow-glib/compute.cpp
@@ -77,6 +77,32 @@ garrow_numeric_array_compare(GArrowArrayType array,
   }
 }
 
+template <typename GArrowTypeNewRaw>
+auto
+garrow_take(arrow::Datum arrow_values,
+            arrow::Datum arrow_indices,
+            GArrowTakeOptions *options,
+            GArrowTypeNewRaw garrow_type_new_raw,
+            GError **error,
+            const gchar *tag) -> decltype(garrow_type_new_raw(arrow::Datum()))
+{
+  arrow::Result<arrow::Datum> arrow_taken_datum;
+  if (options) {
+    auto arrow_options = garrow_take_options_get_raw(options);
+    arrow_taken_datum = arrow::compute::Take(arrow_values,
+                                             arrow_indices,
+                                             *arrow_options);
+  } else {
+    arrow_taken_datum = arrow::compute::Take(arrow_values,
+                                             arrow_indices);
+  }
+  if (garrow::check(error, arrow_taken_datum, tag)) {
+    return garrow_type_new_raw(*arrow_taken_datum);
+  } else {
+    return NULL;
+  }
+}
+
 G_BEGIN_DECLS
 
 /**
@@ -1585,24 +1611,17 @@ garrow_array_take(GArrowArray *array,
                   GError **error)
 {
   auto arrow_array = garrow_array_get_raw(array);
-  auto arrow_array_raw = arrow_array.get();
   auto arrow_indices = garrow_array_get_raw(indices);
-  auto arrow_indices_raw = arrow_indices.get();
-  arrow::Result<std::shared_ptr<arrow::Array>> arrow_taken_array;
-  if (options) {
-    auto arrow_options = garrow_take_options_get_raw(options);
-    arrow_taken_array = arrow::compute::Take(*arrow_array_raw,
-                                             *arrow_indices_raw,
-                                             *arrow_options);
-  } else {
-    arrow_taken_array = arrow::compute::Take(*arrow_array_raw,
-                                             *arrow_indices_raw);
-  }
-  if (garrow::check(error, arrow_taken_array, "[array][take]")) {
-    return garrow_array_new_raw(&(*arrow_taken_array));
-  } else {
-    return NULL;
-  }
+  return garrow_take(
+    arrow::Datum(arrow_array),
+    arrow::Datum(arrow_indices),
+    options,
+    [](arrow::Datum arrow_datum) {
+      auto arrow_taken_array = arrow_datum.make_array();
+      return garrow_array_new_raw(&arrow_taken_array);
+    },
+    error,
+    "[array][take][array]");
 }
 
 /**
@@ -1624,26 +1643,17 @@ garrow_array_take_chunked_array(GArrowArray *array,
                                 GError **error)
 {
   auto arrow_array = garrow_array_get_raw(array);
-  auto arrow_array_raw = arrow_array.get();
   auto arrow_indices = garrow_chunked_array_get_raw(indices);
-  auto arrow_indices_raw = arrow_indices.get();
-  arrow::Result<std::shared_ptr<arrow::ChunkedArray>> 
arrow_taken_chunked_array;
-  if (options) {
-    auto arrow_options = garrow_take_options_get_raw(options);
-    arrow_taken_chunked_array = arrow::compute::Take(*arrow_array_raw,
-                                                     *arrow_indices_raw,
-                                                     *arrow_options);
-  } else {
-    arrow_taken_chunked_array = arrow::compute::Take(*arrow_array_raw,
-                                                     *arrow_indices_raw);
-  }
-  if (garrow::check(error,
-                    arrow_taken_chunked_array,
-                    "[array][take][chunked-array]")) {
-    return garrow_chunked_array_new_raw(&(*arrow_taken_chunked_array));
-  } else {
-    return NULL;
-  }
+  return garrow_take(
+    arrow::Datum(arrow_array),
+    arrow::Datum(arrow_indices),
+    options,
+    [](arrow::Datum arrow_datum) {
+      auto arrow_taken_chunked_array = arrow_datum.chunked_array();
+      return garrow_chunked_array_new_raw(&arrow_taken_chunked_array);
+    },
+    error,
+    "[array][take][chunked-array]");
 }
 
 /**
@@ -1665,24 +1675,17 @@ garrow_table_take(GArrowTable *table,
                   GError **error)
 {
   auto arrow_table = garrow_table_get_raw(table);
-  auto arrow_table_raw = arrow_table.get();
   auto arrow_indices = garrow_array_get_raw(indices);
-  auto arrow_indices_raw = arrow_indices.get();
-  arrow::Result<std::shared_ptr<arrow::Table>> arrow_taken_table;
-  if (options) {
-    auto arrow_options = garrow_take_options_get_raw(options);
-    arrow_taken_table = arrow::compute::Take(*arrow_table_raw,
-                                             *arrow_indices_raw,
-                                             *arrow_options);
-  } else {
-    arrow_taken_table = arrow::compute::Take(*arrow_table_raw,
-                                             *arrow_indices_raw);
-  }
-  if (garrow::check(error, arrow_taken_table, "[table][take]")) {
-    return garrow_table_new_raw(&(*arrow_taken_table));
-  } else {
-    return NULL;
-  }
+  return garrow_take(
+    arrow::Datum(arrow_table),
+    arrow::Datum(arrow_indices),
+    options,
+    [](arrow::Datum arrow_datum) {
+      auto arrow_taken_table = arrow_datum.table();
+      return garrow_table_new_raw(&arrow_taken_table);
+    },
+    error,
+    "[table][take]");
 }
 
 /**
@@ -1704,24 +1707,17 @@ garrow_table_take_chunked_array(GArrowTable *table,
                                 GError **error)
 {
   auto arrow_table = garrow_table_get_raw(table);
-  auto arrow_table_raw = arrow_table.get();
   auto arrow_indices = garrow_chunked_array_get_raw(indices);
-  auto arrow_indices_raw = arrow_indices.get();
-  arrow::Result<std::shared_ptr<arrow::Table>> arrow_taken_table;
-  if (options) {
-    auto arrow_options = garrow_take_options_get_raw(options);
-    arrow_taken_table = arrow::compute::Take(*arrow_table_raw,
-                                             *arrow_indices_raw,
-                                             *arrow_options);
-  } else {
-    arrow_taken_table = arrow::compute::Take(*arrow_table_raw,
-                                             *arrow_indices_raw);
-  }
-  if (garrow::check(error, arrow_taken_table, "[table][take][chunked-array]")) 
{
-    return garrow_table_new_raw(&(*arrow_taken_table));
-  } else {
-    return NULL;
-  }
+  return garrow_take(
+    arrow::Datum(arrow_table),
+    arrow::Datum(arrow_indices),
+    options,
+    [](arrow::Datum arrow_datum) {
+      auto arrow_taken_table = arrow_datum.table();
+      return garrow_table_new_raw(&arrow_taken_table);
+    },
+    error,
+    "[table][take][chunked-array]");
 }
 
 /**
@@ -1743,24 +1739,17 @@ garrow_chunked_array_take(GArrowChunkedArray 
*chunked_array,
                           GError **error)
 {
   auto arrow_chunked_array = garrow_chunked_array_get_raw(chunked_array);
-  auto arrow_chunked_array_raw = arrow_chunked_array.get();
   auto arrow_indices = garrow_array_get_raw(indices);
-  auto arrow_indices_raw = arrow_indices.get();
-  arrow::Result<std::shared_ptr<arrow::ChunkedArray>> 
arrow_taken_chunked_array;
-  if (options) {
-    auto arrow_options = garrow_take_options_get_raw(options);
-    arrow_taken_chunked_array = arrow::compute::Take(*arrow_chunked_array_raw,
-                                                     *arrow_indices_raw,
-                                                     *arrow_options);
-  } else {
-    arrow_taken_chunked_array = arrow::compute::Take(*arrow_chunked_array_raw,
-                                                     *arrow_indices_raw);
-  }
-  if (garrow::check(error, arrow_taken_chunked_array, 
"[chunked-array][take]")) {
-    return garrow_chunked_array_new_raw(&(*arrow_taken_chunked_array));
-  } else {
-    return NULL;
-  }
+  return garrow_take(
+    arrow::Datum(arrow_chunked_array),
+    arrow::Datum(arrow_indices),
+    options,
+    [](arrow::Datum arrow_datum) {
+      auto arrow_taken_chunked_array = arrow_datum.chunked_array();
+      return garrow_chunked_array_new_raw(&arrow_taken_chunked_array);
+    },
+    error,
+    "[chunked-array][take]");
 }
 
 /**
@@ -1782,26 +1771,17 @@ 
garrow_chunked_array_take_chunked_array(GArrowChunkedArray *chunked_array,
                                         GError **error)
 {
   auto arrow_chunked_array = garrow_chunked_array_get_raw(chunked_array);
-  auto arrow_chunked_array_raw = arrow_chunked_array.get();
   auto arrow_indices = garrow_chunked_array_get_raw(indices);
-  auto arrow_indices_raw = arrow_indices.get();
-  arrow::Result<std::shared_ptr<arrow::ChunkedArray>> 
arrow_taken_chunked_array;
-  if (options) {
-    auto arrow_options = garrow_take_options_get_raw(options);
-    arrow_taken_chunked_array = arrow::compute::Take(*arrow_chunked_array_raw,
-                                                     *arrow_indices_raw,
-                                                     *arrow_options);
-  } else {
-    arrow_taken_chunked_array = arrow::compute::Take(*arrow_chunked_array_raw,
-                                                     *arrow_indices_raw);
-  }
-  if (garrow::check(error,
-                    arrow_taken_chunked_array,
-                    "[chunked-array][take][chunked-array]")) {
-    return garrow_chunked_array_new_raw(&(*arrow_taken_chunked_array));
-  } else {
-    return NULL;
-  }
+  return garrow_take(
+    arrow::Datum(arrow_chunked_array),
+    arrow::Datum(arrow_indices),
+    options,
+    [](arrow::Datum arrow_datum) {
+      auto arrow_taken_chunked_array = arrow_datum.chunked_array();
+      return garrow_chunked_array_new_raw(&arrow_taken_chunked_array);
+    },
+    error,
+    "[chunked-array][take][chunked-array]");
 }
 
 /**
@@ -1823,25 +1803,17 @@ garrow_record_batch_take(GArrowRecordBatch 
*record_batch,
                          GError **error)
 {
   auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
-  auto arrow_record_batch_raw = arrow_record_batch.get();
   auto arrow_indices = garrow_array_get_raw(indices);
-  auto arrow_indices_raw = arrow_indices.get();
-  arrow::Result<std::shared_ptr<arrow::RecordBatch>> arrow_taken_record_batch;
-  if (options) {
-    auto arrow_options = garrow_take_options_get_raw(options);
-    arrow_taken_record_batch = arrow::compute::Take(*arrow_record_batch_raw,
-                                                    *arrow_indices_raw,
-                                                    *arrow_options);
-  } else {
-    arrow_taken_record_batch = arrow::compute::Take(*arrow_record_batch_raw,
-                                                    *arrow_indices_raw);
-  }
-
-  if (garrow::check(error, arrow_taken_record_batch, "[record-batch][take]")) {
-    return garrow_record_batch_new_raw(&(*arrow_taken_record_batch));
-  } else {
-    return NULL;
-  }
+  return garrow_take(
+    arrow::Datum(arrow_record_batch),
+    arrow::Datum(arrow_indices),
+    options,
+    [](arrow::Datum arrow_datum) {
+      auto arrow_taken_record_batch = arrow_datum.record_batch();
+      return garrow_record_batch_new_raw(&arrow_taken_record_batch);
+    },
+    error,
+    "[record-batch][take]");
 }
 
 
diff --git a/c_glib/parquet-glib/arrow-file-reader.cpp 
b/c_glib/parquet-glib/arrow-file-reader.cpp
index c3603b4..c37b957 100644
--- a/c_glib/parquet-glib/arrow-file-reader.cpp
+++ b/c_glib/parquet-glib/arrow-file-reader.cpp
@@ -220,10 +220,8 @@ 
gparquet_arrow_file_reader_read_table(GParquetArrowFileReader *reader,
  * @row_group_index: A row group index to be read.
  * @column_indices: (array length=n_column_indices) (nullable):
  *   Column indices to be read. %NULL means that all columns are read.
- *
  *   If an index is negative, the index is counted backward from the
  *   end of the columns. `-1` means the last column.
- *
  * @n_column_indices: The number of elements of @column_indices.
  * @error: (nullable): Return locatipcn for a #GError or %NULL.
  *
@@ -305,10 +303,8 @@ 
gparquet_arrow_file_reader_get_schema(GParquetArrowFileReader *reader,
  * gparquet_arrow_file_reader_read_column_data:
  * @reader: A #GParquetArrowFileReader.
  * @i: The index of the column to be read.
- *
  *   If an index is negative, the index is counted backward from the
  *   end of the columns. `-1` means the last column.
- *
  * @error: (nullable): Return locatipcn for a #GError or %NULL.
  *
  * Returns: (transfer full) (nullable): A read #GArrowChunkedArray.
diff --git a/cpp/src/arrow/compute/api_vector.h 
b/cpp/src/arrow/compute/api_vector.h
index 166bc10..28812c3 100644
--- a/cpp/src/arrow/compute/api_vector.h
+++ b/cpp/src/arrow/compute/api_vector.h
@@ -209,34 +209,37 @@ Result<Datum> DictionaryEncode(const Datum& data, 
ExecContext* ctx = NULLPTR);
 // ----------------------------------------------------------------------
 // Deprecated functions
 
-// TODO: Add deprecation warnings to these functions
-// ARROW_DEPRECATED("Deprecated in 1.0.0. Use Datum-based version")
-
+ARROW_DEPRECATED("Deprecated in 1.0.0. Use Datum-based version")
 ARROW_EXPORT
 Result<std::shared_ptr<ChunkedArray>> Take(
     const ChunkedArray& values, const Array& indices,
     const TakeOptions& options = TakeOptions::Defaults(), ExecContext* context 
= NULLPTR);
 
+ARROW_DEPRECATED("Deprecated in 1.0.0. Use Datum-based version")
 ARROW_EXPORT
 Result<std::shared_ptr<ChunkedArray>> Take(
     const ChunkedArray& values, const ChunkedArray& indices,
     const TakeOptions& options = TakeOptions::Defaults(), ExecContext* context 
= NULLPTR);
 
+ARROW_DEPRECATED("Deprecated in 1.0.0. Use Datum-based version")
 ARROW_EXPORT
 Result<std::shared_ptr<ChunkedArray>> Take(
     const Array& values, const ChunkedArray& indices,
     const TakeOptions& options = TakeOptions::Defaults(), ExecContext* context 
= NULLPTR);
 
+ARROW_DEPRECATED("Deprecated in 1.0.0. Use Datum-based version")
 ARROW_EXPORT
 Result<std::shared_ptr<RecordBatch>> Take(
     const RecordBatch& batch, const Array& indices,
     const TakeOptions& options = TakeOptions::Defaults(), ExecContext* context 
= NULLPTR);
 
+ARROW_DEPRECATED("Deprecated in 1.0.0. Use Datum-based version")
 ARROW_EXPORT
 Result<std::shared_ptr<Table>> Take(const Table& table, const Array& indices,
                                     const TakeOptions& options = 
TakeOptions::Defaults(),
                                     ExecContext* context = NULLPTR);
 
+ARROW_DEPRECATED("Deprecated in 1.0.0. Use Datum-based version")
 ARROW_EXPORT
 Result<std::shared_ptr<Table>> Take(const Table& table, const ChunkedArray& 
indices,
                                     const TakeOptions& options = 
TakeOptions::Defaults(),

Reply via email to