@@ -37,6 +37,8 @@ G_BEGIN_DECLS
37
37
* @title: Basic array classes
38
38
* @include: arrow-glib/arrow-glib.h
39
39
*
40
+ * #GArrowArrayStatistics is a class for statistics of an array.
41
+ *
40
42
* #GArrowArray is a base class for all array classes such as
41
43
* #GArrowBooleanArray.
42
44
*
@@ -364,6 +366,106 @@ garrow_equal_options_is_approx(GArrowEqualOptions *options)
364
366
return priv->approx ;
365
367
}
366
368
369
+ struct GArrowArrayStatisticsPrivate
370
+ {
371
+ arrow::ArrayStatistics statistics;
372
+ };
373
+
374
+ enum {
375
+ PROP_STATISTICS = 1 ,
376
+ };
377
+
378
+ G_DEFINE_TYPE_WITH_PRIVATE (GArrowArrayStatistics, garrow_array_statistics, G_TYPE_OBJECT)
379
+
380
+ #define GARROW_ARRAY_STATISTICS_GET_PRIVATE (object ) \
381
+ static_cast <GArrowArrayStatisticsPrivate *>( \
382
+ garrow_array_statistics_get_instance_private (GARROW_ARRAY_STATISTICS(object)))
383
+
384
+ static void
385
+ garrow_array_statistics_finalize(GObject *object)
386
+ {
387
+ auto priv = GARROW_ARRAY_STATISTICS_GET_PRIVATE (object);
388
+ priv->statistics .~ArrayStatistics ();
389
+ G_OBJECT_CLASS (garrow_array_statistics_parent_class)->finalize (object);
390
+ }
391
+
392
+ static void
393
+ garrow_array_statistics_set_property (GObject *object,
394
+ guint prop_id,
395
+ const GValue *value,
396
+ GParamSpec *pspec)
397
+ {
398
+ auto priv = GARROW_ARRAY_STATISTICS_GET_PRIVATE (object);
399
+
400
+ switch (prop_id) {
401
+ case PROP_STATISTICS:
402
+ priv->statistics = *static_cast <arrow::ArrayStatistics *>(g_value_get_pointer (value));
403
+ break ;
404
+ default :
405
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
406
+ break ;
407
+ }
408
+ }
409
+
410
+ static void
411
+ garrow_array_statistics_init (GArrowArrayStatistics *object)
412
+ {
413
+ auto priv = GARROW_ARRAY_STATISTICS_GET_PRIVATE (object);
414
+ new (&priv->statistics ) arrow::ArrayStatistics;
415
+ }
416
+
417
+ static void
418
+ garrow_array_statistics_class_init (GArrowArrayStatisticsClass *klass)
419
+ {
420
+ auto gobject_class = G_OBJECT_CLASS (klass);
421
+ gobject_class->finalize = garrow_array_statistics_finalize;
422
+ gobject_class->set_property = garrow_array_statistics_set_property;
423
+
424
+ auto spec = g_param_spec_pointer (
425
+ " statistics" ,
426
+ " Statistics" ,
427
+ " The raw arrow::ArrayStatistics *" ,
428
+ static_cast <GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
429
+ g_object_class_install_property (gobject_class, PROP_STATISTICS, spec);
430
+ }
431
+
432
+ /* *
433
+ * garrow_array_statistics_has_null_count:
434
+ * @statistics: A #GArrowArrayStatistics.
435
+ *
436
+ * Returns: %TRUE if @statistics has a valid null count value,
437
+ * %FALSE otherwise.
438
+ *
439
+ * Since: 20.0.0
440
+ */
441
+ gboolean
442
+ garrow_array_statistics_has_null_count (GArrowArrayStatistics *statistics)
443
+ {
444
+ auto priv = GARROW_ARRAY_STATISTICS_GET_PRIVATE (statistics);
445
+ return priv->statistics .null_count .has_value ();
446
+ }
447
+
448
+ /* *
449
+ * garrow_array_statistics_get_null_count:
450
+ * @statistics: A #GArrowArrayStatistics.
451
+ *
452
+ * Returns: 0 or larger value if @statistics has a valid null count value,
453
+ * -1 otherwise.
454
+ *
455
+ * Since: 20.0.0
456
+ */
457
+ gint64
458
+ garrow_array_statistics_get_null_count (GArrowArrayStatistics *statistics)
459
+ {
460
+ auto priv = GARROW_ARRAY_STATISTICS_GET_PRIVATE (statistics);
461
+ const auto &null_count = priv->statistics .null_count ;
462
+ if (null_count) {
463
+ return null_count.value ();
464
+ } else {
465
+ return -1 ;
466
+ }
467
+ }
468
+
367
469
typedef struct GArrowArrayPrivate_
368
470
{
369
471
std::shared_ptr<arrow::Array> array;
@@ -1049,6 +1151,27 @@ garrow_array_validate_full(GArrowArray *array, GError **error)
1049
1151
return garrow::check (error, arrow_array->ValidateFull (), " [array][validate-full]" );
1050
1152
}
1051
1153
1154
+ /* *
1155
+ * garrow_array_get_statistics:
1156
+ * @array: A #GArrowArray.
1157
+ *
1158
+ * Returns: (transfer full): The associated #GArrowArrayStatistics of @array,
1159
+ * %NULL if @array doesn't have any associated statistics.
1160
+ *
1161
+ * Since: 20.0.0
1162
+ */
1163
+ GArrowArrayStatistics *
1164
+ garrow_array_get_statistics (GArrowArray *array)
1165
+ {
1166
+ const auto arrow_array = garrow_array_get_raw (array);
1167
+ const auto &statistics = arrow_array->statistics ();
1168
+ if (statistics) {
1169
+ return garrow_array_statistics_new_raw (statistics.get ());
1170
+ } else {
1171
+ return nullptr ;
1172
+ }
1173
+ }
1174
+
1052
1175
G_DEFINE_TYPE (GArrowNullArray, garrow_null_array, GARROW_TYPE_ARRAY)
1053
1176
1054
1177
static void
@@ -3468,6 +3591,13 @@ garrow_equal_options_get_raw(GArrowEqualOptions *equal_options)
3468
3591
return &(priv->options );
3469
3592
}
3470
3593
3594
+ GArrowArrayStatistics *
3595
+ garrow_array_statistics_new_raw (arrow::ArrayStatistics *arrow_statistics)
3596
+ {
3597
+ return GARROW_ARRAY_STATISTICS (
3598
+ g_object_new (GARROW_TYPE_ARRAY_STATISTICS, " statistics" , arrow_statistics, nullptr ));
3599
+ }
3600
+
3471
3601
GArrowArray *
3472
3602
garrow_array_new_raw (std::shared_ptr<arrow::Array> *arrow_array)
3473
3603
{
0 commit comments