You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2025/06/25 21:31:44 UTC

(arrow) branch main updated: GH-44435: [GLib] Add distinct count support to GArrowArrayStatistics (#46894)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new d97e7ab509 GH-44435: [GLib] Add distinct count support to GArrowArrayStatistics (#46894)
d97e7ab509 is described below

commit d97e7ab5093d1833321d614c0eb0ba69e61b7860
Author: takuya kodama <a....@gmail.com>
AuthorDate: Thu Jun 26 06:31:37 2025 +0900

    GH-44435: [GLib] Add distinct count support to GArrowArrayStatistics (#46894)
    
    ### Rationale for this change
    
    The GLib bindings were missing methods to handle distinct count statistics in GArrowArrayStatistics.
    
    ### What changes are included in this PR?
    
    This PR adds the following:
    - Add garrow_array_statistics_has_distinct_count()
    - Add garrow_array_statistics_get_distinct_count()
    - Add tests for distinct count
    
    ### Are these changes tested?
    
    Yes.
    
    ### Are there any user-facing changes?
    
    No.
    
    * GitHub Issue: #44435
    
    Authored-by: otegami <a....@gmail.com>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 c_glib/arrow-glib/basic-array.cpp    | 36 ++++++++++++++++++++++++++++++++++++
 c_glib/arrow-glib/basic-array.h      |  7 +++++++
 c_glib/test/test-array-statistics.rb | 10 ++++++++++
 3 files changed, 53 insertions(+)

diff --git a/c_glib/arrow-glib/basic-array.cpp b/c_glib/arrow-glib/basic-array.cpp
index 8127344b3a..d3ea094f55 100644
--- a/c_glib/arrow-glib/basic-array.cpp
+++ b/c_glib/arrow-glib/basic-array.cpp
@@ -476,6 +476,42 @@ garrow_array_statistics_get_null_count(GArrowArrayStatistics *statistics)
   }
 }
 
+/**
+ * garrow_array_statistics_has_distinct_count:
+ * @statistics: A #GArrowArrayStatistics.
+ *
+ * Returns: %TRUE if the distinct count is available, %FALSE otherwise.
+ *
+ * Since: 21.0.0
+ */
+gboolean
+garrow_array_statistics_has_distinct_count(GArrowArrayStatistics *statistics)
+{
+  auto priv = GARROW_ARRAY_STATISTICS_GET_PRIVATE(statistics);
+  return priv->statistics.distinct_count.has_value();
+}
+
+/**
+ * garrow_array_statistics_get_distinct_count:
+ * @statistics: A #GArrowArrayStatistics.
+ *
+ * Returns: 0 or larger value if @statistics has a valid distinct count value,
+ *   -1 otherwise.
+ *
+ * Since: 21.0.0
+ */
+gint64
+garrow_array_statistics_get_distinct_count(GArrowArrayStatistics *statistics)
+{
+  auto priv = GARROW_ARRAY_STATISTICS_GET_PRIVATE(statistics);
+  const auto &distinct_count = priv->statistics.distinct_count;
+  if (distinct_count) {
+    return distinct_count.value();
+  } else {
+    return -1;
+  }
+}
+
 typedef struct GArrowArrayPrivate_
 {
   std::shared_ptr<arrow::Array> array;
diff --git a/c_glib/arrow-glib/basic-array.h b/c_glib/arrow-glib/basic-array.h
index 615d6793b0..4340947044 100644
--- a/c_glib/arrow-glib/basic-array.h
+++ b/c_glib/arrow-glib/basic-array.h
@@ -58,6 +58,13 @@ GARROW_AVAILABLE_IN_20_0
 gint64
 garrow_array_statistics_get_null_count(GArrowArrayStatistics *statistics);
 
+GARROW_AVAILABLE_IN_21_0
+gboolean
+garrow_array_statistics_has_distinct_count(GArrowArrayStatistics *statistics);
+GARROW_AVAILABLE_IN_21_0
+gint64
+garrow_array_statistics_get_distinct_count(GArrowArrayStatistics *statistics);
+
 GARROW_AVAILABLE_IN_6_0
 GArrowArray *
 garrow_array_import(gpointer c_abi_array, GArrowDataType *data_type, GError **error);
diff --git a/c_glib/test/test-array-statistics.rb b/c_glib/test/test-array-statistics.rb
index bf470b4e72..ccc14cccb8 100644
--- a/c_glib/test/test-array-statistics.rb
+++ b/c_glib/test/test-array-statistics.rb
@@ -48,4 +48,14 @@ class TestArrayStatistics < Test::Unit::TestCase
   test("#null_count") do
     assert_equal(1, @statistics.null_count)
   end
+
+  test("#has_distinct_count?") do
+    assert do
+      !@statistics.has_distinct_count?
+    end
+  end
+
+  test ("#distinct_count") do
+    assert_equal(-1, @statistics.distinct_count)
+  end
 end