|
28 | 28 | #include <arrow-glib/error.hpp> |
29 | 29 | #include <arrow-glib/reader.hpp> |
30 | 30 | #include <arrow-glib/record-batch.hpp> |
| 31 | +#include <arrow-glib/scalar.hpp> |
31 | 32 | #include <arrow-glib/schema.hpp> |
32 | 33 | #include <arrow-glib/table.hpp> |
33 | 34 |
|
@@ -173,6 +174,11 @@ G_BEGIN_DECLS |
173 | 174 | * #GArrowVarianceOptions is a class to customize the `stddev` function |
174 | 175 | * and `variance` function. |
175 | 176 | * |
| 177 | + * #GArrowRoundOptions is a class to customize the `round` function. |
| 178 | + * |
| 179 | + * #GArrowRoundToMultipleOptions is a class to customize the |
| 180 | + * `round_to_multiple` function. |
| 181 | + * |
176 | 182 | * There are many functions to compute data on an array. |
177 | 183 | */ |
178 | 184 |
|
@@ -3136,6 +3142,179 @@ garrow_round_options_new(void) |
3136 | 3142 | } |
3137 | 3143 |
|
3138 | 3144 |
|
| 3145 | +typedef struct GArrowRoundToMultipleOptionsPrivate_ { |
| 3146 | + GArrowScalar *multiple; |
| 3147 | +} GArrowRoundToMultipleOptionsPrivate; |
| 3148 | + |
| 3149 | +enum { |
| 3150 | + PROP_ROUND_TO_MULTIPLE_OPTIONS_MULTIPLE = 1, |
| 3151 | + PROP_ROUND_TO_MULTIPLE_OPTIONS_MODE, |
| 3152 | +}; |
| 3153 | + |
| 3154 | +G_DEFINE_TYPE_WITH_PRIVATE(GArrowRoundToMultipleOptions, |
| 3155 | + garrow_round_to_multiple_options, |
| 3156 | + GARROW_TYPE_FUNCTION_OPTIONS) |
| 3157 | + |
| 3158 | +#define GARROW_ROUND_TO_MULTIPLE_OPTIONS_GET_PRIVATE(object) \ |
| 3159 | + static_cast<GArrowRoundToMultipleOptionsPrivate *>( \ |
| 3160 | + garrow_round_to_multiple_options_get_instance_private( \ |
| 3161 | + GARROW_ROUND_TO_MULTIPLE_OPTIONS(object))) |
| 3162 | + |
| 3163 | +static void |
| 3164 | +garrow_round_to_multiple_options_dispose(GObject *object) |
| 3165 | +{ |
| 3166 | + auto priv = GARROW_ROUND_TO_MULTIPLE_OPTIONS_GET_PRIVATE(object); |
| 3167 | + |
| 3168 | + if (priv->multiple) { |
| 3169 | + g_object_unref(priv->multiple); |
| 3170 | + priv->multiple = NULL; |
| 3171 | + } |
| 3172 | + |
| 3173 | + G_OBJECT_CLASS(garrow_round_to_multiple_options_parent_class)->dispose(object); |
| 3174 | +} |
| 3175 | + |
| 3176 | +static void |
| 3177 | +garrow_round_to_multiple_options_set_property(GObject *object, |
| 3178 | + guint prop_id, |
| 3179 | + const GValue *value, |
| 3180 | + GParamSpec *pspec) |
| 3181 | +{ |
| 3182 | + auto priv = GARROW_ROUND_TO_MULTIPLE_OPTIONS_GET_PRIVATE(object); |
| 3183 | + auto options = |
| 3184 | + garrow_round_to_multiple_options_get_raw( |
| 3185 | + GARROW_ROUND_TO_MULTIPLE_OPTIONS(object)); |
| 3186 | + |
| 3187 | + switch (prop_id) { |
| 3188 | + case PROP_ROUND_TO_MULTIPLE_OPTIONS_MULTIPLE: |
| 3189 | + { |
| 3190 | + auto multiple = g_value_get_object(value); |
| 3191 | + if (priv->multiple != multiple) { |
| 3192 | + if (priv->multiple) { |
| 3193 | + g_object_unref(priv->multiple); |
| 3194 | + } |
| 3195 | + if (multiple) { |
| 3196 | + priv->multiple = GARROW_SCALAR(multiple); |
| 3197 | + g_object_ref(priv->multiple); |
| 3198 | + options->multiple = garrow_scalar_get_raw(priv->multiple); |
| 3199 | + } else { |
| 3200 | + priv->multiple = NULL; |
| 3201 | + options->multiple = std::make_shared<arrow::NullScalar>(); |
| 3202 | + } |
| 3203 | + } |
| 3204 | + } |
| 3205 | + break; |
| 3206 | + case PROP_ROUND_TO_MULTIPLE_OPTIONS_MODE: |
| 3207 | + options->round_mode = |
| 3208 | + static_cast<arrow::compute::RoundMode>(g_value_get_enum(value)); |
| 3209 | + break; |
| 3210 | + default: |
| 3211 | + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); |
| 3212 | + break; |
| 3213 | + } |
| 3214 | +} |
| 3215 | + |
| 3216 | +static void |
| 3217 | +garrow_round_to_multiple_options_get_property(GObject *object, |
| 3218 | + guint prop_id, |
| 3219 | + GValue *value, |
| 3220 | + GParamSpec *pspec) |
| 3221 | +{ |
| 3222 | + auto priv = GARROW_ROUND_TO_MULTIPLE_OPTIONS_GET_PRIVATE(object); |
| 3223 | + auto options = |
| 3224 | + garrow_round_to_multiple_options_get_raw( |
| 3225 | + GARROW_ROUND_TO_MULTIPLE_OPTIONS(object)); |
| 3226 | + |
| 3227 | + switch (prop_id) { |
| 3228 | + case PROP_ROUND_TO_MULTIPLE_OPTIONS_MULTIPLE: |
| 3229 | + g_value_set_object(value, priv->multiple); |
| 3230 | + break; |
| 3231 | + case PROP_ROUND_TO_MULTIPLE_OPTIONS_MODE: |
| 3232 | + g_value_set_enum(value, static_cast<GArrowRoundMode>(options->round_mode)); |
| 3233 | + break; |
| 3234 | + default: |
| 3235 | + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); |
| 3236 | + break; |
| 3237 | + } |
| 3238 | +} |
| 3239 | + |
| 3240 | +static void |
| 3241 | +garrow_round_to_multiple_options_init(GArrowRoundToMultipleOptions *object) |
| 3242 | +{ |
| 3243 | + auto function_options_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object); |
| 3244 | + auto options = new arrow::compute::RoundToMultipleOptions(); |
| 3245 | + function_options_priv->options = |
| 3246 | + static_cast<arrow::compute::FunctionOptions *>(options); |
| 3247 | + auto priv = GARROW_ROUND_TO_MULTIPLE_OPTIONS_GET_PRIVATE(object); |
| 3248 | + priv->multiple = garrow_scalar_new_raw(&(options->multiple)); |
| 3249 | +} |
| 3250 | + |
| 3251 | +static void |
| 3252 | +garrow_round_to_multiple_options_class_init( |
| 3253 | + GArrowRoundToMultipleOptionsClass *klass) |
| 3254 | +{ |
| 3255 | + auto gobject_class = G_OBJECT_CLASS(klass); |
| 3256 | + gobject_class->dispose = garrow_round_to_multiple_options_dispose; |
| 3257 | + gobject_class->set_property = garrow_round_to_multiple_options_set_property; |
| 3258 | + gobject_class->get_property = garrow_round_to_multiple_options_get_property; |
| 3259 | + |
| 3260 | + |
| 3261 | + arrow::compute::RoundToMultipleOptions options; |
| 3262 | + |
| 3263 | + GParamSpec *spec; |
| 3264 | + /** |
| 3265 | + * GArrowRoundToMultipleOptions:multiple: |
| 3266 | + * |
| 3267 | + * The rounding scale (multiple to round to). |
| 3268 | + * |
| 3269 | + * Should be a scalar of a type compatible with the argument to be rounded. |
| 3270 | + * For example, rounding a decimal value means a decimal multiple is |
| 3271 | + * required. Rounding a floating point or integer value means a floating |
| 3272 | + * point scalar is required. |
| 3273 | + * |
| 3274 | + * Since: 7.0.0 |
| 3275 | + */ |
| 3276 | + spec = g_param_spec_object("multiple", |
| 3277 | + "Multiple to round to", |
| 3278 | + "The round scale", |
| 3279 | + GARROW_TYPE_SCALAR, |
| 3280 | + static_cast<GParamFlags>(G_PARAM_READWRITE)); |
| 3281 | + g_object_class_install_property(gobject_class, |
| 3282 | + PROP_ROUND_TO_MULTIPLE_OPTIONS_MULTIPLE, |
| 3283 | + spec); |
| 3284 | + |
| 3285 | + /** |
| 3286 | + * GArrowRoundToMultipleOptions:mode: |
| 3287 | + * |
| 3288 | + * The rounding and tie-breaking mode. |
| 3289 | + * |
| 3290 | + * Since: 7.0.0 |
| 3291 | + */ |
| 3292 | + spec = g_param_spec_enum("mode", |
| 3293 | + "Mode", |
| 3294 | + "The rounding and tie-breaking mode", |
| 3295 | + GARROW_TYPE_ROUND_MODE, |
| 3296 | + static_cast<GArrowRoundMode>(options.round_mode), |
| 3297 | + static_cast<GParamFlags>(G_PARAM_READWRITE)); |
| 3298 | + g_object_class_install_property(gobject_class, |
| 3299 | + PROP_ROUND_TO_MULTIPLE_OPTIONS_MODE, |
| 3300 | + spec); |
| 3301 | +} |
| 3302 | + |
| 3303 | +/** |
| 3304 | + * garrow_round_to_multiple_options_new: |
| 3305 | + * |
| 3306 | + * Returns: A newly created #GArrowRoundToMultipleOptions. |
| 3307 | + * |
| 3308 | + * Since: 7.0.0 |
| 3309 | + */ |
| 3310 | +GArrowRoundToMultipleOptions * |
| 3311 | +garrow_round_to_multiple_options_new(void) |
| 3312 | +{ |
| 3313 | + return GARROW_ROUND_TO_MULTIPLE_OPTIONS( |
| 3314 | + g_object_new(GARROW_TYPE_ROUND_TO_MULTIPLE_OPTIONS, NULL)); |
| 3315 | +} |
| 3316 | + |
| 3317 | + |
3139 | 3318 | /** |
3140 | 3319 | * garrow_array_cast: |
3141 | 3320 | * @array: A #GArrowArray. |
@@ -4538,3 +4717,11 @@ garrow_round_options_get_raw(GArrowRoundOptions *options) |
4538 | 4717 | return static_cast<arrow::compute::RoundOptions *>( |
4539 | 4718 | garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options))); |
4540 | 4719 | } |
| 4720 | + |
| 4721 | + |
| 4722 | +arrow::compute::RoundToMultipleOptions * |
| 4723 | +garrow_round_to_multiple_options_get_raw(GArrowRoundToMultipleOptions *options) |
| 4724 | +{ |
| 4725 | + return static_cast<arrow::compute::RoundToMultipleOptions *>( |
| 4726 | + garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options))); |
| 4727 | +} |
0 commit comments