Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions c_glib/arrow-glib/basic-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hopeful as more kernel functions are implemented that some common patterns will emerge to make things simpler in binding layers like this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I'll keep implementing kernel function bindings.

}


G_DEFINE_TYPE(GArrowNullArray, \
garrow_null_array, \
Expand Down
2 changes: 2 additions & 0 deletions c_glib/arrow-glib/basic-array.h
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
31 changes: 31 additions & 0 deletions c_glib/test/test-unique.rb
Original file line number Diff line number Diff line change
@@ -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