This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new d5171c6b69 GH-48362: [GLib][Ruby] Add FixedSizeListArray (#48369)
d5171c6b69 is described below

commit d5171c6b69b4bc987b1835efc4c1d104dfc05c5b
Author: Sten Larsson <[email protected]>
AuthorDate: Wed Dec 10 22:41:39 2025 +0100

    GH-48362: [GLib][Ruby] Add FixedSizeListArray (#48369)
    
    ### Rationale for this change
    
    The `FixedSizeListArray` class is not available in GLib/Ruby, and it can be 
the result of e.g. the `extract_regex_span` and `list_slice` compute functions.
    
    ### What changes are included in this PR?
    
    This adds the `GArrowFixedSizeListArray` and 
`GArrowFixedSizeListArrayBuilder` to GLib.
    
    ### Are these changes tested?
    
    Yes, with Ruby unit tests.
    
    ### Are there any user-facing changes?
    
    Yes, new classes.
    * GitHub Issue: #48362
    
    Authored-by: Sten Larsson <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 c_glib/arrow-glib/array-builder.cpp               | 122 +++++++++++
 c_glib/arrow-glib/array-builder.h                 |  26 +++
 c_glib/arrow-glib/basic-array.cpp                 |   3 +
 c_glib/arrow-glib/composite-array.cpp             | 250 ++++++++++++++++++++++
 c_glib/arrow-glib/composite-array.h               |  44 ++++
 c_glib/test/helper/buildable.rb                   |  12 +-
 c_glib/test/test-fixed-size-list-array-builder.rb |  97 +++++++++
 c_glib/test/test-fixed-size-list-array.rb         |  80 +++++++
 8 files changed, 633 insertions(+), 1 deletion(-)

diff --git a/c_glib/arrow-glib/array-builder.cpp 
b/c_glib/arrow-glib/array-builder.cpp
index 87e22c7435..e8300692ff 100644
--- a/c_glib/arrow-glib/array-builder.cpp
+++ b/c_glib/arrow-glib/array-builder.cpp
@@ -5674,6 +5674,125 @@ 
garrow_large_list_array_builder_get_value_builder(GArrowLargeListArrayBuilder *b
   return priv->value_builder;
 }
 
+typedef struct GArrowFixedSizeListArrayBuilderPrivate_
+{
+  GArrowArrayBuilder *value_builder;
+} GArrowFixedSizeListArrayBuilderPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE(GArrowFixedSizeListArrayBuilder,
+                           garrow_fixed_size_list_array_builder,
+                           GARROW_TYPE_ARRAY_BUILDER)
+
+#define GARROW_FIXED_SIZE_LIST_ARRAY_BUILDER_GET_PRIVATE(obj)                  
          \
+  static_cast<GArrowFixedSizeListArrayBuilderPrivate *>(                       
          \
+    garrow_fixed_size_list_array_builder_get_instance_private(                 
          \
+      GARROW_FIXED_SIZE_LIST_ARRAY_BUILDER(obj)))
+
+static void
+garrow_fixed_size_list_array_builder_dispose(GObject *object)
+{
+  auto priv = GARROW_FIXED_SIZE_LIST_ARRAY_BUILDER_GET_PRIVATE(object);
+
+  if (priv->value_builder) {
+    g_object_unref(priv->value_builder);
+    priv->value_builder = NULL;
+  }
+
+  
G_OBJECT_CLASS(garrow_fixed_size_list_array_builder_parent_class)->dispose(object);
+}
+
+static void
+garrow_fixed_size_list_array_builder_init(GArrowFixedSizeListArrayBuilder 
*builder)
+{
+}
+
+static void
+garrow_fixed_size_list_array_builder_class_init(
+  GArrowFixedSizeListArrayBuilderClass *klass)
+{
+  auto gobject_class = G_OBJECT_CLASS(klass);
+
+  gobject_class->dispose = garrow_fixed_size_list_array_builder_dispose;
+}
+
+/**
+ * garrow_fixed_size_list_array_builder_new:
+ * @data_type: A #GArrowFixedSizeListDataType for value.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: A newly created #GArrowFixedSizeListArrayBuilder.
+ *
+ * Since: 23.0.0
+ */
+GArrowFixedSizeListArrayBuilder *
+garrow_fixed_size_list_array_builder_new(GArrowFixedSizeListDataType 
*data_type,
+                                         GError **error)
+{
+  if (!GARROW_IS_FIXED_SIZE_LIST_DATA_TYPE(data_type)) {
+    g_set_error(
+      error,
+      GARROW_ERROR,
+      GARROW_ERROR_INVALID,
+      "[fixed-size-list-array-builder][new] data type must be fixed-size list 
data type");
+    return NULL;
+  }
+
+  auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type));
+  auto builder = garrow_array_builder_new(arrow_data_type,
+                                          error,
+                                          
"[fixed-size-list-array-builder][new]");
+  return GARROW_FIXED_SIZE_LIST_ARRAY_BUILDER(builder);
+}
+
+/**
+ * garrow_fixed_size_list_array_builder_append_value:
+ * @builder: A #GArrowFixedSizeListArrayBuilder.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: %TRUE on success, %FALSE if there was an error.
+ *
+ * It appends a new list element. To append a new list element, you
+ * need to call this function then append list element values to
+ * `value_builder`. `value_builder` is the #GArrowArrayBuilder
+ * specified to constructor. You can get `value_builder` by
+ * garrow_fixed_size_list_array_builder_get_value_builder().
+ *
+ * Since: 23.0.0
+ */
+gboolean
+garrow_fixed_size_list_array_builder_append_value(
+  GArrowFixedSizeListArrayBuilder *builder, GError **error)
+{
+  auto arrow_builder = std::static_pointer_cast<arrow::FixedSizeListBuilder>(
+    garrow_array_builder_get_raw(GARROW_ARRAY_BUILDER(builder)));
+  auto status = arrow_builder->Append();
+  return garrow_error_check(error,
+                            status,
+                            "[fixed-size-list-array-builder][append-value]");
+}
+
+/**
+ * garrow_fixed_size_list_array_builder_get_value_builder:
+ * @builder: A #GArrowFixedSizeListArrayBuilder.
+ *
+ * Returns: (transfer none): The #GArrowArrayBuilder for building list element 
values.
+ *
+ * Since: 23.0.0
+ */
+GArrowArrayBuilder *
+garrow_fixed_size_list_array_builder_get_value_builder(
+  GArrowFixedSizeListArrayBuilder *builder)
+{
+  auto priv = GARROW_FIXED_SIZE_LIST_ARRAY_BUILDER_GET_PRIVATE(builder);
+  if (!priv->value_builder) {
+    auto arrow_builder = std::static_pointer_cast<arrow::FixedSizeListBuilder>(
+      garrow_array_builder_get_raw(GARROW_ARRAY_BUILDER(builder)));
+    auto arrow_value_builder = arrow_builder->value_builder();
+    priv->value_builder = garrow_array_builder_new_raw(arrow_value_builder);
+  }
+  return priv->value_builder;
+}
+
 G_DEFINE_TYPE(GArrowStructArrayBuilder,
               garrow_struct_array_builder,
               GARROW_TYPE_ARRAY_BUILDER)
@@ -6779,6 +6898,9 @@ 
garrow_array_builder_new_raw(std::shared_ptr<arrow::ArrayBuilder> *arrow_builder
     case arrow::Type::type::LARGE_LIST:
       type = GARROW_TYPE_LARGE_LIST_ARRAY_BUILDER;
       break;
+    case arrow::Type::type::FIXED_SIZE_LIST:
+      type = GARROW_TYPE_FIXED_SIZE_LIST_ARRAY_BUILDER;
+      break;
     case arrow::Type::type::STRUCT:
       type = GARROW_TYPE_STRUCT_ARRAY_BUILDER;
       break;
diff --git a/c_glib/arrow-glib/array-builder.h 
b/c_glib/arrow-glib/array-builder.h
index c15c411503..a4ccb8d224 100644
--- a/c_glib/arrow-glib/array-builder.h
+++ b/c_glib/arrow-glib/array-builder.h
@@ -1635,6 +1635,32 @@ GARROW_AVAILABLE_IN_0_16
 GArrowArrayBuilder *
 garrow_large_list_array_builder_get_value_builder(GArrowLargeListArrayBuilder 
*builder);
 
+#define GARROW_TYPE_FIXED_SIZE_LIST_ARRAY_BUILDER                              
          \
+  (garrow_fixed_size_list_array_builder_get_type())
+GARROW_AVAILABLE_IN_23_0
+G_DECLARE_DERIVABLE_TYPE(GArrowFixedSizeListArrayBuilder,
+                         garrow_fixed_size_list_array_builder,
+                         GARROW,
+                         FIXED_SIZE_LIST_ARRAY_BUILDER,
+                         GArrowArrayBuilder)
+struct _GArrowFixedSizeListArrayBuilderClass
+{
+  GArrowArrayBuilderClass parent_class;
+};
+
+GARROW_AVAILABLE_IN_23_0
+GArrowFixedSizeListArrayBuilder *
+garrow_fixed_size_list_array_builder_new(GArrowFixedSizeListDataType 
*data_type,
+                                         GError **error);
+GARROW_AVAILABLE_IN_23_0
+gboolean
+garrow_fixed_size_list_array_builder_append_value(
+  GArrowFixedSizeListArrayBuilder *builder, GError **error);
+GARROW_AVAILABLE_IN_23_0
+GArrowArrayBuilder *
+garrow_fixed_size_list_array_builder_get_value_builder(
+  GArrowFixedSizeListArrayBuilder *builder);
+
 #define GARROW_TYPE_STRUCT_ARRAY_BUILDER 
(garrow_struct_array_builder_get_type())
 GARROW_AVAILABLE_IN_ALL
 G_DECLARE_DERIVABLE_TYPE(GArrowStructArrayBuilder,
diff --git a/c_glib/arrow-glib/basic-array.cpp 
b/c_glib/arrow-glib/basic-array.cpp
index 34b577ea1a..e42d2ed162 100644
--- a/c_glib/arrow-glib/basic-array.cpp
+++ b/c_glib/arrow-glib/basic-array.cpp
@@ -4005,6 +4005,9 @@ garrow_array_new_raw_valist(std::shared_ptr<arrow::Array> 
*arrow_array,
   case arrow::Type::type::LARGE_LIST:
     type = GARROW_TYPE_LARGE_LIST_ARRAY;
     break;
+  case arrow::Type::type::FIXED_SIZE_LIST:
+    type = GARROW_TYPE_FIXED_SIZE_LIST_ARRAY;
+    break;
   case arrow::Type::type::STRUCT:
     type = GARROW_TYPE_STRUCT_ARRAY;
     break;
diff --git a/c_glib/arrow-glib/composite-array.cpp 
b/c_glib/arrow-glib/composite-array.cpp
index d49b393605..9bc53264b7 100644
--- a/c_glib/arrow-glib/composite-array.cpp
+++ b/c_glib/arrow-glib/composite-array.cpp
@@ -40,6 +40,11 @@ G_BEGIN_DECLS
  * It can store zero or more list data. If you don't have Arrow format data,
  * you need to use #GArrowLargeListArrayBuilder to create a new array.
  *
+ * #GArrowFixedSizeListArray is a class for fixed-size list array.
+ * It can store zero or more list data where each list has the same size.
+ * If you don't have Arrow format data, you need to use
+ * #GArrowFixedSizeListArrayBuilder to create a new array.
+ *
  * #GArrowStructArray is a class for struct array. It can store zero
  * or more structs. One struct has one or more fields. If you don't
  * have Arrow format data, you need to use #GArrowStructArrayBuilder
@@ -597,6 +602,251 @@ 
garrow_large_list_array_get_value_offsets(GArrowLargeListArray *array, gint64 *n
   return reinterpret_cast<const gint64 *>(value_offsets);
 }
 
+typedef struct GArrowFixedSizeListArrayPrivate_
+{
+  GArrowArray *raw_values;
+} GArrowFixedSizeListArrayPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE(GArrowFixedSizeListArray,
+                           garrow_fixed_size_list_array,
+                           GARROW_TYPE_ARRAY)
+
+#define GARROW_FIXED_SIZE_LIST_ARRAY_GET_PRIVATE(obj)                          
          \
+  static_cast<GArrowFixedSizeListArrayPrivate *>(                              
          \
+    garrow_fixed_size_list_array_get_instance_private(                         
          \
+      GARROW_FIXED_SIZE_LIST_ARRAY(obj)))
+
+static void
+garrow_fixed_size_list_array_dispose(GObject *object)
+{
+  auto priv = GARROW_FIXED_SIZE_LIST_ARRAY_GET_PRIVATE(object);
+
+  if (priv->raw_values) {
+    g_object_unref(priv->raw_values);
+    priv->raw_values = NULL;
+  }
+
+  G_OBJECT_CLASS(garrow_fixed_size_list_array_parent_class)->dispose(object);
+}
+
+static void
+garrow_fixed_size_list_array_set_property(GObject *object,
+                                          guint prop_id,
+                                          const GValue *value,
+                                          GParamSpec *pspec)
+{
+  auto priv = GARROW_FIXED_SIZE_LIST_ARRAY_GET_PRIVATE(object);
+
+  switch (prop_id) {
+  case PROP_RAW_VALUES:
+    priv->raw_values = GARROW_ARRAY(g_value_dup_object(value));
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+garrow_fixed_size_list_array_get_property(GObject *object,
+                                          guint prop_id,
+                                          GValue *value,
+                                          GParamSpec *pspec)
+{
+  auto priv = GARROW_FIXED_SIZE_LIST_ARRAY_GET_PRIVATE(object);
+
+  switch (prop_id) {
+  case PROP_RAW_VALUES:
+    g_value_set_object(value, priv->raw_values);
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+garrow_fixed_size_list_array_init(GArrowFixedSizeListArray *object)
+{
+}
+
+static void
+garrow_fixed_size_list_array_class_init(GArrowFixedSizeListArrayClass *klass)
+{
+  auto gobject_class = G_OBJECT_CLASS(klass);
+
+  gobject_class->dispose = garrow_fixed_size_list_array_dispose;
+  gobject_class->set_property = garrow_fixed_size_list_array_set_property;
+  gobject_class->get_property = garrow_fixed_size_list_array_get_property;
+
+  GParamSpec *spec;
+  spec = g_param_spec_object(
+    "raw-values",
+    "Raw values",
+    "The raw values",
+    GARROW_TYPE_ARRAY,
+    static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property(gobject_class, PROP_RAW_VALUES, spec);
+}
+
+/**
+ * garrow_fixed_size_list_array_new:
+ * @data_type: The data type of the list.
+ * @length: The number of elements.
+ * @values: The values as #GArrowArray.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowFixedSizeListArray.
+ *
+ * Since: 23.0.0
+ */
+GArrowFixedSizeListArray *
+garrow_fixed_size_list_array_new(GArrowDataType *data_type,
+                                 gint64 length,
+                                 GArrowArray *values,
+                                 GArrowBuffer *null_bitmap,
+                                 gint64 n_nulls)
+{
+  const auto arrow_data_type = garrow_data_type_get_raw(data_type);
+  const auto arrow_values = garrow_array_get_raw(values);
+  const auto arrow_null_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_fixed_size_list_array =
+    std::make_shared<arrow::FixedSizeListArray>(arrow_data_type,
+                                                length,
+                                                arrow_values,
+                                                arrow_null_bitmap,
+                                                n_nulls);
+  auto arrow_array = 
std::static_pointer_cast<arrow::Array>(arrow_fixed_size_list_array);
+  return GARROW_FIXED_SIZE_LIST_ARRAY(garrow_array_new_raw(&arrow_array,
+                                                           "array",
+                                                           &arrow_array,
+                                                           "value-data-type",
+                                                           data_type,
+                                                           "null-bitmap",
+                                                           null_bitmap,
+                                                           "raw-values",
+                                                           values,
+                                                           NULL));
+}
+
+/**
+ * garrow_fixed_size_list_array_get_value_type:
+ * @array: A #GArrowFixedSizeListArray.
+ *
+ * Returns: (transfer full): The data type of value in each list.
+ *
+ * Since: 23.0.0
+ */
+GArrowDataType *
+garrow_fixed_size_list_array_get_value_type(GArrowFixedSizeListArray *array)
+{
+  auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+  auto arrow_fixed_size_list_array =
+    std::static_pointer_cast<arrow::FixedSizeListArray>(arrow_array);
+  auto arrow_value_type = arrow_fixed_size_list_array->value_type();
+  return garrow_data_type_new_raw(&arrow_value_type);
+}
+
+/**
+ * garrow_fixed_size_list_array_get_value:
+ * @array: A #GArrowFixedSizeListArray.
+ * @i: The index of the target value.
+ *
+ * Returns: (transfer full): The @i-th list.
+ *
+ * Since: 23.0.0
+ */
+GArrowArray *
+garrow_fixed_size_list_array_get_value(GArrowFixedSizeListArray *array, gint64 
i)
+{
+  auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+  auto arrow_fixed_size_list_array =
+    std::static_pointer_cast<arrow::FixedSizeListArray>(arrow_array);
+  auto arrow_list = arrow_fixed_size_list_array->value_slice(i);
+  return garrow_array_new_raw(&arrow_list, "array", &arrow_list, "parent", 
array, NULL);
+}
+
+/**
+ * garrow_fixed_size_list_array_get_values:
+ * @array: A #GArrowFixedSizeListArray.
+ *
+ * Returns: (transfer full): The array containing the list's values.
+ *
+ * Since: 23.0.0
+ */
+GArrowArray *
+garrow_fixed_size_list_array_get_values(GArrowFixedSizeListArray *array)
+{
+  auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+  auto arrow_fixed_size_list_array =
+    std::static_pointer_cast<arrow::FixedSizeListArray>(arrow_array);
+  auto arrow_values = arrow_fixed_size_list_array->values();
+  return garrow_array_new_raw(&arrow_values,
+                              "array",
+                              &arrow_values,
+                              "parent",
+                              array,
+                              NULL);
+}
+
+/**
+ * garrow_fixed_size_list_array_get_value_offset:
+ * @array: A #GArrowFixedSizeListArray.
+ * @i: The index of the offset of the target value.
+ *
+ * Returns: The target offset in the array containing the list's values.
+ *
+ * Since: 23.0.0
+ */
+gint64
+garrow_fixed_size_list_array_get_value_offset(GArrowFixedSizeListArray *array, 
gint64 i)
+{
+  auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+  auto arrow_fixed_size_list_array =
+    std::static_pointer_cast<arrow::FixedSizeListArray>(arrow_array);
+  return arrow_fixed_size_list_array->value_offset(i);
+}
+
+/**
+ * garrow_fixed_size_list_array_get_value_length:
+ * @array: A #GArrowFixedSizeListArray.
+ * @i: The index of the target value (unused, as all lists have the same size).
+ *
+ * Returns: The fixed size of each list.
+ *
+ * Since: 23.0.0
+ */
+gint32
+garrow_fixed_size_list_array_get_value_length(GArrowFixedSizeListArray *array, 
gint64 i)
+{
+  auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+  auto arrow_fixed_size_list_array =
+    std::static_pointer_cast<arrow::FixedSizeListArray>(arrow_array);
+  return arrow_fixed_size_list_array->value_length(i);
+}
+
+/**
+ * garrow_fixed_size_list_array_get_list_size:
+ * @array: A #GArrowFixedSizeListArray.
+ *
+ * Returns: The fixed size of each list.
+ *
+ * Since: 23.0.0
+ */
+gint32
+garrow_fixed_size_list_array_get_list_size(GArrowFixedSizeListArray *array)
+{
+  auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+  auto arrow_fixed_size_list_array =
+    std::static_pointer_cast<arrow::FixedSizeListArray>(arrow_array);
+  return arrow_fixed_size_list_array->list_type()->list_size();
+}
+
 typedef struct GArrowStructArrayPrivate_
 {
   GPtrArray *fields;
diff --git a/c_glib/arrow-glib/composite-array.h 
b/c_glib/arrow-glib/composite-array.h
index b8ba901363..117ffdf707 100644
--- a/c_glib/arrow-glib/composite-array.h
+++ b/c_glib/arrow-glib/composite-array.h
@@ -110,6 +110,50 @@ GARROW_AVAILABLE_IN_2_0
 const gint64 *
 garrow_large_list_array_get_value_offsets(GArrowLargeListArray *array, gint64 
*n_offsets);
 
+#define GARROW_TYPE_FIXED_SIZE_LIST_ARRAY 
(garrow_fixed_size_list_array_get_type())
+GARROW_AVAILABLE_IN_23_0
+G_DECLARE_DERIVABLE_TYPE(GArrowFixedSizeListArray,
+                         garrow_fixed_size_list_array,
+                         GARROW,
+                         FIXED_SIZE_LIST_ARRAY,
+                         GArrowArray)
+struct _GArrowFixedSizeListArrayClass
+{
+  GArrowArrayClass parent_class;
+};
+
+GARROW_AVAILABLE_IN_23_0
+GArrowFixedSizeListArray *
+garrow_fixed_size_list_array_new(GArrowDataType *data_type,
+                                 gint64 length,
+                                 GArrowArray *values,
+                                 GArrowBuffer *null_bitmap,
+                                 gint64 n_nulls);
+
+GARROW_AVAILABLE_IN_23_0
+GArrowDataType *
+garrow_fixed_size_list_array_get_value_type(GArrowFixedSizeListArray *array);
+
+GARROW_AVAILABLE_IN_23_0
+GArrowArray *
+garrow_fixed_size_list_array_get_value(GArrowFixedSizeListArray *array, gint64 
i);
+
+GARROW_AVAILABLE_IN_23_0
+GArrowArray *
+garrow_fixed_size_list_array_get_values(GArrowFixedSizeListArray *array);
+
+GARROW_AVAILABLE_IN_23_0
+gint64
+garrow_fixed_size_list_array_get_value_offset(GArrowFixedSizeListArray *array, 
gint64 i);
+
+GARROW_AVAILABLE_IN_23_0
+gint32
+garrow_fixed_size_list_array_get_value_length(GArrowFixedSizeListArray *array, 
gint64 i);
+
+GARROW_AVAILABLE_IN_23_0
+gint32
+garrow_fixed_size_list_array_get_list_size(GArrowFixedSizeListArray *array);
+
 #define GARROW_TYPE_STRUCT_ARRAY (garrow_struct_array_get_type())
 GARROW_AVAILABLE_IN_ALL
 G_DECLARE_DERIVABLE_TYPE(
diff --git a/c_glib/test/helper/buildable.rb b/c_glib/test/helper/buildable.rb
index b0156f9c8e..e7c4f98d53 100644
--- a/c_glib/test/helper/buildable.rb
+++ b/c_glib/test/helper/buildable.rb
@@ -172,6 +172,16 @@ module Helper
       builder.finish
     end
 
+    def build_fixed_size_list_array(value_data_type, list_size, values_list, 
field_name: "value")
+      value_field = Arrow::Field.new(field_name, value_data_type)
+      data_type = Arrow::FixedSizeListDataType.new(value_field, list_size)
+      builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+      values_list.each do |values|
+        append_to_builder(builder, values)
+      end
+      builder.finish
+    end
+
     def build_map_array(key_data_type, item_data_type, maps)
       data_type = Arrow::MapDataType.new(key_data_type, item_data_type)
       builder = Arrow::MapArrayBuilder.new(data_type)
@@ -204,7 +214,7 @@ module Helper
             append_to_builder(key_builder, k)
             append_to_builder(item_builder, v)
           end
-        when Arrow::ListDataType, Arrow::LargeListDataType
+        when Arrow::ListDataType, Arrow::LargeListDataType, 
Arrow::FixedSizeListDataType
           builder.append_value
           value_builder = builder.value_builder
           value.each do |v|
diff --git a/c_glib/test/test-fixed-size-list-array-builder.rb 
b/c_glib/test/test-fixed-size-list-array-builder.rb
new file mode 100644
index 0000000000..dcd518043b
--- /dev/null
+++ b/c_glib/test/test-fixed-size-list-array-builder.rb
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestFixedSizeListArrayBuilder < Test::Unit::TestCase
+  include Helper::Buildable
+  include Helper::Omittable
+
+  def setup
+    require_gi_bindings(3, 1, 9)
+  end
+
+  def get_value(array, i)
+    value = array.get_value(i)
+    value.length.times.collect do |j|
+      value.get_value(j)
+    end
+  end
+
+  def test_new
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    assert_equal(data_type, builder.value_data_type)
+  end
+
+  def test_append_value
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    value_builder = builder.value_builder
+
+    # Append first list: [1, 2]
+    builder.append_value
+    value_builder.append_value(1)
+    value_builder.append_value(2)
+
+    # Append second list: [3, 4]
+    builder.append_value
+    value_builder.append_value(3)
+    value_builder.append_value(4)
+
+    array = builder.finish
+    assert_equal(2, array.length)
+    assert_equal([1, 2], get_value(array, 0))
+    assert_equal([3, 4], get_value(array, 1))
+  end
+
+  def test_append_null
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    value_builder = builder.value_builder
+
+    # Append first list: [1, 2]
+    builder.append_value
+    value_builder.append_value(1)
+    value_builder.append_value(2)
+
+    # Append null list
+    builder.append_null
+
+    # Append third list: [5, 6]
+    builder.append_value
+    value_builder.append_value(5)
+    value_builder.append_value(6)
+
+    array = builder.finish
+    assert_equal(3, array.length)
+    assert_equal([1, 2], get_value(array, 0))
+    assert do
+      array.null?(1)
+    end
+    assert_equal([5, 6], get_value(array, 2))
+  end
+
+  def test_value_builder
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    value_builder = builder.value_builder
+    assert_equal(Arrow::Int8DataType.new, value_builder.value_data_type)
+  end
+end
diff --git a/c_glib/test/test-fixed-size-list-array.rb 
b/c_glib/test/test-fixed-size-list-array.rb
new file mode 100644
index 0000000000..8eb4c15efd
--- /dev/null
+++ b/c_glib/test/test-fixed-size-list-array.rb
@@ -0,0 +1,80 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestFixedSizeListArray < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    data = Arrow::Buffer.new([1, 2, 3, 4].pack("c*"))
+    nulls = Arrow::Buffer.new([0b1111].pack("C*"))
+    values = Arrow::Int8Array.new(4, data, nulls, 0)
+    assert_equal(build_fixed_size_list_array(Arrow::Int8DataType.new, 2,
+                                             [[1, 2], [3, 4]]),
+                 Arrow::FixedSizeListArray.new(data_type,
+                                               2,
+                                               values,
+                                               
Arrow::Buffer.new([0b11].pack("C*")),
+                                               -1))
+  end
+
+  def test_value
+    array = build_fixed_size_list_array(Arrow::Int8DataType.new, 2,
+                                        [[1, 2], [3, 4]])
+    value = array.get_value(1)
+    assert_equal([3, 4],
+                 value.length.times.collect {|i| value.get_value(i)})
+  end
+
+  def test_value_type
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    array = builder.finish
+    assert_equal(Arrow::Int8DataType.new, array.value_type)
+  end
+
+  def test_values
+    array = build_fixed_size_list_array(Arrow::Int8DataType.new, 2,
+                                        [[1, 2], [3, 4]])
+    values = array.values
+    assert_equal([1, 2, 3, 4],
+                 values.length.times.collect {|i| values.get_value(i)})
+  end
+
+  def test_value_offset
+    array = build_fixed_size_list_array(Arrow::Int8DataType.new, 2,
+                                        [[1, 2], [3, 4]])
+    assert_equal([0, 2],
+                 array.length.times.collect {|i| array.get_value_offset(i)})
+  end
+
+  def test_value_length
+    array = build_fixed_size_list_array(Arrow::Int8DataType.new, 2,
+                                        [[1, 2], [3, 4]])
+    # All lists have the same fixed size
+    assert_equal([2, 2],
+                 array.length.times.collect {|i| array.get_value_length(i)})
+  end
+
+  def test_list_size
+    array = build_fixed_size_list_array(Arrow::Int8DataType.new, 2,
+                                        [[1, 2], [3, 4]])
+    assert_equal(2, array.list_size)
+  end
+end

Reply via email to