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-1874: [GLib] Add garrow_array_unique()
Date Fri, 01 Dec 2017 21:14:48 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 705d842  ARROW-1874: [GLib] Add garrow_array_unique()
705d842 is described below

commit 705d842664d6626d25843ebbb331186033126287
Author: Kouhei Sutou <kou@clear-code.com>
AuthorDate: Fri Dec 1 16:14:44 2017 -0500

    ARROW-1874: [GLib] Add garrow_array_unique()
    
    Author: Kouhei Sutou <kou@clear-code.com>
    
    Closes #1377 from kou/glib-unique and squashes the following commits:
    
    4385e22d [Kouhei Sutou] Add garrow_array_unique()
---
 c_glib/arrow-glib/basic-array.cpp | 33 +++++++++++++++++++++++++++++++++
 c_glib/arrow-glib/basic-array.h   |  2 ++
 c_glib/test/test-unique.rb        | 31 +++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+)

diff --git a/c_glib/arrow-glib/basic-array.cpp b/c_glib/arrow-glib/basic-array.cpp
index 36cf460..a7afaca 100644
--- a/c_glib/arrow-glib/basic-array.cpp
+++ b/c_glib/arrow-glib/basic-array.cpp
@@ -563,6 +563,39 @@ garrow_array_cast(GArrowArray *array,
   return garrow_array_new_raw(&arrow_casted_array);
 }
 
+/**
+ * garrow_array_unique:
+ * @array: A #GArrowArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable) (transfer full):
+ *   A newly created unique elements array on success, %NULL on error.
+ *
+ * Since: 0.8.0
+ */
+GArrowArray *
+garrow_array_unique(GArrowArray *array,
+                    GError **error)
+{
+  auto arrow_array = garrow_array_get_raw(array);
+  auto memory_pool = arrow::default_memory_pool();
+  arrow::compute::FunctionContext context(memory_pool);
+  std::shared_ptr<arrow::Array> arrow_unique_array;
+  auto status = arrow::compute::Unique(&context,
+                                       arrow::compute::Datum(arrow_array),
+                                       &arrow_unique_array);
+  if (!status.ok()) {
+    std::stringstream message;
+    message << "[array][unique] <";
+    message << arrow_array->type()->ToString();
+    message << ">";
+    garrow_error_check(error, status, message.str().c_str());
+    return NULL;
+  }
+
+  return garrow_array_new_raw(&arrow_unique_array);
+}
+
 
 G_DEFINE_TYPE(GArrowNullArray,               \
               garrow_null_array,             \
diff --git a/c_glib/arrow-glib/basic-array.h b/c_glib/arrow-glib/basic-array.h
index c01a04f..613a59b 100644
--- a/c_glib/arrow-glib/basic-array.h
+++ b/c_glib/arrow-glib/basic-array.h
@@ -66,6 +66,8 @@ GArrowArray   *garrow_array_cast        (GArrowArray *array,
                                          GArrowDataType *target_data_type,
                                          GArrowCastOptions *options,
                                          GError **error);
+GArrowArray   *garrow_array_unique      (GArrowArray *array,
+                                         GError **error);
 
 #define GARROW_TYPE_NULL_ARRAY                  \
   (garrow_null_array_get_type())
diff --git a/c_glib/test/test-unique.rb b/c_glib/test/test-unique.rb
new file mode 100644
index 0000000..b94ff46
--- /dev/null
+++ b/c_glib/test/test-unique.rb
@@ -0,0 +1,31 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestUnique < Test::Unit::TestCase
+  include Helper::Buildable
+  include Helper::Omittable
+
+  def test_int32
+    assert_equal(build_int32_array([1, 3, -1, -3]),
+                 build_int32_array([1, 3, 1, -1, -3, -1]).unique)
+  end
+
+  def test_string
+    assert_equal(build_string_array(["Ruby", "Python"]),
+                 build_string_array(["Ruby", "Python", "Ruby"]).unique)
+  end
+end

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

Mime
View raw message