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 2022/06/14 00:35:39 UTC
[arrow] branch master updated: ARROW-16623: [GLib] Add GArrowQuantileOptions (#13374)
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 14471e767a ARROW-16623: [GLib] Add GArrowQuantileOptions (#13374)
14471e767a is described below
commit 14471e767a446e31110828a1a304771f426050e9
Author: Sutou Kouhei <ko...@clear-code.com>
AuthorDate: Tue Jun 14 09:35:32 2022 +0900
ARROW-16623: [GLib] Add GArrowQuantileOptions (#13374)
Authored-by: Sutou Kouhei <ko...@clear-code.com>
Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
c_glib/arrow-glib/compute.cpp | 250 +++++++++++++++++++++++++++++
c_glib/arrow-glib/compute.h | 51 ++++++
c_glib/arrow-glib/compute.hpp | 7 +
c_glib/arrow-glib/version.h.in | 23 +++
c_glib/doc/arrow-glib/arrow-glib-docs.xml | 4 +
c_glib/test/test-utf8-normalize-options.rb | 2 -
6 files changed, 335 insertions(+), 2 deletions(-)
diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp
index 0080688b13..96346edfd6 100644
--- a/c_glib/arrow-glib/compute.cpp
+++ b/c_glib/arrow-glib/compute.cpp
@@ -3696,6 +3696,226 @@ garrow_utf8_normalize_options_new(void)
}
+enum {
+ PROP_QUANTILE_OPTIONS_INTERPOLATION = 1,
+ PROP_QUANTILE_OPTIONS_SKIP_NULLS,
+ PROP_QUANTILE_OPTIONS_MIN_COUNT,
+};
+
+G_DEFINE_TYPE(GArrowQuantileOptions,
+ garrow_quantile_options,
+ GARROW_TYPE_FUNCTION_OPTIONS)
+
+#define GARROW_QUANTILE_OPTIONS_GET_PRIVATE(object) \
+ static_cast<GArrowQuantileOptionsPrivate *>( \
+ garrow_quantile_options_get_instance_private( \
+ GARROW_QUANTILE_OPTIONS(object)))
+
+static void
+garrow_quantile_options_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ auto options =
+ garrow_quantile_options_get_raw(
+ GARROW_QUANTILE_OPTIONS(object));
+
+ switch (prop_id) {
+ case PROP_QUANTILE_OPTIONS_INTERPOLATION:
+ options->interpolation =
+ static_cast<arrow::compute::QuantileOptions::Interpolation>(
+ g_value_get_enum(value));
+ break;
+ case PROP_QUANTILE_OPTIONS_SKIP_NULLS:
+ options->skip_nulls = g_value_get_boolean(value);
+ break;
+ case PROP_QUANTILE_OPTIONS_MIN_COUNT:
+ options->min_count = g_value_get_uint(value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_quantile_options_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ auto options = garrow_quantile_options_get_raw(
+ GARROW_QUANTILE_OPTIONS(object));
+
+ switch (prop_id) {
+ case PROP_QUANTILE_OPTIONS_INTERPOLATION:
+ g_value_set_enum(
+ value,
+ static_cast<GArrowQuantileInterpolation>(options->interpolation));
+ break;
+ case PROP_QUANTILE_OPTIONS_SKIP_NULLS:
+ g_value_set_boolean(value, options->skip_nulls);
+ break;
+ case PROP_QUANTILE_OPTIONS_MIN_COUNT:
+ g_value_set_uint(value, options->min_count);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_quantile_options_init(GArrowQuantileOptions *object)
+{
+ auto priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
+ priv->options = static_cast<arrow::compute::FunctionOptions *>(
+ new arrow::compute::QuantileOptions());
+}
+
+static void
+garrow_quantile_options_class_init(GArrowQuantileOptionsClass *klass)
+{
+ auto gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->set_property = garrow_quantile_options_set_property;
+ gobject_class->get_property = garrow_quantile_options_get_property;
+
+
+ auto options = arrow::compute::QuantileOptions::Defaults();
+
+ GParamSpec *spec;
+ /**
+ * GArrowQuantileOptions:interpolation:
+ *
+ * Interpolation method to use when quantile lies between two data
+ * points.
+ *
+ * Since: 9.0.0
+ */
+ spec = g_param_spec_enum("interpolation",
+ "Interpolation",
+ "Interpolation method to use when "
+ "quantile lies between two data points.",
+ GARROW_TYPE_QUANTILE_INTERPOLATION,
+ static_cast<GArrowQuantileInterpolation>(
+ options.interpolation),
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_QUANTILE_OPTIONS_INTERPOLATION,
+ spec);
+
+ /**
+ * GArrowQuantileOptions:skip-nulls:
+ *
+ * If true (the default), null values are ignored. Otherwise, if any
+ * value is null, emit null.
+ *
+ * Since: 9.0.0
+ */
+ spec = g_param_spec_boolean("skip-nulls",
+ "Skip nulls",
+ "If true (the default), "
+ "null values are ignored. "
+ "Otherwise, if any value is null, "
+ "emit null.",
+ options.skip_nulls,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_QUANTILE_OPTIONS_SKIP_NULLS,
+ spec);
+
+ /**
+ * GArrowQuantileOptions:min-count:
+ *
+ * If less than this many non-null values are observed, emit null.
+ *
+ * Since: 9.0.0
+ */
+ spec = g_param_spec_uint("min-count",
+ "Min count",
+ "If less than this many non-null values are "
+ "observed, emit null.",
+ 0,
+ G_MAXUINT32,
+ options.min_count,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_QUANTILE_OPTIONS_MIN_COUNT,
+ spec);
+}
+
+/**
+ * garrow_quantile_options_new:
+ *
+ * Returns: A newly created #GArrowQuantileOptions.
+ *
+ * Since: 9.0.0
+ */
+GArrowQuantileOptions *
+garrow_quantile_options_new(void)
+{
+ return GARROW_QUANTILE_OPTIONS(
+ g_object_new(GARROW_TYPE_QUANTILE_OPTIONS, NULL));
+}
+
+/**
+ * garrow_quantile_options_get_qs:
+ * @options: A #GArrowQuantileOptions.
+ * @n: (out): The number of `q`s.
+ *
+ * Returns: (array length=n) (transfer none): The `q`s to be used.
+ *
+ * Since: 9.0.0
+ */
+const gdouble *
+garrow_quantile_options_get_qs(GArrowQuantileOptions *options, gsize *n)
+{
+ auto priv = garrow_quantile_options_get_raw(options);
+ if (n) {
+ *n = priv->q.size();
+ }
+ return priv->q.data();
+}
+
+/**
+ * garrow_quantile_options_set_q:
+ * @options: A #GArrowQuantileOptions.
+ * @q: A `q` to be used.
+ *
+ * Since: 9.0.0
+ */
+void
+garrow_quantile_options_set_q(GArrowQuantileOptions *options,
+ gdouble q)
+{
+ auto priv = garrow_quantile_options_get_raw(options);
+ priv->q.clear();
+ priv->q.push_back(q);
+}
+
+/**
+ * garrow_quantile_options_set_qs:
+ * @options: A #GArrowQuantileOptions.
+ * @qs: (array length=n): `q`s to be used.
+ * @n: The number of @qs.
+ *
+ * Since: 9.0.0
+ */
+void
+garrow_quantile_options_set_qs(GArrowQuantileOptions *options,
+ const gdouble *qs,
+ gsize n)
+{
+ auto priv = garrow_quantile_options_get_raw(options);
+ priv->q.clear();
+ for (gsize i = 0; i < n; i++) {
+ priv->q.push_back(qs[i]);
+ }
+}
+
+
/**
* garrow_array_cast:
* @array: A #GArrowArray.
@@ -4964,6 +5184,11 @@ garrow_function_options_new_raw(
auto options = garrow_utf8_normalize_options_new_raw(
arrow_utf8_normalize_options);
return GARROW_FUNCTION_OPTIONS(options);
+ } else if (arrow_type_name == "QuantileOptions") {
+ const auto arrow_quantile_options =
+ static_cast<const arrow::compute::QuantileOptions *>(arrow_options);
+ auto options = garrow_quantile_options_new_raw(arrow_quantile_options);
+ return GARROW_FUNCTION_OPTIONS(options);
} else {
auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS,
NULL);
@@ -5328,3 +5553,28 @@ garrow_utf8_normalize_options_get_raw(GArrowUTF8NormalizeOptions *options)
return static_cast<arrow::compute::Utf8NormalizeOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
+
+
+GArrowQuantileOptions *
+garrow_quantile_options_new_raw(
+ const arrow::compute::QuantileOptions *arrow_options)
+{
+ auto options =
+ GARROW_QUANTILE_OPTIONS(
+ g_object_new(GARROW_TYPE_QUANTILE_OPTIONS,
+ "interpolation", arrow_options->interpolation,
+ "skip-nulls", arrow_options->skip_nulls,
+ "min-count", arrow_options->min_count,
+ NULL));
+ garrow_quantile_options_set_qs(options,
+ arrow_options->q.data(),
+ arrow_options->q.size());
+ return options;
+}
+
+arrow::compute::QuantileOptions *
+garrow_quantile_options_get_raw(GArrowQuantileOptions *options)
+{
+ return static_cast<arrow::compute::QuantileOptions *>(
+ garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
+}
diff --git a/c_glib/arrow-glib/compute.h b/c_glib/arrow-glib/compute.h
index 66cc129d6c..818b76ed72 100644
--- a/c_glib/arrow-glib/compute.h
+++ b/c_glib/arrow-glib/compute.h
@@ -712,6 +712,57 @@ GArrowUTF8NormalizeOptions *
garrow_utf8_normalize_options_new(void);
+/**
+ * GArrowQuantileInterpolation:
+ * @GARROW_QUANTILE_INTERPOLATION_LINEAR: Linear.
+ * @GARROW_QUANTILE_INTERPOLATION_LOWER: Lower.
+ * @GARROW_QUANTILE_INTERPOLATION_HIGHER: Higher.
+ * @GARROW_QUANTILE_INTERPOLATION_NEAREST: Nearest.
+ * @GARROW_QUANTILE_INTERPOLATION_MIDPOINT: Midpoint.
+ *
+ * They correspond to the values of
+ * `arrow::compute::QuantileOptions::Interpolation`.
+ *
+ * Since: 9.0.0
+ */
+typedef enum {
+ GARROW_QUANTILE_INTERPOLATION_LINEAR,
+ GARROW_QUANTILE_INTERPOLATION_LOWER,
+ GARROW_QUANTILE_INTERPOLATION_HIGHER,
+ GARROW_QUANTILE_INTERPOLATION_NEAREST,
+ GARROW_QUANTILE_INTERPOLATION_MIDPOINT,
+} GArrowQuantileInterpolation;
+
+#define GARROW_TYPE_QUANTILE_OPTIONS \
+ (garrow_quantile_options_get_type())
+G_DECLARE_DERIVABLE_TYPE(GArrowQuantileOptions,
+ garrow_quantile_options,
+ GARROW,
+ QUANTILE_OPTIONS,
+ GArrowFunctionOptions)
+struct _GArrowQuantileOptionsClass
+{
+ GArrowFunctionOptionsClass parent_class;
+};
+
+GARROW_AVAILABLE_IN_9_0
+GArrowQuantileOptions *
+garrow_quantile_options_new(void);
+GARROW_AVAILABLE_IN_9_0
+const gdouble *
+garrow_quantile_options_get_qs(GArrowQuantileOptions *options,
+ gsize *n);
+GARROW_AVAILABLE_IN_9_0
+void
+garrow_quantile_options_set_q(GArrowQuantileOptions *options,
+ gdouble quantile);
+GARROW_AVAILABLE_IN_9_0
+void
+garrow_quantile_options_set_qs(GArrowQuantileOptions *options,
+ const gdouble *qs,
+ gsize n);
+
+
GArrowArray *garrow_array_cast(GArrowArray *array,
GArrowDataType *target_data_type,
GArrowCastOptions *options,
diff --git a/c_glib/arrow-glib/compute.hpp b/c_glib/arrow-glib/compute.hpp
index b5516a2961..f7de4d7cf8 100644
--- a/c_glib/arrow-glib/compute.hpp
+++ b/c_glib/arrow-glib/compute.hpp
@@ -155,3 +155,10 @@ garrow_utf8_normalize_options_new_raw(
const arrow::compute::Utf8NormalizeOptions *arrow_options);
arrow::compute::Utf8NormalizeOptions *
garrow_utf8_normalize_options_get_raw(GArrowUTF8NormalizeOptions *options);
+
+
+GArrowQuantileOptions *
+garrow_quantile_options_new_raw(
+ const arrow::compute::QuantileOptions *arrow_options);
+arrow::compute::QuantileOptions *
+garrow_quantile_options_get_raw(GArrowQuantileOptions *options);
diff --git a/c_glib/arrow-glib/version.h.in b/c_glib/arrow-glib/version.h.in
index b17000ed3c..74c54b998d 100644
--- a/c_glib/arrow-glib/version.h.in
+++ b/c_glib/arrow-glib/version.h.in
@@ -110,6 +110,15 @@
# define GARROW_UNAVAILABLE(major, minor) G_UNAVAILABLE(major, minor)
#endif
+/**
+ * GARROW_VERSION_9_0:
+ *
+ * You can use this macro value for compile time API version check.
+ *
+ * Since: 9.0.0
+ */
+#define GARROW_VERSION_9_0 G_ENCODE_VERSION(9, 0)
+
/**
* GARROW_VERSION_8_0:
*
@@ -292,6 +301,20 @@
#define GARROW_AVAILABLE_IN_ALL
+#if GARROW_VERSION_MIN_REQUIRED >= GARROW_VERSION_9_0
+# define GARROW_DEPRECATED_IN_9_0 GARROW_DEPRECATED
+# define GARROW_DEPRECATED_IN_9_0_FOR(function) GARROW_DEPRECATED_FOR(function)
+#else
+# define GARROW_DEPRECATED_IN_9_0
+# define GARROW_DEPRECATED_IN_9_0_FOR(function)
+#endif
+
+#if GARROW_VERSION_MAX_ALLOWED < GARROW_VERSION_9_0
+# define GARROW_AVAILABLE_IN_9_0 GARROW_UNAVAILABLE(9, 0)
+#else
+# define GARROW_AVAILABLE_IN_9_0
+#endif
+
#if GARROW_VERSION_MIN_REQUIRED >= GARROW_VERSION_8_0
# define GARROW_DEPRECATED_IN_8_0 GARROW_DEPRECATED
# define GARROW_DEPRECATED_IN_8_0_FOR(function) GARROW_DEPRECATED_FOR(function)
diff --git a/c_glib/doc/arrow-glib/arrow-glib-docs.xml b/c_glib/doc/arrow-glib/arrow-glib-docs.xml
index 9c6fdf08b4..2ad1135bc6 100644
--- a/c_glib/doc/arrow-glib/arrow-glib-docs.xml
+++ b/c_glib/doc/arrow-glib/arrow-glib-docs.xml
@@ -193,6 +193,10 @@
<title>Index of deprecated API</title>
<xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
</index>
+ <index id="api-index-9-0-0" role="9.0.0">
+ <title>Index of new symbols in 9.0.0</title>
+ <xi:include href="xml/api-index-9.0.0.xml"><xi:fallback /></xi:include>
+ </index>
<index id="api-index-8-0-0" role="8.0.0">
<title>Index of new symbols in 8.0.0</title>
<xi:include href="xml/api-index-8.0.0.xml"><xi:fallback /></xi:include>
diff --git a/c_glib/test/test-utf8-normalize-options.rb b/c_glib/test/test-utf8-normalize-options.rb
index d3e1bcd1ab..940a95d47b 100644
--- a/c_glib/test/test-utf8-normalize-options.rb
+++ b/c_glib/test/test-utf8-normalize-options.rb
@@ -16,8 +16,6 @@
# under the License.
class TestUTF8NormalizeOptions < Test::Unit::TestCase
- include Helper::Buildable
-
def setup
@options = Arrow::UTF8NormalizeOptions.new
end