You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/12/29 21:31:11 UTC

[GitHub] [arrow] kou commented on a change in pull request #12043: ARROW-15204: [GLib] Add Arrow::RoundOptions

kou commented on a change in pull request #12043:
URL: https://github.com/apache/arrow/pull/12043#discussion_r776499329



##########
File path: c_glib/arrow-glib/compute.cpp
##########
@@ -2902,6 +2902,133 @@ garrow_variance_options_new(void)
 }
 
 
+enum {
+  PROP_ROUND_OPTIONS_N_DIGITS = 1,
+  PROP_ROUND_OPTIONS_MODE,
+};
+
+G_DEFINE_TYPE(GArrowRoundOptions,
+              garrow_round_options,
+              GARROW_TYPE_FUNCTION_OPTIONS)
+
+#define GARROW_ROUND_OPTIONS_GET_PRIVATE(object)  \
+  static_cast<GArrowRoundOptionsPrivate *>(       \
+    garrow_round_options_get_instance_private(    \
+      GARROW_ROUND_OPTIONS(object)))
+
+static void
+garrow_round_options_set_property(GObject *object,
+                                  guint prop_id,
+                                  const GValue *value,
+                                  GParamSpec *pspec)
+{
+  auto options = garrow_round_options_get_raw(GARROW_ROUND_OPTIONS(object));
+
+  switch (prop_id) {
+  case PROP_ROUND_OPTIONS_N_DIGITS:
+    options->ndigits = g_value_get_int64(value);
+    break;
+  case PROP_ROUND_OPTIONS_MODE:
+    options->round_mode =
+      static_cast<arrow::compute::RoundMode>(g_value_get_enum(value));
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+garrow_round_options_get_property(GObject *object,
+                                  guint prop_id,
+                                  GValue *value,
+                                  GParamSpec *pspec)
+{
+  auto options = garrow_round_options_get_raw(GARROW_ROUND_OPTIONS(object));
+
+  switch (prop_id) {
+  case PROP_ROUND_OPTIONS_N_DIGITS:
+    g_value_set_int64(value, options->ndigits);
+    break;
+  case PROP_ROUND_OPTIONS_MODE:
+    g_value_set_enum(value, static_cast<GArrowRoundMode>(options->round_mode));
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+garrow_round_options_init(GArrowRoundOptions *object)
+{
+  auto priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
+  priv->options = static_cast<arrow::compute::FunctionOptions *>(
+    new arrow::compute::RoundOptions());
+}
+
+static void
+garrow_round_options_class_init(GArrowRoundOptionsClass *klass)
+{
+  auto gobject_class = G_OBJECT_CLASS(klass);
+
+  gobject_class->set_property = garrow_round_options_set_property;
+  gobject_class->get_property = garrow_round_options_get_property;
+
+
+  arrow::compute::RoundOptions options;

Review comment:
       I added the 2 empty lines explicitly to separate code blocks for `gobject_class->XXX = ...` and `g_param_spec_*()`.

##########
File path: c_glib/arrow-glib/compute.cpp
##########
@@ -2902,6 +2902,133 @@ garrow_variance_options_new(void)
 }
 
 
+enum {
+  PROP_ROUND_OPTIONS_N_DIGITS = 1,
+  PROP_ROUND_OPTIONS_MODE,
+};
+
+G_DEFINE_TYPE(GArrowRoundOptions,
+              garrow_round_options,
+              GARROW_TYPE_FUNCTION_OPTIONS)
+
+#define GARROW_ROUND_OPTIONS_GET_PRIVATE(object)  \
+  static_cast<GArrowRoundOptionsPrivate *>(       \
+    garrow_round_options_get_instance_private(    \
+      GARROW_ROUND_OPTIONS(object)))
+
+static void
+garrow_round_options_set_property(GObject *object,
+                                  guint prop_id,
+                                  const GValue *value,
+                                  GParamSpec *pspec)
+{
+  auto options = garrow_round_options_get_raw(GARROW_ROUND_OPTIONS(object));
+
+  switch (prop_id) {
+  case PROP_ROUND_OPTIONS_N_DIGITS:

Review comment:
       Thanks for this comment.
   `case`s are indented in `cpp/` but `c_glib/` uses this style.

##########
File path: c_glib/arrow-glib/compute.cpp
##########
@@ -2902,6 +2902,133 @@ garrow_variance_options_new(void)
 }
 
 
+enum {
+  PROP_ROUND_OPTIONS_N_DIGITS = 1,
+  PROP_ROUND_OPTIONS_MODE,
+};
+
+G_DEFINE_TYPE(GArrowRoundOptions,
+              garrow_round_options,
+              GARROW_TYPE_FUNCTION_OPTIONS)
+
+#define GARROW_ROUND_OPTIONS_GET_PRIVATE(object)  \
+  static_cast<GArrowRoundOptionsPrivate *>(       \
+    garrow_round_options_get_instance_private(    \
+      GARROW_ROUND_OPTIONS(object)))
+
+static void
+garrow_round_options_set_property(GObject *object,
+                                  guint prop_id,
+                                  const GValue *value,
+                                  GParamSpec *pspec)
+{
+  auto options = garrow_round_options_get_raw(GARROW_ROUND_OPTIONS(object));
+
+  switch (prop_id) {
+  case PROP_ROUND_OPTIONS_N_DIGITS:
+    options->ndigits = g_value_get_int64(value);
+    break;
+  case PROP_ROUND_OPTIONS_MODE:
+    options->round_mode =
+      static_cast<arrow::compute::RoundMode>(g_value_get_enum(value));
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+garrow_round_options_get_property(GObject *object,
+                                  guint prop_id,
+                                  GValue *value,
+                                  GParamSpec *pspec)
+{
+  auto options = garrow_round_options_get_raw(GARROW_ROUND_OPTIONS(object));
+
+  switch (prop_id) {
+  case PROP_ROUND_OPTIONS_N_DIGITS:
+    g_value_set_int64(value, options->ndigits);
+    break;
+  case PROP_ROUND_OPTIONS_MODE:
+    g_value_set_enum(value, static_cast<GArrowRoundMode>(options->round_mode));
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+garrow_round_options_init(GArrowRoundOptions *object)
+{
+  auto priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
+  priv->options = static_cast<arrow::compute::FunctionOptions *>(
+    new arrow::compute::RoundOptions());
+}
+
+static void
+garrow_round_options_class_init(GArrowRoundOptionsClass *klass)
+{
+  auto gobject_class = G_OBJECT_CLASS(klass);
+
+  gobject_class->set_property = garrow_round_options_set_property;
+  gobject_class->get_property = garrow_round_options_get_property;
+
+
+  arrow::compute::RoundOptions options;
+
+  GParamSpec *spec;
+  /**
+   * GArrowRoundOptions:n-digits:
+   *
+   * The rounding precision (number of digits to round to).
+   *
+   * Since: 7.0.0
+   */
+  spec = g_param_spec_int64("n-digits",
+                            "Number of digits to round to",
+                            "The round precision",
+                            G_MININT64,
+                            G_MAXINT64,
+                            options.ndigits,
+                            static_cast<GParamFlags>(G_PARAM_READWRITE));
+  g_object_class_install_property(gobject_class,
+                                  PROP_ROUND_OPTIONS_N_DIGITS,
+                                  spec);
+
+  /**
+   * GArrowRoundOptions:mode:
+   *
+   * The rounding and tie-breaking mode.
+   *
+   * Since: 7.0.0
+   */
+  spec = g_param_spec_enum("mode",
+                           "Mode",

Review comment:
       I think that "Rounding" is redundant here because this is a parameter for `GArrowRoundOptions`.
   "Mode" is for "round" in this context.
   
   Should we remove `round_` from `arrow::compute::RoundOptions::round_mode` too?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org