1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *   http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #include <arrow-glib/basic-array.hpp>
21 #include <arrow-glib/buffer.hpp>
22 #include <arrow-glib/data-type.hpp>
23 #include <arrow-glib/decimal.hpp>
24 #include <arrow-glib/error.hpp>
25 #include <arrow-glib/scalar.hpp>
26 
27 G_BEGIN_DECLS
28 
29 /**
30  * SECTION: scalar
31  * @section_id: scalar-classes
32  * @title: Scalar classes
33  * @include: arrow-glib/arrow-glib.h
34  *
35  * #GArrowScalar is a base class for all scalar classes such as
36  * #GArrowBooleanScalar.
37  *
38  * #GArrowNullScalar is a class for a null scalar.
39  *
40  * #GArrowBooleanScalar is a class for a boolean scalar.
41  *
42  * #GArrowInt8Scalar is a class for a 8-bit integer scalar.
43  *
44  * #GArrowInt16Scalar is a class for a 16-bit integer scalar.
45  *
46  * #GArrowInt32Scalar is a class for a 32-bit integer scalar.
47  *
48  * #GArrowInt64Scalar is a class for a 64-bit integer scalar.
49  *
50  * #GArrowUInt8Scalar is a class for a 8-bit unsigned integer scalar.
51  *
52  * #GArrowUInt16Scalar is a class for a 16-bit unsigned integer scalar.
53  *
54  * #GArrowUInt32Scalar is a class for a 32-bit unsigned integer scalar.
55  *
56  * #GArrowUInt64Scalar is a class for a 64-bit unsigned integer scalar.
57  *
58  * #GArrowFloatScalar is a class for a 32-bit floating point scalar.
59  *
60  * #GArrowDoubleScalar is a class for a 64-bit floating point scalar.
61  *
62  * #GArrowBaseBinaryScalar is a base class for all binary and string
63  * scalar classes such as #GArrowBinaryScalar.
64  *
65  * #GArrowBinaryScalar is a class for a binary scalar.
66  *
67  * #GArrowStringScalar is a class for an UTF-8 encoded string scalar.
68  *
69  * #GArrowLargeBinaryScalar is a class for a 64-bit offsets binary
70  * scalar.
71  *
72  * #GArrowLargeStringScalar is a class for a 64-bit offsets UTF-8
73  * encoded string scalar.
74  *
75  * #GArrowFixedSizeBinaryScalar is a class for a fixed-size binary
76  * scalar.
77  *
78  * #GArrowDate32Scalar is a class for the number of days since UNIX
79  * epoch in a 32-bit signed integer scalar.
80  *
81  * #GArrowDate64Scalar is a class for the number of milliseconds
82  * since UNIX epoch in a 64-bit signed integer scalar.
83  *
84  * #GArrowTime32Scalar is a class for the number of seconds or
85  * milliseconds since midnight in a 32-bit signed integer scalar.
86  *
87  * #GArrowTime64Scalar is a class for the number of microseconds or
88  * nanoseconds since midnight in a 64-bit signed integer scalar.
89  *
90  * #GArrowTimestampScalar is a class for the number of
91  * seconds/milliseconds/microseconds/nanoseconds since UNIX epoch in
92  * a 64-bit signed integer scalar.
93  *
94  * #GArrowDecimal128Scalar is a class for a 128-bit decimal scalar.
95  *
96  * #GArrowDecimal256Scalar is a class for a 256-bit decimal scalar.
97  *
98  * #GArrowBaseListScalar is a base class for all list scalar classes
99  * such as #GArrowListScalar.
100  *
101  * #GArrowListScalar is a class for a list scalar.
102  *
103  * #GArrowLargeListScalar is a class for a large list scalar.
104  *
105  * #GArrowMapScalar is a class for a map list scalar.
106  *
107  * #GArrowStructScalar is a class for a struct list scalar.
108  *
109  * #GArrowUnionScalar is a base class for all union scalar classes
110  * such as #GArrowSparseUnionScalar.
111  *
112  * #GArrowSparseUnionScalar is a class for a sparse union scalar.
113  *
114  * #GArrowDenseUnionScalar is a class for a dense union scalar.
115  *
116  * #GArrowExtensionScalar is a base class for user-defined extension
117  * scalar.
118  */
119 
120 typedef struct GArrowScalarPrivate_ {
121   std::shared_ptr<arrow::Scalar> scalar;
122   GArrowDataType *data_type;
123 } GArrowScalarPrivate;
124 
125 enum {
126   PROP_SCALAR = 1,
127   PROP_DATA_TYPE,
128 };
129 
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GArrowScalar,garrow_scalar,G_TYPE_OBJECT)130 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GArrowScalar,
131                                     garrow_scalar,
132                                     G_TYPE_OBJECT)
133 
134 #define GARROW_SCALAR_GET_PRIVATE(obj)            \
135   static_cast<GArrowScalarPrivate *>(             \
136     garrow_scalar_get_instance_private(           \
137       GARROW_SCALAR(obj)))
138 
139 static void
140 garrow_scalar_dispose(GObject *object)
141 {
142   auto priv = GARROW_SCALAR_GET_PRIVATE(object);
143 
144   if (priv->data_type) {
145     g_object_unref(priv->data_type);
146     priv->data_type = NULL;
147   }
148 
149   G_OBJECT_CLASS(garrow_scalar_parent_class)->dispose(object);
150 }
151 
152 static void
garrow_scalar_finalize(GObject * object)153 garrow_scalar_finalize(GObject *object)
154 {
155   auto priv = GARROW_SCALAR_GET_PRIVATE(object);
156 
157   priv->scalar.~shared_ptr();
158 
159   G_OBJECT_CLASS(garrow_scalar_parent_class)->finalize(object);
160 }
161 
162 static void
garrow_scalar_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)163 garrow_scalar_set_property(GObject *object,
164                            guint prop_id,
165                            const GValue *value,
166                            GParamSpec *pspec)
167 {
168   auto priv = GARROW_SCALAR_GET_PRIVATE(object);
169 
170   switch (prop_id) {
171   case PROP_SCALAR:
172     priv->scalar =
173       *static_cast<std::shared_ptr<arrow::Scalar> *>(g_value_get_pointer(value));
174     break;
175   case PROP_DATA_TYPE:
176     priv->data_type = GARROW_DATA_TYPE(g_value_dup_object(value));
177     break;
178   default:
179     G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
180     break;
181   }
182 }
183 
184 static void
garrow_scalar_init(GArrowScalar * object)185 garrow_scalar_init(GArrowScalar *object)
186 {
187   auto priv = GARROW_SCALAR_GET_PRIVATE(object);
188   new(&priv->scalar) std::shared_ptr<arrow::Scalar>;
189 }
190 
191 static void
garrow_scalar_class_init(GArrowScalarClass * klass)192 garrow_scalar_class_init(GArrowScalarClass *klass)
193 {
194   auto gobject_class = G_OBJECT_CLASS(klass);
195 
196   gobject_class->dispose      = garrow_scalar_dispose;
197   gobject_class->finalize     = garrow_scalar_finalize;
198   gobject_class->set_property = garrow_scalar_set_property;
199 
200   GParamSpec *spec;
201   spec = g_param_spec_pointer("scalar",
202                               "Scalar",
203                               "The raw std::shared<arrow::Scalar> *",
204                               static_cast<GParamFlags>(G_PARAM_WRITABLE |
205                                                        G_PARAM_CONSTRUCT_ONLY));
206   g_object_class_install_property(gobject_class, PROP_SCALAR, spec);
207 
208   /**
209    * GArrowScalar:data-type:
210    *
211    * The data type of the scalar.
212    *
213    * Since: 5.0.0
214    */
215   spec = g_param_spec_object("data-type",
216                              "Data type",
217                              "The data type of the scalar",
218                              GARROW_TYPE_DATA_TYPE,
219                              static_cast<GParamFlags>(G_PARAM_WRITABLE |
220                                                       G_PARAM_CONSTRUCT_ONLY));
221   g_object_class_install_property(gobject_class, PROP_DATA_TYPE, spec);
222 }
223 
224 /**
225  * garrow_scalar_parse:
226  * @data_type: A #GArrowDataType for the parsed scalar.
227  * @data: (array length=size): Data to be parsed.
228  * @size: The number of bytes of the data.
229  * @error: (nullable): Return location for a #GError or %NULL.
230  *
231  * Returns: (nullable) (transfer full):
232  *   A newly created #GArrowScalar if the data is parsed successfully,
233  *   %NULL otherwise.
234  *
235  * Since: 5.0.0
236  */
237 GArrowScalar *
garrow_scalar_parse(GArrowDataType * data_type,const guint8 * data,gsize size,GError ** error)238 garrow_scalar_parse(GArrowDataType *data_type,
239                     const guint8 *data,
240                     gsize size,
241                     GError **error)
242 {
243   const auto arrow_data_type = garrow_data_type_get_raw(data_type);
244   auto arrow_data =
245     arrow::util::string_view(reinterpret_cast<const char *>(data),
246                              size);
247   auto arrow_scalar_result = arrow::Scalar::Parse(arrow_data_type, arrow_data);
248   if (garrow::check(error, arrow_scalar_result, "[scalar][parse]")) {
249     auto arrow_scalar = *arrow_scalar_result;
250     return garrow_scalar_new_raw(&arrow_scalar,
251                                  "scalar", &arrow_scalar,
252                                  "data-type", data_type,
253                                  NULL);
254   } else {
255     return NULL;
256   }
257 }
258 
259 /**
260  * garrow_scalar_get_data_type:
261  * @scalar: A #GArrowScalar.
262  *
263  * Returns: (transfer none): The #GArrowDataType for the scalar.
264  *
265  * Since: 5.0.0
266  */
267 GArrowDataType *
garrow_scalar_get_data_type(GArrowScalar * scalar)268 garrow_scalar_get_data_type(GArrowScalar *scalar)
269 {
270   auto priv = GARROW_SCALAR_GET_PRIVATE(scalar);
271   if (!priv->data_type) {
272     priv->data_type = garrow_data_type_new_raw(&(priv->scalar->type));
273   }
274   return priv->data_type;
275 }
276 
277 /**
278  * garrow_scalar_is_valid:
279  * @scalar: A #GArrowScalar.
280  *
281  * Returns: %TRUE if the scalar is valid, %FALSE otherwise.
282  *
283  * Since: 5.0.0
284  */
285 gboolean
garrow_scalar_is_valid(GArrowScalar * scalar)286 garrow_scalar_is_valid(GArrowScalar *scalar)
287 {
288   const auto arrow_scalar = garrow_scalar_get_raw(scalar);
289   return arrow_scalar->is_valid;
290 }
291 
292 /**
293  * garrow_scalar_equal:
294  * @scalar: A #GArrowScalar.
295  * @other_scalar: A #GArrowScalar to be compared.
296  *
297  * Returns: %TRUE if both of them have the same data, %FALSE
298  *   otherwise.
299  *
300  * Since: 5.0.0
301  */
302 gboolean
garrow_scalar_equal(GArrowScalar * scalar,GArrowScalar * other_scalar)303 garrow_scalar_equal(GArrowScalar *scalar,
304                     GArrowScalar *other_scalar)
305 {
306   return garrow_scalar_equal_options(scalar, other_scalar, NULL);
307 }
308 
309 /**
310  * garrow_scalar_equal_options:
311  * @scalar: A #GArrowScalar.
312  * @other_scalar: A #GArrowScalar to be compared.
313  * @options: (nullable): A #GArrowEqualOptions.
314  *
315  * Returns: %TRUE if both of them have the same data, %FALSE
316  *   otherwise.
317  *
318  * Since: 5.0.0
319  */
320 gboolean
garrow_scalar_equal_options(GArrowScalar * scalar,GArrowScalar * other_scalar,GArrowEqualOptions * options)321 garrow_scalar_equal_options(GArrowScalar *scalar,
322                             GArrowScalar *other_scalar,
323                             GArrowEqualOptions *options)
324 {
325   const auto arrow_scalar = garrow_scalar_get_raw(scalar);
326   const auto arrow_other_scalar = garrow_scalar_get_raw(other_scalar);
327   if (options) {
328     auto is_approx = garrow_equal_options_is_approx(options);
329     const auto arrow_options = garrow_equal_options_get_raw(options);
330     if (is_approx) {
331       return arrow_scalar->ApproxEquals(*arrow_other_scalar, *arrow_options);
332     } else {
333       return arrow_scalar->Equals(arrow_other_scalar, *arrow_options);
334     }
335   } else {
336     return arrow_scalar->Equals(arrow_other_scalar);
337   }
338 }
339 
340 /**
341  * garrow_scalar_to_string:
342  * @scalar: A #GArrowScalar.
343  *
344  * Returns: The string representation of the scalar.
345  *
346  *   It should be freed with g_free() when no longer needed.
347  *
348  * Since: 5.0.0
349  */
350 gchar *
garrow_scalar_to_string(GArrowScalar * scalar)351 garrow_scalar_to_string(GArrowScalar *scalar)
352 {
353   const auto arrow_scalar = garrow_scalar_get_raw(scalar);
354   return g_strdup(arrow_scalar->ToString().c_str());
355 }
356 
357 /**
358  * garrow_scalar_cast:
359  * @scalar: A #GArrowScalar.
360  * @data_type: A #GArrowDataType of the casted scalar.
361  * @options: (nullable): A #GArrowCastOptions.
362  * @error: (nullable): Return location for a #GError or %NULL.
363  *
364  * Returns: (nullable) (transfer full):
365  *   A newly created casted scalar on success, %NULL on error.
366  *
367  * Since: 5.0.0
368  */
369 GArrowScalar *
garrow_scalar_cast(GArrowScalar * scalar,GArrowDataType * data_type,GArrowCastOptions * options,GError ** error)370 garrow_scalar_cast(GArrowScalar *scalar,
371                    GArrowDataType *data_type,
372                    GArrowCastOptions *options,
373                    GError **error)
374 {
375   const auto arrow_scalar = garrow_scalar_get_raw(scalar);
376   const auto arrow_data_type = garrow_data_type_get_raw(data_type);
377   auto arrow_casted_scalar_result = arrow_scalar->CastTo(arrow_data_type);
378   if (garrow::check(error, arrow_casted_scalar_result, "[scalar][cast]")) {
379     auto arrow_casted_scalar = *arrow_casted_scalar_result;
380     return garrow_scalar_new_raw(&arrow_casted_scalar,
381                                  "scalar", &arrow_casted_scalar,
382                                  "data-type", data_type,
383                                  NULL);
384   } else {
385     return NULL;
386   }
387 }
388 
389 
G_DEFINE_TYPE(GArrowNullScalar,garrow_null_scalar,GARROW_TYPE_SCALAR)390 G_DEFINE_TYPE(GArrowNullScalar,
391               garrow_null_scalar,
392               GARROW_TYPE_SCALAR)
393 
394 static void
395 garrow_null_scalar_init(GArrowNullScalar *object)
396 {
397 }
398 
399 static void
garrow_null_scalar_class_init(GArrowNullScalarClass * klass)400 garrow_null_scalar_class_init(GArrowNullScalarClass *klass)
401 {
402 }
403 
404 /**
405  * garrow_null_scalar_new:
406  *
407  * Returns: A newly created #GArrowNullScalar.
408  *
409  * Since: 5.0.0
410  */
411 GArrowNullScalar *
garrow_null_scalar_new(void)412 garrow_null_scalar_new(void)
413 {
414   auto arrow_scalar =
415     std::static_pointer_cast<arrow::Scalar>(
416       std::make_shared<arrow::NullScalar>());
417   return GARROW_NULL_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
418 }
419 
420 
G_DEFINE_TYPE(GArrowBooleanScalar,garrow_boolean_scalar,GARROW_TYPE_SCALAR)421 G_DEFINE_TYPE(GArrowBooleanScalar,
422               garrow_boolean_scalar,
423               GARROW_TYPE_SCALAR)
424 
425 static void
426 garrow_boolean_scalar_init(GArrowBooleanScalar *object)
427 {
428 }
429 
430 static void
garrow_boolean_scalar_class_init(GArrowBooleanScalarClass * klass)431 garrow_boolean_scalar_class_init(GArrowBooleanScalarClass *klass)
432 {
433 }
434 
435 /**
436  * garrow_boolean_scalar_new:
437  * @value: The value of this scalar.
438  *
439  * Returns: A newly created #GArrowBooleanScalar.
440  *
441  * Since: 5.0.0
442  */
443 GArrowBooleanScalar *
garrow_boolean_scalar_new(gboolean value)444 garrow_boolean_scalar_new(gboolean value)
445 {
446   auto arrow_scalar =
447     std::static_pointer_cast<arrow::Scalar>(
448       std::make_shared<arrow::BooleanScalar>(value));
449   return GARROW_BOOLEAN_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
450 }
451 
452 /**
453  * garrow_boolean_scalar_get_value:
454  * @scalar: A #GArrowBooleanScalar.
455  *
456  * Returns: The value of this scalar.
457  *
458  * Since: 5.0.0
459  */
460 gboolean
garrow_boolean_scalar_get_value(GArrowBooleanScalar * scalar)461 garrow_boolean_scalar_get_value(GArrowBooleanScalar *scalar)
462 {
463   const auto arrow_scalar =
464     std::static_pointer_cast<arrow::BooleanScalar>(
465       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
466   return arrow_scalar->value;
467 }
468 
469 
G_DEFINE_TYPE(GArrowInt8Scalar,garrow_int8_scalar,GARROW_TYPE_SCALAR)470 G_DEFINE_TYPE(GArrowInt8Scalar,
471               garrow_int8_scalar,
472               GARROW_TYPE_SCALAR)
473 
474 static void
475 garrow_int8_scalar_init(GArrowInt8Scalar *object)
476 {
477 }
478 
479 static void
garrow_int8_scalar_class_init(GArrowInt8ScalarClass * klass)480 garrow_int8_scalar_class_init(GArrowInt8ScalarClass *klass)
481 {
482 }
483 
484 /**
485  * garrow_int8_scalar_new:
486  * @value: The value of this scalar.
487  *
488  * Returns: A newly created #GArrowInt8Scalar.
489  *
490  * Since: 5.0.0
491  */
492 GArrowInt8Scalar *
garrow_int8_scalar_new(gint8 value)493 garrow_int8_scalar_new(gint8 value)
494 {
495   auto arrow_scalar =
496     std::static_pointer_cast<arrow::Scalar>(
497       std::make_shared<arrow::Int8Scalar>(value));
498   return GARROW_INT8_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
499 }
500 
501 /**
502  * garrow_int8_scalar_get_value:
503  * @scalar: A #GArrowInt8Scalar.
504  *
505  * Returns: The value of this scalar.
506  *
507  * Since: 5.0.0
508  */
509 gint8
garrow_int8_scalar_get_value(GArrowInt8Scalar * scalar)510 garrow_int8_scalar_get_value(GArrowInt8Scalar *scalar)
511 {
512   const auto arrow_scalar =
513     std::static_pointer_cast<arrow::Int8Scalar>(
514       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
515   return arrow_scalar->value;
516 }
517 
518 
G_DEFINE_TYPE(GArrowInt16Scalar,garrow_int16_scalar,GARROW_TYPE_SCALAR)519 G_DEFINE_TYPE(GArrowInt16Scalar,
520               garrow_int16_scalar,
521               GARROW_TYPE_SCALAR)
522 
523 static void
524 garrow_int16_scalar_init(GArrowInt16Scalar *object)
525 {
526 }
527 
528 static void
garrow_int16_scalar_class_init(GArrowInt16ScalarClass * klass)529 garrow_int16_scalar_class_init(GArrowInt16ScalarClass *klass)
530 {
531 }
532 
533 /**
534  * garrow_int16_scalar_new:
535  * @value: The value of this scalar.
536  *
537  * Returns: A newly created #GArrowInt16Scalar.
538  *
539  * Since: 5.0.0
540  */
541 GArrowInt16Scalar *
garrow_int16_scalar_new(gint16 value)542 garrow_int16_scalar_new(gint16 value)
543 {
544   auto arrow_scalar =
545     std::static_pointer_cast<arrow::Scalar>(
546       std::make_shared<arrow::Int16Scalar>(value));
547   return GARROW_INT16_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
548 }
549 
550 /**
551  * garrow_int16_scalar_get_value:
552  * @scalar: A #GArrowInt16Scalar.
553  *
554  * Returns: The value of this scalar.
555  *
556  * Since: 5.0.0
557  */
558 gint16
garrow_int16_scalar_get_value(GArrowInt16Scalar * scalar)559 garrow_int16_scalar_get_value(GArrowInt16Scalar *scalar)
560 {
561   const auto arrow_scalar =
562     std::static_pointer_cast<arrow::Int16Scalar>(
563       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
564   return arrow_scalar->value;
565 }
566 
567 
G_DEFINE_TYPE(GArrowInt32Scalar,garrow_int32_scalar,GARROW_TYPE_SCALAR)568 G_DEFINE_TYPE(GArrowInt32Scalar,
569               garrow_int32_scalar,
570               GARROW_TYPE_SCALAR)
571 
572 static void
573 garrow_int32_scalar_init(GArrowInt32Scalar *object)
574 {
575 }
576 
577 static void
garrow_int32_scalar_class_init(GArrowInt32ScalarClass * klass)578 garrow_int32_scalar_class_init(GArrowInt32ScalarClass *klass)
579 {
580 }
581 
582 /**
583  * garrow_int32_scalar_new:
584  * @value: The value of this scalar.
585  *
586  * Returns: A newly created #GArrowInt32Scalar.
587  *
588  * Since: 5.0.0
589  */
590 GArrowInt32Scalar *
garrow_int32_scalar_new(gint32 value)591 garrow_int32_scalar_new(gint32 value)
592 {
593   auto arrow_scalar =
594     std::static_pointer_cast<arrow::Scalar>(
595       std::make_shared<arrow::Int32Scalar>(value));
596   return GARROW_INT32_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
597 }
598 
599 /**
600  * garrow_int32_scalar_get_value:
601  * @scalar: A #GArrowInt32Scalar.
602  *
603  * Returns: The value of this scalar.
604  *
605  * Since: 5.0.0
606  */
607 gint32
garrow_int32_scalar_get_value(GArrowInt32Scalar * scalar)608 garrow_int32_scalar_get_value(GArrowInt32Scalar *scalar)
609 {
610   const auto arrow_scalar =
611     std::static_pointer_cast<arrow::Int32Scalar>(
612       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
613   return arrow_scalar->value;
614 }
615 
616 
G_DEFINE_TYPE(GArrowInt64Scalar,garrow_int64_scalar,GARROW_TYPE_SCALAR)617 G_DEFINE_TYPE(GArrowInt64Scalar,
618               garrow_int64_scalar,
619               GARROW_TYPE_SCALAR)
620 
621 static void
622 garrow_int64_scalar_init(GArrowInt64Scalar *object)
623 {
624 }
625 
626 static void
garrow_int64_scalar_class_init(GArrowInt64ScalarClass * klass)627 garrow_int64_scalar_class_init(GArrowInt64ScalarClass *klass)
628 {
629 }
630 
631 /**
632  * garrow_int64_scalar_new:
633  * @value: The value of this scalar.
634  *
635  * Returns: A newly created #GArrowInt64Scalar.
636  *
637  * Since: 5.0.0
638  */
639 GArrowInt64Scalar *
garrow_int64_scalar_new(gint64 value)640 garrow_int64_scalar_new(gint64 value)
641 {
642   auto arrow_scalar =
643     std::static_pointer_cast<arrow::Scalar>(
644       std::make_shared<arrow::Int64Scalar>(value));
645   return GARROW_INT64_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
646 }
647 
648 /**
649  * garrow_int64_scalar_get_value:
650  * @scalar: A #GArrowInt64Scalar.
651  *
652  * Returns: The value of this scalar.
653  *
654  * Since: 5.0.0
655  */
656 gint64
garrow_int64_scalar_get_value(GArrowInt64Scalar * scalar)657 garrow_int64_scalar_get_value(GArrowInt64Scalar *scalar)
658 {
659   const auto arrow_scalar =
660     std::static_pointer_cast<arrow::Int64Scalar>(
661       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
662   return arrow_scalar->value;
663 }
664 
665 
G_DEFINE_TYPE(GArrowUInt8Scalar,garrow_uint8_scalar,GARROW_TYPE_SCALAR)666 G_DEFINE_TYPE(GArrowUInt8Scalar,
667               garrow_uint8_scalar,
668               GARROW_TYPE_SCALAR)
669 
670 static void
671 garrow_uint8_scalar_init(GArrowUInt8Scalar *object)
672 {
673 }
674 
675 static void
garrow_uint8_scalar_class_init(GArrowUInt8ScalarClass * klass)676 garrow_uint8_scalar_class_init(GArrowUInt8ScalarClass *klass)
677 {
678 }
679 
680 /**
681  * garrow_uint8_scalar_new:
682  * @value: The value of this scalar.
683  *
684  * Returns: A newly created #GArrowUInt8Scalar.
685  *
686  * Since: 5.0.0
687  */
688 GArrowUInt8Scalar *
garrow_uint8_scalar_new(guint8 value)689 garrow_uint8_scalar_new(guint8 value)
690 {
691   auto arrow_scalar =
692     std::static_pointer_cast<arrow::Scalar>(
693       std::make_shared<arrow::UInt8Scalar>(value));
694   return GARROW_UINT8_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
695 }
696 
697 /**
698  * garrow_uint8_scalar_get_value:
699  * @scalar: A #GArrowUInt8Scalar.
700  *
701  * Returns: The value of this scalar.
702  *
703  * Since: 5.0.0
704  */
705 guint8
garrow_uint8_scalar_get_value(GArrowUInt8Scalar * scalar)706 garrow_uint8_scalar_get_value(GArrowUInt8Scalar *scalar)
707 {
708   const auto arrow_scalar =
709     std::static_pointer_cast<arrow::UInt8Scalar>(
710       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
711   return arrow_scalar->value;
712 }
713 
714 
G_DEFINE_TYPE(GArrowUInt16Scalar,garrow_uint16_scalar,GARROW_TYPE_SCALAR)715 G_DEFINE_TYPE(GArrowUInt16Scalar,
716               garrow_uint16_scalar,
717               GARROW_TYPE_SCALAR)
718 
719 static void
720 garrow_uint16_scalar_init(GArrowUInt16Scalar *object)
721 {
722 }
723 
724 static void
garrow_uint16_scalar_class_init(GArrowUInt16ScalarClass * klass)725 garrow_uint16_scalar_class_init(GArrowUInt16ScalarClass *klass)
726 {
727 }
728 
729 /**
730  * garrow_uint16_scalar_new:
731  * @value: The value of this scalar.
732  *
733  * Returns: A newly created #GArrowUInt16Scalar.
734  *
735  * Since: 5.0.0
736  */
737 GArrowUInt16Scalar *
garrow_uint16_scalar_new(guint16 value)738 garrow_uint16_scalar_new(guint16 value)
739 {
740   auto arrow_scalar =
741     std::static_pointer_cast<arrow::Scalar>(
742       std::make_shared<arrow::UInt16Scalar>(value));
743   return GARROW_UINT16_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
744 }
745 
746 /**
747  * garrow_uint16_scalar_get_value:
748  * @scalar: A #GArrowUInt16Scalar.
749  *
750  * Returns: The value of this scalar.
751  *
752  * Since: 5.0.0
753  */
754 guint16
garrow_uint16_scalar_get_value(GArrowUInt16Scalar * scalar)755 garrow_uint16_scalar_get_value(GArrowUInt16Scalar *scalar)
756 {
757   const auto arrow_scalar =
758     std::static_pointer_cast<arrow::UInt16Scalar>(
759       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
760   return arrow_scalar->value;
761 }
762 
763 
G_DEFINE_TYPE(GArrowUInt32Scalar,garrow_uint32_scalar,GARROW_TYPE_SCALAR)764 G_DEFINE_TYPE(GArrowUInt32Scalar,
765               garrow_uint32_scalar,
766               GARROW_TYPE_SCALAR)
767 
768 static void
769 garrow_uint32_scalar_init(GArrowUInt32Scalar *object)
770 {
771 }
772 
773 static void
garrow_uint32_scalar_class_init(GArrowUInt32ScalarClass * klass)774 garrow_uint32_scalar_class_init(GArrowUInt32ScalarClass *klass)
775 {
776 }
777 
778 /**
779  * garrow_uint32_scalar_new:
780  * @value: The value of this scalar.
781  *
782  * Returns: A newly created #GArrowUInt32Scalar.
783  *
784  * Since: 5.0.0
785  */
786 GArrowUInt32Scalar *
garrow_uint32_scalar_new(guint32 value)787 garrow_uint32_scalar_new(guint32 value)
788 {
789   auto arrow_scalar =
790     std::static_pointer_cast<arrow::Scalar>(
791       std::make_shared<arrow::UInt32Scalar>(value));
792   return GARROW_UINT32_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
793 }
794 
795 /**
796  * garrow_uint32_scalar_get_value:
797  * @scalar: A #GArrowUInt32Scalar.
798  *
799  * Returns: The value of this scalar.
800  *
801  * Since: 5.0.0
802  */
803 guint32
garrow_uint32_scalar_get_value(GArrowUInt32Scalar * scalar)804 garrow_uint32_scalar_get_value(GArrowUInt32Scalar *scalar)
805 {
806   const auto arrow_scalar =
807     std::static_pointer_cast<arrow::UInt32Scalar>(
808       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
809   return arrow_scalar->value;
810 }
811 
812 
G_DEFINE_TYPE(GArrowUInt64Scalar,garrow_uint64_scalar,GARROW_TYPE_SCALAR)813 G_DEFINE_TYPE(GArrowUInt64Scalar,
814               garrow_uint64_scalar,
815               GARROW_TYPE_SCALAR)
816 
817 static void
818 garrow_uint64_scalar_init(GArrowUInt64Scalar *object)
819 {
820 }
821 
822 static void
garrow_uint64_scalar_class_init(GArrowUInt64ScalarClass * klass)823 garrow_uint64_scalar_class_init(GArrowUInt64ScalarClass *klass)
824 {
825 }
826 
827 /**
828  * garrow_uint64_scalar_new:
829  * @value: The value of this scalar.
830  *
831  * Returns: A newly created #GArrowUInt64Scalar.
832  *
833  * Since: 5.0.0
834  */
835 GArrowUInt64Scalar *
garrow_uint64_scalar_new(guint64 value)836 garrow_uint64_scalar_new(guint64 value)
837 {
838   auto arrow_scalar =
839     std::static_pointer_cast<arrow::Scalar>(
840       std::make_shared<arrow::UInt64Scalar>(value));
841   return GARROW_UINT64_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
842 }
843 
844 /**
845  * garrow_uint64_scalar_get_value:
846  * @scalar: A #GArrowUInt64Scalar.
847  *
848  * Returns: The value of this scalar.
849  *
850  * Since: 5.0.0
851  */
852 guint64
garrow_uint64_scalar_get_value(GArrowUInt64Scalar * scalar)853 garrow_uint64_scalar_get_value(GArrowUInt64Scalar *scalar)
854 {
855   const auto arrow_scalar =
856     std::static_pointer_cast<arrow::UInt64Scalar>(
857       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
858   return arrow_scalar->value;
859 }
860 
861 
G_DEFINE_TYPE(GArrowFloatScalar,garrow_float_scalar,GARROW_TYPE_SCALAR)862 G_DEFINE_TYPE(GArrowFloatScalar,
863               garrow_float_scalar,
864               GARROW_TYPE_SCALAR)
865 
866 static void
867 garrow_float_scalar_init(GArrowFloatScalar *object)
868 {
869 }
870 
871 static void
garrow_float_scalar_class_init(GArrowFloatScalarClass * klass)872 garrow_float_scalar_class_init(GArrowFloatScalarClass *klass)
873 {
874 }
875 
876 /**
877  * garrow_float_scalar_new:
878  * @value: The value of this scalar.
879  *
880  * Returns: A newly created #GArrowFloatScalar.
881  *
882  * Since: 5.0.0
883  */
884 GArrowFloatScalar *
garrow_float_scalar_new(gfloat value)885 garrow_float_scalar_new(gfloat value)
886 {
887   auto arrow_scalar =
888     std::static_pointer_cast<arrow::Scalar>(
889       std::make_shared<arrow::FloatScalar>(value));
890   return GARROW_FLOAT_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
891 }
892 
893 /**
894  * garrow_float_scalar_get_value:
895  * @scalar: A #GArrowFloatScalar.
896  *
897  * Returns: The value of this scalar.
898  *
899  * Since: 5.0.0
900  */
901 gfloat
garrow_float_scalar_get_value(GArrowFloatScalar * scalar)902 garrow_float_scalar_get_value(GArrowFloatScalar *scalar)
903 {
904   const auto arrow_scalar =
905     std::static_pointer_cast<arrow::FloatScalar>(
906       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
907   return arrow_scalar->value;
908 }
909 
910 
G_DEFINE_TYPE(GArrowDoubleScalar,garrow_double_scalar,GARROW_TYPE_SCALAR)911 G_DEFINE_TYPE(GArrowDoubleScalar,
912               garrow_double_scalar,
913               GARROW_TYPE_SCALAR)
914 
915 static void
916 garrow_double_scalar_init(GArrowDoubleScalar *object)
917 {
918 }
919 
920 static void
garrow_double_scalar_class_init(GArrowDoubleScalarClass * klass)921 garrow_double_scalar_class_init(GArrowDoubleScalarClass *klass)
922 {
923 }
924 
925 /**
926  * garrow_double_scalar_new:
927  * @value: The value of this scalar.
928  *
929  * Returns: A newly created #GArrowDoubleScalar.
930  *
931  * Since: 5.0.0
932  */
933 GArrowDoubleScalar *
garrow_double_scalar_new(gdouble value)934 garrow_double_scalar_new(gdouble value)
935 {
936   auto arrow_scalar =
937     std::static_pointer_cast<arrow::Scalar>(
938       std::make_shared<arrow::DoubleScalar>(value));
939   return GARROW_DOUBLE_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
940 }
941 
942 /**
943  * garrow_double_scalar_get_value:
944  * @scalar: A #GArrowDoubleScalar.
945  *
946  * Returns: The value of this scalar.
947  *
948  * Since: 5.0.0
949  */
950 gdouble
garrow_double_scalar_get_value(GArrowDoubleScalar * scalar)951 garrow_double_scalar_get_value(GArrowDoubleScalar *scalar)
952 {
953   const auto arrow_scalar =
954     std::static_pointer_cast<arrow::DoubleScalar>(
955       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
956   return arrow_scalar->value;
957 }
958 
959 
960 typedef struct GArrowBaseBinaryScalarPrivate_ {
961   GArrowBuffer *value;
962 } GArrowBaseBinaryScalarPrivate;
963 
964 enum {
965   PROP_VALUE = 1,
966 };
967 
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GArrowBaseBinaryScalar,garrow_base_binary_scalar,GARROW_TYPE_SCALAR)968 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GArrowBaseBinaryScalar,
969                                     garrow_base_binary_scalar,
970                                     GARROW_TYPE_SCALAR)
971 
972 #define GARROW_BASE_BINARY_SCALAR_GET_PRIVATE(obj)            \
973   static_cast<GArrowBaseBinaryScalarPrivate *>(               \
974     garrow_base_binary_scalar_get_instance_private(           \
975       GARROW_BASE_BINARY_SCALAR(obj)))
976 
977 static void
978 garrow_base_binary_scalar_dispose(GObject *object)
979 {
980   auto priv = GARROW_BASE_BINARY_SCALAR_GET_PRIVATE(object);
981 
982   if (priv->value) {
983     g_object_unref(priv->value);
984     priv->value = NULL;
985   }
986 
987   G_OBJECT_CLASS(garrow_base_binary_scalar_parent_class)->dispose(object);
988 }
989 
990 static void
garrow_base_binary_scalar_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)991 garrow_base_binary_scalar_set_property(GObject *object,
992                                        guint prop_id,
993                                        const GValue *value,
994                                        GParamSpec *pspec)
995 {
996   auto priv = GARROW_BASE_BINARY_SCALAR_GET_PRIVATE(object);
997 
998   switch (prop_id) {
999   case PROP_VALUE:
1000     priv->value = GARROW_BUFFER(g_value_dup_object(value));
1001     break;
1002   default:
1003     G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1004     break;
1005   }
1006 }
1007 
1008 static void
garrow_base_binary_scalar_init(GArrowBaseBinaryScalar * object)1009 garrow_base_binary_scalar_init(GArrowBaseBinaryScalar *object)
1010 {
1011 }
1012 
1013 static void
garrow_base_binary_scalar_class_init(GArrowBaseBinaryScalarClass * klass)1014 garrow_base_binary_scalar_class_init(GArrowBaseBinaryScalarClass *klass)
1015 {
1016   auto gobject_class = G_OBJECT_CLASS(klass);
1017   gobject_class->dispose      = garrow_base_binary_scalar_dispose;
1018   gobject_class->set_property = garrow_base_binary_scalar_set_property;
1019 
1020   GParamSpec *spec;
1021   /**
1022    * GArrowBaseBinaryScalar:value:
1023    *
1024    * The value of the scalar.
1025    *
1026    * Since: 5.0.0
1027    */
1028   spec = g_param_spec_object("value",
1029                              "Value",
1030                              "The value of the scalar",
1031                              GARROW_TYPE_BUFFER,
1032                              static_cast<GParamFlags>(G_PARAM_WRITABLE |
1033                                                       G_PARAM_CONSTRUCT_ONLY));
1034   g_object_class_install_property(gobject_class, PROP_VALUE, spec);
1035 }
1036 
1037 G_END_DECLS
1038 template<typename ArrowBinaryScalarType>
1039 GArrowScalar *
garrow_base_binary_scalar_new(GArrowBuffer * value)1040 garrow_base_binary_scalar_new(GArrowBuffer *value)
1041 {
1042   auto arrow_value = garrow_buffer_get_raw(value);
1043   auto arrow_scalar =
1044     std::static_pointer_cast<arrow::Scalar>(
1045       std::make_shared<ArrowBinaryScalarType>(arrow_value));
1046   return garrow_scalar_new_raw(&arrow_scalar,
1047                                "scalar", &arrow_scalar,
1048                                "value", value,
1049                                NULL);
1050 }
1051 G_BEGIN_DECLS
1052 
1053 /**
1054  * garrow_base_binary_scalar_get_value:
1055  * @scalar: A #GArrowBaseBinaryScalar.
1056  *
1057  * Returns: (transfer none): The value of this scalar.
1058  *
1059  * Since: 5.0.0
1060  */
1061 GArrowBuffer *
garrow_base_binary_scalar_get_value(GArrowBaseBinaryScalar * scalar)1062 garrow_base_binary_scalar_get_value(GArrowBaseBinaryScalar *scalar)
1063 {
1064   auto priv = GARROW_BASE_BINARY_SCALAR_GET_PRIVATE(scalar);
1065   if (!priv->value) {
1066     const auto arrow_scalar =
1067       std::static_pointer_cast<arrow::BaseBinaryScalar>(
1068         garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
1069     priv->value = garrow_buffer_new_raw(&(arrow_scalar->value));
1070   }
1071   return priv->value;
1072 }
1073 
1074 
G_DEFINE_TYPE(GArrowBinaryScalar,garrow_binary_scalar,GARROW_TYPE_BASE_BINARY_SCALAR)1075 G_DEFINE_TYPE(GArrowBinaryScalar,
1076               garrow_binary_scalar,
1077               GARROW_TYPE_BASE_BINARY_SCALAR)
1078 
1079 static void
1080 garrow_binary_scalar_init(GArrowBinaryScalar *object)
1081 {
1082 }
1083 
1084 static void
garrow_binary_scalar_class_init(GArrowBinaryScalarClass * klass)1085 garrow_binary_scalar_class_init(GArrowBinaryScalarClass *klass)
1086 {
1087 }
1088 
1089 /**
1090  * garrow_binary_scalar_new:
1091  * @value: The value of this scalar.
1092  *
1093  * Returns: A newly created #GArrowBinaryScalar.
1094  *
1095  * Since: 5.0.0
1096  */
1097 GArrowBinaryScalar *
garrow_binary_scalar_new(GArrowBuffer * value)1098 garrow_binary_scalar_new(GArrowBuffer *value)
1099 {
1100   return GARROW_BINARY_SCALAR(
1101     garrow_base_binary_scalar_new<arrow::BinaryScalar>(value));
1102 }
1103 
1104 
G_DEFINE_TYPE(GArrowStringScalar,garrow_string_scalar,GARROW_TYPE_BASE_BINARY_SCALAR)1105 G_DEFINE_TYPE(GArrowStringScalar,
1106               garrow_string_scalar,
1107               GARROW_TYPE_BASE_BINARY_SCALAR)
1108 
1109 static void
1110 garrow_string_scalar_init(GArrowStringScalar *object)
1111 {
1112 }
1113 
1114 static void
garrow_string_scalar_class_init(GArrowStringScalarClass * klass)1115 garrow_string_scalar_class_init(GArrowStringScalarClass *klass)
1116 {
1117 }
1118 
1119 /**
1120  * garrow_string_scalar_new:
1121  * @value: The value of this scalar.
1122  *
1123  * Returns: A newly created #GArrowStringScalar.
1124  *
1125  * Since: 5.0.0
1126  */
1127 GArrowStringScalar *
garrow_string_scalar_new(GArrowBuffer * value)1128 garrow_string_scalar_new(GArrowBuffer *value)
1129 {
1130   return GARROW_STRING_SCALAR(
1131     garrow_base_binary_scalar_new<arrow::StringScalar>(value));
1132 }
1133 
1134 
G_DEFINE_TYPE(GArrowLargeBinaryScalar,garrow_large_binary_scalar,GARROW_TYPE_BASE_BINARY_SCALAR)1135 G_DEFINE_TYPE(GArrowLargeBinaryScalar,
1136               garrow_large_binary_scalar,
1137               GARROW_TYPE_BASE_BINARY_SCALAR)
1138 
1139 static void
1140 garrow_large_binary_scalar_init(GArrowLargeBinaryScalar *object)
1141 {
1142 }
1143 
1144 static void
garrow_large_binary_scalar_class_init(GArrowLargeBinaryScalarClass * klass)1145 garrow_large_binary_scalar_class_init(GArrowLargeBinaryScalarClass *klass)
1146 {
1147 }
1148 
1149 /**
1150  * garrow_large_binary_scalar_new:
1151  * @value: The value of this scalar.
1152  *
1153  * Returns: A newly created #GArrowLargeBinaryScalar.
1154  *
1155  * Since: 5.0.0
1156  */
1157 GArrowLargeBinaryScalar *
garrow_large_binary_scalar_new(GArrowBuffer * value)1158 garrow_large_binary_scalar_new(GArrowBuffer *value)
1159 {
1160   return GARROW_LARGE_BINARY_SCALAR(
1161     garrow_base_binary_scalar_new<arrow::LargeBinaryScalar>(value));
1162 }
1163 
1164 
G_DEFINE_TYPE(GArrowLargeStringScalar,garrow_large_string_scalar,GARROW_TYPE_BASE_BINARY_SCALAR)1165 G_DEFINE_TYPE(GArrowLargeStringScalar,
1166               garrow_large_string_scalar,
1167               GARROW_TYPE_BASE_BINARY_SCALAR)
1168 
1169 static void
1170 garrow_large_string_scalar_init(GArrowLargeStringScalar *object)
1171 {
1172 }
1173 
1174 static void
garrow_large_string_scalar_class_init(GArrowLargeStringScalarClass * klass)1175 garrow_large_string_scalar_class_init(GArrowLargeStringScalarClass *klass)
1176 {
1177 }
1178 
1179 /**
1180  * garrow_large_string_scalar_new:
1181  * @value: The value of this scalar.
1182  *
1183  * Returns: A newly created #GArrowLargeStringScalar.
1184  *
1185  * Since: 5.0.0
1186  */
1187 GArrowLargeStringScalar *
garrow_large_string_scalar_new(GArrowBuffer * value)1188 garrow_large_string_scalar_new(GArrowBuffer *value)
1189 {
1190   return GARROW_LARGE_STRING_SCALAR(
1191     garrow_base_binary_scalar_new<arrow::LargeStringScalar>(value));
1192 }
1193 
1194 
G_DEFINE_TYPE(GArrowFixedSizeBinaryScalar,garrow_fixed_size_binary_scalar,GARROW_TYPE_BASE_BINARY_SCALAR)1195 G_DEFINE_TYPE(GArrowFixedSizeBinaryScalar,
1196               garrow_fixed_size_binary_scalar,
1197               GARROW_TYPE_BASE_BINARY_SCALAR)
1198 
1199 static void
1200 garrow_fixed_size_binary_scalar_init(GArrowFixedSizeBinaryScalar *object)
1201 {
1202 }
1203 
1204 static void
garrow_fixed_size_binary_scalar_class_init(GArrowFixedSizeBinaryScalarClass * klass)1205 garrow_fixed_size_binary_scalar_class_init(
1206   GArrowFixedSizeBinaryScalarClass *klass)
1207 {
1208 }
1209 
1210 /**
1211  * garrow_fixed_size_binary_scalar_new:
1212  * @data_type: A #GArrowFixedSizeBinaryDataType for this scalar.
1213  * @value: The value of this scalar.
1214  *
1215  * Returns: A newly created #GArrowFixedSizeBinaryScalar.
1216  *
1217  * Since: 5.0.0
1218  */
1219 GArrowFixedSizeBinaryScalar *
garrow_fixed_size_binary_scalar_new(GArrowFixedSizeBinaryDataType * data_type,GArrowBuffer * value)1220 garrow_fixed_size_binary_scalar_new(GArrowFixedSizeBinaryDataType *data_type,
1221                                     GArrowBuffer *value)
1222 {
1223   auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type));
1224   auto arrow_value = garrow_buffer_get_raw(value);
1225   auto arrow_scalar =
1226     std::static_pointer_cast<arrow::Scalar>(
1227       std::make_shared<arrow::FixedSizeBinaryScalar>(
1228         arrow_value, arrow_data_type));
1229   return GARROW_FIXED_SIZE_BINARY_SCALAR(
1230     garrow_scalar_new_raw(&arrow_scalar,
1231                           "scalar", &arrow_scalar,
1232                           "data-type", data_type,
1233                           "value", value,
1234                           NULL));
1235 }
1236 
1237 
G_DEFINE_TYPE(GArrowDate32Scalar,garrow_date32_scalar,GARROW_TYPE_SCALAR)1238 G_DEFINE_TYPE(GArrowDate32Scalar,
1239               garrow_date32_scalar,
1240               GARROW_TYPE_SCALAR)
1241 
1242 static void
1243 garrow_date32_scalar_init(GArrowDate32Scalar *object)
1244 {
1245 }
1246 
1247 static void
garrow_date32_scalar_class_init(GArrowDate32ScalarClass * klass)1248 garrow_date32_scalar_class_init(GArrowDate32ScalarClass *klass)
1249 {
1250 }
1251 
1252 /**
1253  * garrow_date32_scalar_new:
1254  * @value: The value of this scalar.
1255  *
1256  * Returns: A newly created #GArrowDate32Scalar.
1257  *
1258  * Since: 5.0.0
1259  */
1260 GArrowDate32Scalar *
garrow_date32_scalar_new(gint32 value)1261 garrow_date32_scalar_new(gint32 value)
1262 {
1263   auto arrow_scalar =
1264     std::static_pointer_cast<arrow::Scalar>(
1265       std::make_shared<arrow::Date32Scalar>(value));
1266   return GARROW_DATE32_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
1267 }
1268 
1269 /**
1270  * garrow_date32_scalar_get_value:
1271  * @scalar: A #GArrowDate32Scalar.
1272  *
1273  * Returns: The value of this scalar.
1274  *
1275  * Since: 5.0.0
1276  */
1277 gint32
garrow_date32_scalar_get_value(GArrowDate32Scalar * scalar)1278 garrow_date32_scalar_get_value(GArrowDate32Scalar *scalar)
1279 {
1280   const auto arrow_scalar =
1281     std::static_pointer_cast<arrow::Date32Scalar>(
1282       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
1283   return arrow_scalar->value;
1284 }
1285 
1286 
G_DEFINE_TYPE(GArrowDate64Scalar,garrow_date64_scalar,GARROW_TYPE_SCALAR)1287 G_DEFINE_TYPE(GArrowDate64Scalar,
1288               garrow_date64_scalar,
1289               GARROW_TYPE_SCALAR)
1290 
1291 static void
1292 garrow_date64_scalar_init(GArrowDate64Scalar *object)
1293 {
1294 }
1295 
1296 static void
garrow_date64_scalar_class_init(GArrowDate64ScalarClass * klass)1297 garrow_date64_scalar_class_init(GArrowDate64ScalarClass *klass)
1298 {
1299 }
1300 
1301 /**
1302  * garrow_date64_scalar_new:
1303  * @value: The value of this scalar.
1304  *
1305  * Returns: A newly created #GArrowDate64Scalar.
1306  *
1307  * Since: 5.0.0
1308  */
1309 GArrowDate64Scalar *
garrow_date64_scalar_new(gint64 value)1310 garrow_date64_scalar_new(gint64 value)
1311 {
1312   auto arrow_scalar =
1313     std::static_pointer_cast<arrow::Scalar>(
1314       std::make_shared<arrow::Date64Scalar>(value));
1315   return GARROW_DATE64_SCALAR(garrow_scalar_new_raw(&arrow_scalar));
1316 }
1317 
1318 /**
1319  * garrow_date64_scalar_get_value:
1320  * @scalar: A #GArrowDate64Scalar.
1321  *
1322  * Returns: The value of this scalar.
1323  *
1324  * Since: 5.0.0
1325  */
1326 gint64
garrow_date64_scalar_get_value(GArrowDate64Scalar * scalar)1327 garrow_date64_scalar_get_value(GArrowDate64Scalar *scalar)
1328 {
1329   const auto arrow_scalar =
1330     std::static_pointer_cast<arrow::Date64Scalar>(
1331       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
1332   return arrow_scalar->value;
1333 }
1334 
1335 
G_DEFINE_TYPE(GArrowTime32Scalar,garrow_time32_scalar,GARROW_TYPE_SCALAR)1336 G_DEFINE_TYPE(GArrowTime32Scalar,
1337               garrow_time32_scalar,
1338               GARROW_TYPE_SCALAR)
1339 
1340 static void
1341 garrow_time32_scalar_init(GArrowTime32Scalar *object)
1342 {
1343 }
1344 
1345 static void
garrow_time32_scalar_class_init(GArrowTime32ScalarClass * klass)1346 garrow_time32_scalar_class_init(GArrowTime32ScalarClass *klass)
1347 {
1348 }
1349 
1350 /**
1351  * garrow_time32_scalar_new:
1352  * @data_type: A #GArrowTime32DataType for this scalar.
1353  * @value: The value of this scalar.
1354  *
1355  * Returns: A newly created #GArrowTime32Scalar.
1356  *
1357  * Since: 5.0.0
1358  */
1359 GArrowTime32Scalar *
garrow_time32_scalar_new(GArrowTime32DataType * data_type,gint32 value)1360 garrow_time32_scalar_new(GArrowTime32DataType *data_type,
1361                          gint32 value)
1362 {
1363   auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type));
1364   auto arrow_scalar =
1365     std::static_pointer_cast<arrow::Scalar>(
1366       std::make_shared<arrow::Time32Scalar>(value, arrow_data_type));
1367   return GARROW_TIME32_SCALAR(
1368     garrow_scalar_new_raw(&arrow_scalar,
1369                           "scalar", &arrow_scalar,
1370                           "data-type", data_type,
1371                           NULL));
1372 }
1373 
1374 /**
1375  * garrow_time32_scalar_get_value:
1376  * @scalar: A #GArrowTime32Scalar.
1377  *
1378  * Returns: The value of this scalar.
1379  *
1380  * Since: 5.0.0
1381  */
1382 gint32
garrow_time32_scalar_get_value(GArrowTime32Scalar * scalar)1383 garrow_time32_scalar_get_value(GArrowTime32Scalar *scalar)
1384 {
1385   const auto arrow_scalar =
1386     std::static_pointer_cast<arrow::Time32Scalar>(
1387       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
1388   return arrow_scalar->value;
1389 }
1390 
1391 
G_DEFINE_TYPE(GArrowTime64Scalar,garrow_time64_scalar,GARROW_TYPE_SCALAR)1392 G_DEFINE_TYPE(GArrowTime64Scalar,
1393               garrow_time64_scalar,
1394               GARROW_TYPE_SCALAR)
1395 
1396 static void
1397 garrow_time64_scalar_init(GArrowTime64Scalar *object)
1398 {
1399 }
1400 
1401 static void
garrow_time64_scalar_class_init(GArrowTime64ScalarClass * klass)1402 garrow_time64_scalar_class_init(GArrowTime64ScalarClass *klass)
1403 {
1404 }
1405 
1406 /**
1407  * garrow_time64_scalar_new:
1408  * @data_type: A #GArrowTime64DataType for this scalar.
1409  * @value: The value of this scalar.
1410  *
1411  * Returns: A newly created #GArrowTime64Scalar.
1412  *
1413  * Since: 5.0.0
1414  */
1415 GArrowTime64Scalar *
garrow_time64_scalar_new(GArrowTime64DataType * data_type,gint64 value)1416 garrow_time64_scalar_new(GArrowTime64DataType *data_type,
1417                          gint64 value)
1418 {
1419   auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type));
1420   auto arrow_scalar =
1421     std::static_pointer_cast<arrow::Scalar>(
1422       std::make_shared<arrow::Time64Scalar>(value, arrow_data_type));
1423   return GARROW_TIME64_SCALAR(
1424     garrow_scalar_new_raw(&arrow_scalar,
1425                           "scalar", &arrow_scalar,
1426                           "data-type", data_type,
1427                           NULL));
1428 }
1429 
1430 /**
1431  * garrow_time64_scalar_get_value:
1432  * @scalar: A #GArrowTime64Scalar.
1433  *
1434  * Returns: The value of this scalar.
1435  *
1436  * Since: 5.0.0
1437  */
1438 gint64
garrow_time64_scalar_get_value(GArrowTime64Scalar * scalar)1439 garrow_time64_scalar_get_value(GArrowTime64Scalar *scalar)
1440 {
1441   const auto arrow_scalar =
1442     std::static_pointer_cast<arrow::Time64Scalar>(
1443       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
1444   return arrow_scalar->value;
1445 }
1446 
1447 
G_DEFINE_TYPE(GArrowTimestampScalar,garrow_timestamp_scalar,GARROW_TYPE_SCALAR)1448 G_DEFINE_TYPE(GArrowTimestampScalar,
1449               garrow_timestamp_scalar,
1450               GARROW_TYPE_SCALAR)
1451 
1452 static void
1453 garrow_timestamp_scalar_init(GArrowTimestampScalar *object)
1454 {
1455 }
1456 
1457 static void
garrow_timestamp_scalar_class_init(GArrowTimestampScalarClass * klass)1458 garrow_timestamp_scalar_class_init(GArrowTimestampScalarClass *klass)
1459 {
1460 }
1461 
1462 /**
1463  * garrow_timestamp_scalar_new:
1464  * @data_type: A #GArrowTimestampDataType for this scalar.
1465  * @value: The value of this scalar.
1466  *
1467  * Returns: A newly created #GArrowTimestampScalar.
1468  *
1469  * Since: 5.0.0
1470  */
1471 GArrowTimestampScalar *
garrow_timestamp_scalar_new(GArrowTimestampDataType * data_type,gint64 value)1472 garrow_timestamp_scalar_new(GArrowTimestampDataType *data_type,
1473                             gint64 value)
1474 {
1475   auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type));
1476   auto arrow_scalar =
1477     std::static_pointer_cast<arrow::Scalar>(
1478       std::make_shared<arrow::TimestampScalar>(value, arrow_data_type));
1479   return GARROW_TIMESTAMP_SCALAR(
1480     garrow_scalar_new_raw(&arrow_scalar,
1481                           "scalar", &arrow_scalar,
1482                           "data-type", data_type,
1483                           NULL));
1484 }
1485 
1486 /**
1487  * garrow_timestamp_scalar_get_value:
1488  * @scalar: A #GArrowTimestampScalar.
1489  *
1490  * Returns: The value of this scalar.
1491  *
1492  * Since: 5.0.0
1493  */
1494 gint64
garrow_timestamp_scalar_get_value(GArrowTimestampScalar * scalar)1495 garrow_timestamp_scalar_get_value(GArrowTimestampScalar *scalar)
1496 {
1497   const auto arrow_scalar =
1498     std::static_pointer_cast<arrow::TimestampScalar>(
1499       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
1500   return arrow_scalar->value;
1501 }
1502 
1503 
1504 typedef struct GArrowDecimal128ScalarPrivate_ {
1505   GArrowDecimal128 *value;
1506 } GArrowDecimal128ScalarPrivate;
1507 
G_DEFINE_TYPE_WITH_PRIVATE(GArrowDecimal128Scalar,garrow_decimal128_scalar,GARROW_TYPE_SCALAR)1508 G_DEFINE_TYPE_WITH_PRIVATE(GArrowDecimal128Scalar,
1509                            garrow_decimal128_scalar,
1510                            GARROW_TYPE_SCALAR)
1511 
1512 #define GARROW_DECIMAL128_SCALAR_GET_PRIVATE(obj)            \
1513   static_cast<GArrowDecimal128ScalarPrivate *>(              \
1514     garrow_decimal128_scalar_get_instance_private(           \
1515       GARROW_DECIMAL128_SCALAR(obj)))
1516 
1517 static void
1518 garrow_decimal128_scalar_dispose(GObject *object)
1519 {
1520   auto priv = GARROW_DECIMAL128_SCALAR_GET_PRIVATE(object);
1521 
1522   if (priv->value) {
1523     g_object_unref(priv->value);
1524     priv->value = NULL;
1525   }
1526 
1527   G_OBJECT_CLASS(garrow_decimal128_scalar_parent_class)->dispose(object);
1528 }
1529 
1530 static void
garrow_decimal128_scalar_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)1531 garrow_decimal128_scalar_set_property(GObject *object,
1532                                       guint prop_id,
1533                                       const GValue *value,
1534                                       GParamSpec *pspec)
1535 {
1536   auto priv = GARROW_DECIMAL128_SCALAR_GET_PRIVATE(object);
1537 
1538   switch (prop_id) {
1539   case PROP_VALUE:
1540     priv->value = GARROW_DECIMAL128(g_value_dup_object(value));
1541     break;
1542   default:
1543     G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1544     break;
1545   }
1546 }
1547 
1548 static void
garrow_decimal128_scalar_init(GArrowDecimal128Scalar * object)1549 garrow_decimal128_scalar_init(GArrowDecimal128Scalar *object)
1550 {
1551 }
1552 
1553 static void
garrow_decimal128_scalar_class_init(GArrowDecimal128ScalarClass * klass)1554 garrow_decimal128_scalar_class_init(GArrowDecimal128ScalarClass *klass)
1555 {
1556   auto gobject_class = G_OBJECT_CLASS(klass);
1557 
1558   gobject_class->dispose      = garrow_decimal128_scalar_dispose;
1559   gobject_class->set_property = garrow_decimal128_scalar_set_property;
1560 
1561   GParamSpec *spec;
1562   /**
1563    * GArrowDecimal128Scalar:value:
1564    *
1565    * The value of the scalar.
1566    *
1567    * Since: 5.0.0
1568    */
1569   spec = g_param_spec_object("value",
1570                              "Value",
1571                              "The value of the scalar",
1572                              garrow_decimal128_get_type(),
1573                              static_cast<GParamFlags>(G_PARAM_WRITABLE |
1574                                                       G_PARAM_CONSTRUCT_ONLY));
1575   g_object_class_install_property(gobject_class, PROP_VALUE, spec);
1576 }
1577 
1578 /**
1579  * garrow_decimal128_scalar_new:
1580  * @data_type: A #GArrowDecimal128DataType for this scalar.
1581  * @value: The value of this scalar.
1582  *
1583  * Returns: A newly created #GArrowDecimal128Scalar.
1584  *
1585  * Since: 5.0.0
1586  */
1587 GArrowDecimal128Scalar *
garrow_decimal128_scalar_new(GArrowDecimal128DataType * data_type,GArrowDecimal128 * value)1588 garrow_decimal128_scalar_new(GArrowDecimal128DataType *data_type,
1589                              GArrowDecimal128 *value)
1590 {
1591   auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type));
1592   auto arrow_value = garrow_decimal128_get_raw(value);
1593   auto arrow_scalar =
1594     std::static_pointer_cast<arrow::Scalar>(
1595       std::make_shared<arrow::Decimal128Scalar>(*arrow_value, arrow_data_type));
1596   return GARROW_DECIMAL128_SCALAR(
1597     garrow_scalar_new_raw(&arrow_scalar,
1598                           "scalar", &arrow_scalar,
1599                           "data-type", data_type,
1600                           "value", value,
1601                           NULL));
1602 }
1603 
1604 /**
1605  * garrow_decimal128_scalar_get_value:
1606  * @scalar: A #GArrowDecimal128Scalar.
1607  *
1608  * Returns: (transfer none): The value of this scalar.
1609  *
1610  * Since: 5.0.0
1611  */
1612 GArrowDecimal128 *
garrow_decimal128_scalar_get_value(GArrowDecimal128Scalar * scalar)1613 garrow_decimal128_scalar_get_value(GArrowDecimal128Scalar *scalar)
1614 {
1615   auto priv = GARROW_DECIMAL128_SCALAR_GET_PRIVATE(scalar);
1616   if (!priv->value) {
1617     auto arrow_scalar =
1618       std::static_pointer_cast<arrow::Decimal128Scalar>(
1619         garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
1620     auto arrow_value = std::make_shared<arrow::Decimal128>(arrow_scalar->value);
1621     priv->value = garrow_decimal128_new_raw(&arrow_value);
1622   }
1623   return priv->value;
1624 }
1625 
1626 
1627 typedef struct GArrowDecimal256ScalarPrivate_ {
1628   GArrowDecimal256 *value;
1629 } GArrowDecimal256ScalarPrivate;
1630 
G_DEFINE_TYPE_WITH_PRIVATE(GArrowDecimal256Scalar,garrow_decimal256_scalar,GARROW_TYPE_SCALAR)1631 G_DEFINE_TYPE_WITH_PRIVATE(GArrowDecimal256Scalar,
1632                            garrow_decimal256_scalar,
1633                            GARROW_TYPE_SCALAR)
1634 
1635 #define GARROW_DECIMAL256_SCALAR_GET_PRIVATE(obj)            \
1636   static_cast<GArrowDecimal256ScalarPrivate *>(              \
1637     garrow_decimal256_scalar_get_instance_private(           \
1638       GARROW_DECIMAL256_SCALAR(obj)))
1639 
1640 static void
1641 garrow_decimal256_scalar_dispose(GObject *object)
1642 {
1643   auto priv = GARROW_DECIMAL256_SCALAR_GET_PRIVATE(object);
1644 
1645   if (priv->value) {
1646     g_object_unref(priv->value);
1647     priv->value = NULL;
1648   }
1649 
1650   G_OBJECT_CLASS(garrow_decimal256_scalar_parent_class)->dispose(object);
1651 }
1652 
1653 static void
garrow_decimal256_scalar_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)1654 garrow_decimal256_scalar_set_property(GObject *object,
1655                                       guint prop_id,
1656                                       const GValue *value,
1657                                       GParamSpec *pspec)
1658 {
1659   auto priv = GARROW_DECIMAL256_SCALAR_GET_PRIVATE(object);
1660 
1661   switch (prop_id) {
1662   case PROP_VALUE:
1663     priv->value = GARROW_DECIMAL256(g_value_dup_object(value));
1664     break;
1665   default:
1666     G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1667     break;
1668   }
1669 }
1670 
1671 static void
garrow_decimal256_scalar_init(GArrowDecimal256Scalar * object)1672 garrow_decimal256_scalar_init(GArrowDecimal256Scalar *object)
1673 {
1674 }
1675 
1676 static void
garrow_decimal256_scalar_class_init(GArrowDecimal256ScalarClass * klass)1677 garrow_decimal256_scalar_class_init(GArrowDecimal256ScalarClass *klass)
1678 {
1679   auto gobject_class = G_OBJECT_CLASS(klass);
1680 
1681   gobject_class->dispose      = garrow_decimal256_scalar_dispose;
1682   gobject_class->set_property = garrow_decimal256_scalar_set_property;
1683 
1684   GParamSpec *spec;
1685   /**
1686    * GArrowDecimal256Scalar:value:
1687    *
1688    * The value of the scalar.
1689    *
1690    * Since: 5.0.0
1691    */
1692   spec = g_param_spec_object("value",
1693                              "Value",
1694                              "The value of the scalar",
1695                              garrow_decimal256_get_type(),
1696                              static_cast<GParamFlags>(G_PARAM_WRITABLE |
1697                                                       G_PARAM_CONSTRUCT_ONLY));
1698   g_object_class_install_property(gobject_class, PROP_VALUE, spec);
1699 }
1700 
1701 /**
1702  * garrow_decimal256_scalar_new:
1703  * @data_type: A #GArrowDecimal256DataType for this scalar.
1704  * @value: The value of this scalar.
1705  *
1706  * Returns: A newly created #GArrowDecimal256Scalar.
1707  *
1708  * Since: 5.0.0
1709  */
1710 GArrowDecimal256Scalar *
garrow_decimal256_scalar_new(GArrowDecimal256DataType * data_type,GArrowDecimal256 * value)1711 garrow_decimal256_scalar_new(GArrowDecimal256DataType *data_type,
1712                              GArrowDecimal256 *value)
1713 {
1714   auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type));
1715   auto arrow_value = garrow_decimal256_get_raw(value);
1716   auto arrow_scalar =
1717     std::static_pointer_cast<arrow::Scalar>(
1718       std::make_shared<arrow::Decimal256Scalar>(*arrow_value, arrow_data_type));
1719   return GARROW_DECIMAL256_SCALAR(garrow_scalar_new_raw(&arrow_scalar,
1720                                                         "scalar", &arrow_scalar,
1721                                                         "data-type", data_type,
1722                                                         "value", value,
1723                                                         NULL));
1724 }
1725 
1726 /**
1727  * garrow_decimal256_scalar_get_value:
1728  * @scalar: A #GArrowDecimal256Scalar.
1729  *
1730  * Returns: (transfer none): The value of this scalar.
1731  *
1732  * Since: 5.0.0
1733  */
1734 GArrowDecimal256 *
garrow_decimal256_scalar_get_value(GArrowDecimal256Scalar * scalar)1735 garrow_decimal256_scalar_get_value(GArrowDecimal256Scalar *scalar)
1736 {
1737   auto priv = GARROW_DECIMAL256_SCALAR_GET_PRIVATE(scalar);
1738   if (!priv->value) {
1739     auto arrow_scalar =
1740       std::static_pointer_cast<arrow::Decimal256Scalar>(
1741         garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
1742     auto arrow_value = std::make_shared<arrow::Decimal256>(arrow_scalar->value);
1743     priv->value = garrow_decimal256_new_raw(&arrow_value);
1744   }
1745   return priv->value;
1746 }
1747 
1748 
1749 typedef struct GArrowBaseListScalarPrivate_ {
1750   GArrowArray *value;
1751 } GArrowBaseListScalarPrivate;
1752 
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GArrowBaseListScalar,garrow_base_list_scalar,GARROW_TYPE_SCALAR)1753 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GArrowBaseListScalar,
1754                                     garrow_base_list_scalar,
1755                                     GARROW_TYPE_SCALAR)
1756 
1757 #define GARROW_BASE_LIST_SCALAR_GET_PRIVATE(obj)            \
1758   static_cast<GArrowBaseListScalarPrivate *>(               \
1759     garrow_base_list_scalar_get_instance_private(           \
1760       GARROW_BASE_LIST_SCALAR(obj)))
1761 
1762 static void
1763 garrow_base_list_scalar_dispose(GObject *object)
1764 {
1765   auto priv = GARROW_BASE_LIST_SCALAR_GET_PRIVATE(object);
1766 
1767   if (priv->value) {
1768     g_object_unref(priv->value);
1769     priv->value = NULL;
1770   }
1771 
1772   G_OBJECT_CLASS(garrow_base_list_scalar_parent_class)->dispose(object);
1773 }
1774 
1775 static void
garrow_base_list_scalar_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)1776 garrow_base_list_scalar_set_property(GObject *object,
1777                                      guint prop_id,
1778                                      const GValue *value,
1779                                      GParamSpec *pspec)
1780 {
1781   auto priv = GARROW_BASE_LIST_SCALAR_GET_PRIVATE(object);
1782 
1783   switch (prop_id) {
1784   case PROP_VALUE:
1785     priv->value = GARROW_ARRAY(g_value_dup_object(value));
1786     break;
1787   default:
1788     G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1789     break;
1790   }
1791 }
1792 
1793 static void
garrow_base_list_scalar_init(GArrowBaseListScalar * object)1794 garrow_base_list_scalar_init(GArrowBaseListScalar *object)
1795 {
1796 }
1797 
1798 static void
garrow_base_list_scalar_class_init(GArrowBaseListScalarClass * klass)1799 garrow_base_list_scalar_class_init(GArrowBaseListScalarClass *klass)
1800 {
1801   auto gobject_class = G_OBJECT_CLASS(klass);
1802 
1803   gobject_class->dispose      = garrow_base_list_scalar_dispose;
1804   gobject_class->set_property = garrow_base_list_scalar_set_property;
1805 
1806   GParamSpec *spec;
1807   /**
1808    * GArrowBaseListScalar:value:
1809    *
1810    * The value of the scalar.
1811    *
1812    * Since: 5.0.0
1813    */
1814   spec = g_param_spec_object("value",
1815                              "Value",
1816                              "The value of the scalar",
1817                              GARROW_TYPE_ARRAY,
1818                              static_cast<GParamFlags>(G_PARAM_WRITABLE |
1819                                                       G_PARAM_CONSTRUCT_ONLY));
1820   g_object_class_install_property(gobject_class, PROP_VALUE, spec);
1821 }
1822 
1823 G_END_DECLS
1824 template<typename ArrowListScalarType>
1825 GArrowScalar *
garrow_base_list_scalar_new(GArrowArray * value)1826 garrow_base_list_scalar_new(GArrowArray *value)
1827 {
1828   auto arrow_value = garrow_array_get_raw(value);
1829   auto arrow_scalar =
1830     std::static_pointer_cast<arrow::Scalar>(
1831       std::make_shared<ArrowListScalarType>(arrow_value));
1832   auto data_type = garrow_array_get_value_data_type(value);
1833   auto scalar = garrow_scalar_new_raw(&arrow_scalar,
1834                                       "scalar", &arrow_scalar,
1835                                       "data-type", data_type,
1836                                       "value", value,
1837                                       NULL);
1838   g_object_unref(data_type);
1839   return scalar;
1840 }
1841 G_BEGIN_DECLS
1842 
1843 /**
1844  * garrow_base_list_scalar_get_value:
1845  * @scalar: A #GArrowBaseListScalar.
1846  *
1847  * Returns: (transfer none): The value of this scalar.
1848  *
1849  * Since: 5.0.0
1850  */
1851 GArrowArray *
garrow_base_list_scalar_get_value(GArrowBaseListScalar * scalar)1852 garrow_base_list_scalar_get_value(GArrowBaseListScalar *scalar)
1853 {
1854   auto priv = GARROW_BASE_LIST_SCALAR_GET_PRIVATE(scalar);
1855   if (!priv->value) {
1856     const auto arrow_scalar =
1857       std::static_pointer_cast<arrow::BaseListScalar>(
1858         garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
1859     priv->value = garrow_array_new_raw(&(arrow_scalar->value));
1860   }
1861   return priv->value;
1862 }
1863 
1864 
G_DEFINE_TYPE(GArrowListScalar,garrow_list_scalar,GARROW_TYPE_BASE_LIST_SCALAR)1865 G_DEFINE_TYPE(GArrowListScalar,
1866               garrow_list_scalar,
1867               GARROW_TYPE_BASE_LIST_SCALAR)
1868 
1869 static void
1870 garrow_list_scalar_init(GArrowListScalar *object)
1871 {
1872 }
1873 
1874 static void
garrow_list_scalar_class_init(GArrowListScalarClass * klass)1875 garrow_list_scalar_class_init(GArrowListScalarClass *klass)
1876 {
1877 }
1878 
1879 /**
1880  * garrow_list_scalar_new:
1881  * @value: The value of this scalar.
1882  *
1883  * Returns: A newly created #GArrowListScalar.
1884  *
1885  * Since: 5.0.0
1886  */
1887 GArrowListScalar *
garrow_list_scalar_new(GArrowListArray * value)1888 garrow_list_scalar_new(GArrowListArray *value)
1889 {
1890   return GARROW_LIST_SCALAR(
1891     garrow_base_list_scalar_new<arrow::ListScalar>(GARROW_ARRAY(value)));
1892 }
1893 
1894 
G_DEFINE_TYPE(GArrowLargeListScalar,garrow_large_list_scalar,GARROW_TYPE_BASE_LIST_SCALAR)1895 G_DEFINE_TYPE(GArrowLargeListScalar,
1896               garrow_large_list_scalar,
1897               GARROW_TYPE_BASE_LIST_SCALAR)
1898 
1899 static void
1900 garrow_large_list_scalar_init(GArrowLargeListScalar *object)
1901 {
1902 }
1903 
1904 static void
garrow_large_list_scalar_class_init(GArrowLargeListScalarClass * klass)1905 garrow_large_list_scalar_class_init(GArrowLargeListScalarClass *klass)
1906 {
1907 }
1908 
1909 /**
1910  * garrow_large_list_scalar_new:
1911  * @value: The value of this scalar.
1912  *
1913  * Returns: A newly created #GArrowLargeListScalar.
1914  *
1915  * Since: 5.0.0
1916  */
1917 GArrowLargeListScalar *
garrow_large_list_scalar_new(GArrowLargeListArray * value)1918 garrow_large_list_scalar_new(GArrowLargeListArray *value)
1919 {
1920   return GARROW_LARGE_LIST_SCALAR(
1921     garrow_base_list_scalar_new<arrow::LargeListScalar>(GARROW_ARRAY(value)));
1922 }
1923 
1924 
G_DEFINE_TYPE(GArrowMapScalar,garrow_map_scalar,GARROW_TYPE_BASE_LIST_SCALAR)1925 G_DEFINE_TYPE(GArrowMapScalar,
1926               garrow_map_scalar,
1927               GARROW_TYPE_BASE_LIST_SCALAR)
1928 
1929 static void
1930 garrow_map_scalar_init(GArrowMapScalar *object)
1931 {
1932 }
1933 
1934 static void
garrow_map_scalar_class_init(GArrowMapScalarClass * klass)1935 garrow_map_scalar_class_init(GArrowMapScalarClass *klass)
1936 {
1937 }
1938 
1939 /**
1940  * garrow_map_scalar_new:
1941  * @value: The value of this scalar.
1942  *
1943  * Returns: A newly created #GArrowMapScalar.
1944  *
1945  * Since: 5.0.0
1946  */
1947 GArrowMapScalar *
garrow_map_scalar_new(GArrowStructArray * value)1948 garrow_map_scalar_new(GArrowStructArray *value)
1949 {
1950   return GARROW_MAP_SCALAR(
1951     garrow_base_list_scalar_new<arrow::MapScalar>(GARROW_ARRAY(value)));
1952 }
1953 
1954 
1955 typedef struct GArrowStructScalarPrivate_ {
1956   GList *value;
1957 } GArrowStructScalarPrivate;
1958 
G_DEFINE_TYPE_WITH_PRIVATE(GArrowStructScalar,garrow_struct_scalar,GARROW_TYPE_SCALAR)1959 G_DEFINE_TYPE_WITH_PRIVATE(GArrowStructScalar,
1960                            garrow_struct_scalar,
1961                            GARROW_TYPE_SCALAR)
1962 
1963 #define GARROW_STRUCT_SCALAR_GET_PRIVATE(obj)             \
1964   static_cast<GArrowStructScalarPrivate *>(               \
1965     garrow_struct_scalar_get_instance_private(            \
1966       GARROW_STRUCT_SCALAR(obj)))
1967 
1968 static void
1969 garrow_struct_scalar_dispose(GObject *object)
1970 {
1971   auto priv = GARROW_STRUCT_SCALAR_GET_PRIVATE(object);
1972 
1973   if (priv->value) {
1974     g_list_free_full(priv->value, g_object_unref);
1975     priv->value = NULL;
1976   }
1977 
1978   G_OBJECT_CLASS(garrow_struct_scalar_parent_class)->dispose(object);
1979 }
1980 
1981 static void
garrow_struct_scalar_init(GArrowStructScalar * object)1982 garrow_struct_scalar_init(GArrowStructScalar *object)
1983 {
1984 }
1985 
1986 static void
garrow_struct_scalar_class_init(GArrowStructScalarClass * klass)1987 garrow_struct_scalar_class_init(GArrowStructScalarClass *klass)
1988 {
1989   auto gobject_class = G_OBJECT_CLASS(klass);
1990   gobject_class->dispose = garrow_struct_scalar_dispose;
1991 }
1992 
1993 /**
1994  * garrow_struct_scalar_new:
1995  * @data_type: A #GArrowStructDataType for this scalar.
1996  * @value: (element-type GArrowScalar): The value of this scalar.
1997  *
1998  * Returns: A newly created #GArrowDecimal256Scalar.
1999  *
2000  * Since: 5.0.0
2001  */
2002 GArrowStructScalar *
garrow_struct_scalar_new(GArrowStructDataType * data_type,GList * value)2003 garrow_struct_scalar_new(GArrowStructDataType *data_type,
2004                          GList *value)
2005 {
2006   auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type));
2007   std::vector<std::shared_ptr<arrow::Scalar>> arrow_value;
2008   for (GList *node = value; node; node = node->next) {
2009     auto field = GARROW_SCALAR(node->data);
2010     auto arrow_field = garrow_scalar_get_raw(field);
2011     arrow_value.push_back(arrow_field);
2012   }
2013   auto arrow_scalar =
2014     std::static_pointer_cast<arrow::Scalar>(
2015       std::make_shared<arrow::StructScalar>(arrow_value, arrow_data_type));
2016   auto scalar =
2017     GARROW_STRUCT_SCALAR(
2018       garrow_scalar_new_raw(&arrow_scalar,
2019                             "scalar", &arrow_scalar,
2020                             "data-type", data_type,
2021                             NULL));
2022   auto priv = GARROW_STRUCT_SCALAR_GET_PRIVATE(scalar);
2023   priv->value = g_list_copy_deep(value,
2024                                  reinterpret_cast<GCopyFunc>(g_object_ref),
2025                                  NULL);
2026   return scalar;
2027 }
2028 
2029 /**
2030  * garrow_struct_scalar_get_value:
2031  * @scalar: A #GArrowStructScalar.
2032  *
2033  * Returns: (element-type GArrowScalar) (transfer none):
2034  *   The value of this scalar.
2035  *
2036  * Since: 5.0.0
2037  */
2038 GList *
garrow_struct_scalar_get_value(GArrowStructScalar * scalar)2039 garrow_struct_scalar_get_value(GArrowStructScalar *scalar)
2040 {
2041   auto priv = GARROW_STRUCT_SCALAR_GET_PRIVATE(scalar);
2042   return priv->value;
2043 }
2044 
2045 
2046 typedef struct GArrowUnionScalarPrivate_ {
2047   GArrowScalar *value;
2048 } GArrowUnionScalarPrivate;
2049 
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GArrowUnionScalar,garrow_union_scalar,GARROW_TYPE_SCALAR)2050 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GArrowUnionScalar,
2051                                     garrow_union_scalar,
2052                                     GARROW_TYPE_SCALAR)
2053 
2054 #define GARROW_UNION_SCALAR_GET_PRIVATE(obj)             \
2055   static_cast<GArrowUnionScalarPrivate *>(               \
2056     garrow_union_scalar_get_instance_private(            \
2057       GARROW_UNION_SCALAR(obj)))
2058 
2059 static void
2060 garrow_union_scalar_dispose(GObject *object)
2061 {
2062   auto priv = GARROW_UNION_SCALAR_GET_PRIVATE(object);
2063 
2064   if (priv->value) {
2065     g_object_unref(priv->value);
2066     priv->value = NULL;
2067   }
2068 
2069   G_OBJECT_CLASS(garrow_union_scalar_parent_class)->dispose(object);
2070 }
2071 
2072 static void
garrow_union_scalar_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)2073 garrow_union_scalar_set_property(GObject *object,
2074                                  guint prop_id,
2075                                  const GValue *value,
2076                                  GParamSpec *pspec)
2077 {
2078   auto priv = GARROW_UNION_SCALAR_GET_PRIVATE(object);
2079 
2080   switch (prop_id) {
2081   case PROP_VALUE:
2082     priv->value = GARROW_SCALAR(g_value_dup_object(value));
2083     break;
2084   default:
2085     G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
2086     break;
2087   }
2088 }
2089 
2090 static void
garrow_union_scalar_init(GArrowUnionScalar * object)2091 garrow_union_scalar_init(GArrowUnionScalar *object)
2092 {
2093 }
2094 
2095 static void
garrow_union_scalar_class_init(GArrowUnionScalarClass * klass)2096 garrow_union_scalar_class_init(GArrowUnionScalarClass *klass)
2097 {
2098   auto gobject_class = G_OBJECT_CLASS(klass);
2099   gobject_class->dispose      = garrow_union_scalar_dispose;
2100   gobject_class->set_property = garrow_union_scalar_set_property;
2101 
2102   GParamSpec *spec;
2103   /**
2104    * GArrowUnionScalar:value:
2105    *
2106    * The value of the scalar.
2107    *
2108    * Since: 5.0.0
2109    */
2110   spec = g_param_spec_object("value",
2111                              "Value",
2112                              "The value of the scalar",
2113                              GARROW_TYPE_SCALAR,
2114                              static_cast<GParamFlags>(G_PARAM_WRITABLE |
2115                                                       G_PARAM_CONSTRUCT_ONLY));
2116   g_object_class_install_property(gobject_class, PROP_VALUE, spec);
2117 }
2118 
2119 G_END_DECLS
2120 template<typename ArrowUnionScalarType>
2121 GArrowScalar *
garrow_union_scalar_new(GArrowDataType * data_type,gint8 type_code,GArrowScalar * value)2122 garrow_union_scalar_new(GArrowDataType *data_type,
2123                         gint8 type_code,
2124                         GArrowScalar *value)
2125 {
2126   auto arrow_data_type = garrow_data_type_get_raw(data_type);
2127   auto arrow_value = garrow_scalar_get_raw(value);
2128   auto arrow_scalar =
2129     std::static_pointer_cast<arrow::Scalar>(
2130       std::make_shared<ArrowUnionScalarType>(arrow_value, type_code,
2131                                              arrow_data_type));
2132   auto scalar = garrow_scalar_new_raw(&arrow_scalar,
2133                                       "scalar", &arrow_scalar,
2134                                       "data-type", data_type,
2135                                       "value", value,
2136                                       NULL);
2137   return scalar;
2138 }
2139 G_BEGIN_DECLS
2140 
2141 /**
2142  * garrow_union_scalar_get_type_code:
2143  * @scalar: A #GArrowUnionScalar.
2144  *
2145  * Returns: The type code of this scalar.
2146  *
2147  * Since: 6.0.0
2148  */
2149 gint8
garrow_union_scalar_get_type_code(GArrowUnionScalar * scalar)2150 garrow_union_scalar_get_type_code(GArrowUnionScalar *scalar)
2151 {
2152   const auto &arrow_scalar =
2153     std::static_pointer_cast<arrow::UnionScalar>(
2154       garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
2155   return arrow_scalar->type_code;
2156 }
2157 
2158 /**
2159  * garrow_union_scalar_get_value:
2160  * @scalar: A #GArrowUnionScalar.
2161  *
2162  * Returns: (transfer none): The value of this scalar.
2163  *
2164  * Since: 5.0.0
2165  */
2166 GArrowScalar *
garrow_union_scalar_get_value(GArrowUnionScalar * scalar)2167 garrow_union_scalar_get_value(GArrowUnionScalar *scalar)
2168 {
2169   auto priv = GARROW_UNION_SCALAR_GET_PRIVATE(scalar);
2170   return priv->value;
2171 }
2172 
2173 
G_DEFINE_TYPE(GArrowSparseUnionScalar,garrow_sparse_union_scalar,GARROW_TYPE_UNION_SCALAR)2174 G_DEFINE_TYPE(GArrowSparseUnionScalar,
2175               garrow_sparse_union_scalar,
2176               GARROW_TYPE_UNION_SCALAR)
2177 
2178 static void
2179 garrow_sparse_union_scalar_init(GArrowSparseUnionScalar *object)
2180 {
2181 }
2182 
2183 static void
garrow_sparse_union_scalar_class_init(GArrowSparseUnionScalarClass * klass)2184 garrow_sparse_union_scalar_class_init(GArrowSparseUnionScalarClass *klass)
2185 {
2186 }
2187 
2188 /**
2189  * garrow_sparse_union_scalar_new:
2190  * @data_type: A #GArrowSparseUnionDataType for this scalar.
2191  * @type_code: The type code of this scalar.
2192  * @value: The value of this scalar.
2193  *
2194  * Returns: A newly created #GArrowSparseUnionScalar.
2195  *
2196  * Since: 5.0.0
2197  */
2198 GArrowSparseUnionScalar *
garrow_sparse_union_scalar_new(GArrowSparseUnionDataType * data_type,gint8 type_code,GArrowScalar * value)2199 garrow_sparse_union_scalar_new(GArrowSparseUnionDataType *data_type,
2200                                gint8 type_code,
2201                                GArrowScalar *value)
2202 {
2203   return GARROW_SPARSE_UNION_SCALAR(
2204     garrow_union_scalar_new<arrow::SparseUnionScalar>(
2205       GARROW_DATA_TYPE(data_type), type_code, value));
2206 }
2207 
2208 
G_DEFINE_TYPE(GArrowDenseUnionScalar,garrow_dense_union_scalar,GARROW_TYPE_UNION_SCALAR)2209 G_DEFINE_TYPE(GArrowDenseUnionScalar,
2210               garrow_dense_union_scalar,
2211               GARROW_TYPE_UNION_SCALAR)
2212 
2213 static void
2214 garrow_dense_union_scalar_init(GArrowDenseUnionScalar *object)
2215 {
2216 }
2217 
2218 static void
garrow_dense_union_scalar_class_init(GArrowDenseUnionScalarClass * klass)2219 garrow_dense_union_scalar_class_init(GArrowDenseUnionScalarClass *klass)
2220 {
2221 }
2222 
2223 /**
2224  * garrow_dense_union_scalar_new:
2225  * @data_type: A #GArrowDenseUnionDataType for this scalar.
2226  * @type_code: The type code of this scalar.
2227  * @value: The value of this scalar.
2228  *
2229  * Returns: A newly created #GArrowDenseUnionScalar.
2230  *
2231  * Since: 5.0.0
2232  */
2233 GArrowDenseUnionScalar *
garrow_dense_union_scalar_new(GArrowDenseUnionDataType * data_type,gint8 type_code,GArrowScalar * value)2234 garrow_dense_union_scalar_new(GArrowDenseUnionDataType *data_type,
2235                               gint8 type_code,
2236                               GArrowScalar *value)
2237 {
2238   return GARROW_DENSE_UNION_SCALAR(
2239     garrow_union_scalar_new<arrow::DenseUnionScalar>(
2240       GARROW_DATA_TYPE(data_type), type_code, value));
2241 }
2242 
2243 
G_DEFINE_TYPE(GArrowExtensionScalar,garrow_extension_scalar,GARROW_TYPE_SCALAR)2244 G_DEFINE_TYPE(GArrowExtensionScalar,
2245               garrow_extension_scalar,
2246               GARROW_TYPE_SCALAR)
2247 
2248 static void
2249 garrow_extension_scalar_init(GArrowExtensionScalar *object)
2250 {
2251 }
2252 
2253 static void
garrow_extension_scalar_class_init(GArrowExtensionScalarClass * klass)2254 garrow_extension_scalar_class_init(GArrowExtensionScalarClass *klass)
2255 {
2256 }
2257 
2258 
2259 G_END_DECLS
2260 
2261 GArrowScalar *
garrow_scalar_new_raw(std::shared_ptr<arrow::Scalar> * arrow_scalar)2262 garrow_scalar_new_raw(std::shared_ptr<arrow::Scalar> *arrow_scalar)
2263 {
2264   return garrow_scalar_new_raw(arrow_scalar,
2265                                "scalar", arrow_scalar,
2266                                NULL);
2267 }
2268 
2269 GArrowScalar *
garrow_scalar_new_raw(std::shared_ptr<arrow::Scalar> * arrow_scalar,const gchar * first_property_name,...)2270 garrow_scalar_new_raw(std::shared_ptr<arrow::Scalar> *arrow_scalar,
2271                       const gchar *first_property_name,
2272                       ...)
2273 {
2274   va_list args;
2275   va_start(args, first_property_name);
2276   auto array = garrow_scalar_new_raw_valist(arrow_scalar,
2277                                             first_property_name,
2278                                             args);
2279   va_end(args);
2280   return array;
2281 }
2282 
2283 GArrowScalar *
garrow_scalar_new_raw_valist(std::shared_ptr<arrow::Scalar> * arrow_scalar,const gchar * first_property_name,va_list args)2284 garrow_scalar_new_raw_valist(std::shared_ptr<arrow::Scalar> *arrow_scalar,
2285                              const gchar *first_property_name,
2286                              va_list args)
2287 {
2288   GType type;
2289   GArrowScalar *scalar;
2290 
2291   switch ((*arrow_scalar)->type->id()) {
2292   case arrow::Type::type::NA:
2293     type = GARROW_TYPE_NULL_SCALAR;
2294     break;
2295   case arrow::Type::type::BOOL:
2296     type = GARROW_TYPE_BOOLEAN_SCALAR;
2297     break;
2298   case arrow::Type::type::INT8:
2299     type = GARROW_TYPE_INT8_SCALAR;
2300     break;
2301   case arrow::Type::type::INT16:
2302     type = GARROW_TYPE_INT16_SCALAR;
2303     break;
2304   case arrow::Type::type::INT32:
2305     type = GARROW_TYPE_INT32_SCALAR;
2306     break;
2307   case arrow::Type::type::INT64:
2308     type = GARROW_TYPE_INT64_SCALAR;
2309     break;
2310   case arrow::Type::type::UINT8:
2311     type = GARROW_TYPE_UINT8_SCALAR;
2312     break;
2313   case arrow::Type::type::UINT16:
2314     type = GARROW_TYPE_UINT16_SCALAR;
2315     break;
2316   case arrow::Type::type::UINT32:
2317     type = GARROW_TYPE_UINT32_SCALAR;
2318     break;
2319   case arrow::Type::type::UINT64:
2320     type = GARROW_TYPE_UINT64_SCALAR;
2321     break;
2322   case arrow::Type::type::FLOAT:
2323     type = GARROW_TYPE_FLOAT_SCALAR;
2324     break;
2325   case arrow::Type::type::DOUBLE:
2326     type = GARROW_TYPE_DOUBLE_SCALAR;
2327     break;
2328   case arrow::Type::type::BINARY:
2329     type = GARROW_TYPE_BINARY_SCALAR;
2330     break;
2331   case arrow::Type::type::STRING:
2332     type = GARROW_TYPE_STRING_SCALAR;
2333     break;
2334   case arrow::Type::type::LARGE_BINARY:
2335     type = GARROW_TYPE_LARGE_BINARY_SCALAR;
2336     break;
2337   case arrow::Type::type::LARGE_STRING:
2338     type = GARROW_TYPE_LARGE_STRING_SCALAR;
2339     break;
2340   case arrow::Type::type::FIXED_SIZE_BINARY:
2341     type = GARROW_TYPE_FIXED_SIZE_BINARY_SCALAR;
2342     break;
2343   case arrow::Type::type::DATE32:
2344     type = GARROW_TYPE_DATE32_SCALAR;
2345     break;
2346   case arrow::Type::type::DATE64:
2347     type = GARROW_TYPE_DATE64_SCALAR;
2348     break;
2349   case arrow::Type::type::TIME32:
2350     type = GARROW_TYPE_TIME32_SCALAR;
2351     break;
2352   case arrow::Type::type::TIME64:
2353     type = GARROW_TYPE_TIME64_SCALAR;
2354     break;
2355   case arrow::Type::type::TIMESTAMP:
2356     type = GARROW_TYPE_TIMESTAMP_SCALAR;
2357     break;
2358   case arrow::Type::type::DECIMAL128:
2359     type = GARROW_TYPE_DECIMAL128_SCALAR;
2360     break;
2361   case arrow::Type::type::DECIMAL256:
2362     type = GARROW_TYPE_DECIMAL256_SCALAR;
2363     break;
2364   case arrow::Type::type::LIST:
2365     type = GARROW_TYPE_LIST_SCALAR;
2366     break;
2367   case arrow::Type::type::LARGE_LIST:
2368     type = GARROW_TYPE_LARGE_LIST_SCALAR;
2369     break;
2370 /*
2371   case arrow::Type::type::FIXED_SIZE_LIST:
2372     type = GARROW_TYPE_FIXED_SIZE_LIST_SCALAR;
2373     break;
2374 */
2375   case arrow::Type::type::MAP:
2376     type = GARROW_TYPE_MAP_SCALAR;
2377     break;
2378   case arrow::Type::type::STRUCT:
2379     type = GARROW_TYPE_STRUCT_SCALAR;
2380     break;
2381   case arrow::Type::type::SPARSE_UNION:
2382     type = GARROW_TYPE_SPARSE_UNION_SCALAR;
2383     break;
2384   case arrow::Type::type::DENSE_UNION:
2385     type = GARROW_TYPE_DENSE_UNION_SCALAR;
2386     break;
2387   case arrow::Type::type::EXTENSION:
2388     type = GARROW_TYPE_EXTENSION_SCALAR;
2389     break;
2390   default:
2391     type = GARROW_TYPE_SCALAR;
2392     break;
2393   }
2394   scalar = GARROW_SCALAR(g_object_new_valist(type,
2395                                              first_property_name,
2396                                              args));
2397   return scalar;
2398 }
2399 
2400 std::shared_ptr<arrow::Scalar>
garrow_scalar_get_raw(GArrowScalar * scalar)2401 garrow_scalar_get_raw(GArrowScalar *scalar)
2402 {
2403   auto priv = GARROW_SCALAR_GET_PRIVATE(scalar);
2404   return priv->scalar;
2405 }
2406