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 93cae033fa GH-46773: [GLib] Add GArrowFixedSizeListDataType (#46774)
93cae033fa is described below

commit 93cae033fab29f8ebea38b649493cc4fc250fef9
Author: Hiroyuki Sato <[email protected]>
AuthorDate: Tue Jun 17 11:01:53 2025 +0900

    GH-46773: [GLib] Add GArrowFixedSizeListDataType (#46774)
    
    ### Rationale for this change
    
    GLib should be able to use `arrow::FixedSizeListType`.
    
    ### What changes are included in this PR?
    
    Add `GArrowFixedSizeListDataType`.
    
    ### Are these changes tested?
    
    Yes.
    
    ### Are there any user-facing changes?
    
    Yes.
    * GitHub Issue: #46773
    
    Lead-authored-by: Hiroyuki Sato <[email protected]>
    Co-authored-by: Sutou Kouhei <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 c_glib/arrow-glib/basic-data-type.cpp         |   3 +
 c_glib/arrow-glib/composite-data-type.cpp     | 121 ++++++++++++++++++++++++--
 c_glib/arrow-glib/composite-data-type.h       |  25 ++++++
 c_glib/test/test-fixed-size-list-data-type.rb |  61 +++++++++++++
 4 files changed, 204 insertions(+), 6 deletions(-)

diff --git a/c_glib/arrow-glib/basic-data-type.cpp 
b/c_glib/arrow-glib/basic-data-type.cpp
index 27bae3b220..51fffb7369 100644
--- a/c_glib/arrow-glib/basic-data-type.cpp
+++ b/c_glib/arrow-glib/basic-data-type.cpp
@@ -2652,6 +2652,9 @@ garrow_data_type_new_raw(std::shared_ptr<arrow::DataType> 
*arrow_data_type)
     }
     type = GARROW_TYPE_EXTENSION_DATA_TYPE;
     break;
+  case arrow::Type::type::FIXED_SIZE_LIST:
+    type = GARROW_TYPE_FIXED_SIZE_LIST_DATA_TYPE;
+    break;
   case arrow::Type::type::RUN_END_ENCODED:
     type = GARROW_TYPE_RUN_END_ENCODED_DATA_TYPE;
     break;
diff --git a/c_glib/arrow-glib/composite-data-type.cpp 
b/c_glib/arrow-glib/composite-data-type.cpp
index 8af1b0c862..3c216867da 100644
--- a/c_glib/arrow-glib/composite-data-type.cpp
+++ b/c_glib/arrow-glib/composite-data-type.cpp
@@ -51,6 +51,8 @@ G_BEGIN_DECLS
  * #GArrowDictionaryDataType is a class for dictionary data type.
  *
  * #GArrowRunEndEncodedDataType is a class for run end encoded data type.
+ *
+ * #GArrowFixedSizeListDataType is a class for fixed size list data type.
  */
 
 G_DEFINE_TYPE(GArrowBaseListDataType, garrow_base_list_data_type, 
GARROW_TYPE_DATA_TYPE)
@@ -65,6 +67,26 @@ 
garrow_base_list_data_type_class_init(GArrowBaseListDataTypeClass *klass)
 {
 }
 
+/**
+ * garrow_base_list_data_type_get_field:
+ * @base_list_data_type: A #GArrowBaseListDataType.
+ *
+ * Returns: (transfer full): The field of value.
+ *
+ * Since: 21.0.0
+ */
+GArrowField *
+garrow_base_list_data_type_get_field(GArrowBaseListDataType 
*base_list_data_type)
+{
+  auto data_type = GARROW_DATA_TYPE(base_list_data_type);
+  auto arrow_data_type = garrow_data_type_get_raw(data_type);
+  auto arrow_base_list_data_type =
+    std::static_pointer_cast<arrow::BaseListType>(arrow_data_type);
+
+  auto arrow_field = arrow_base_list_data_type->value_field();
+  return garrow_field_new_raw(&arrow_field, nullptr);
+}
+
 G_DEFINE_TYPE(GArrowListDataType, garrow_list_data_type, 
GARROW_TYPE_BASE_LIST_DATA_TYPE)
 
 static void
@@ -116,16 +138,14 @@ garrow_list_data_type_get_value_field(GArrowListDataType 
*list_data_type)
  * Returns: (transfer full): The field of value.
  *
  * Since: 0.13.0
+ *
+ * Deprecated: 21.0.0:
+ *   Use garrow_base_list_data_type_get_field() instead.
  */
 GArrowField *
 garrow_list_data_type_get_field(GArrowListDataType *list_data_type)
 {
-  auto data_type = GARROW_DATA_TYPE(list_data_type);
-  auto arrow_data_type = garrow_data_type_get_raw(data_type);
-  auto arrow_list_data_type = static_cast<arrow::ListType 
*>(arrow_data_type.get());
-
-  auto arrow_field = arrow_list_data_type->value_field();
-  return garrow_field_new_raw(&arrow_field, nullptr);
+  return 
garrow_base_list_data_type_get_field(GARROW_BASE_LIST_DATA_TYPE(list_data_type));
 }
 
 G_DEFINE_TYPE(GArrowLargeListDataType, garrow_large_list_data_type, 
GARROW_TYPE_DATA_TYPE)
@@ -767,4 +787,93 @@ garrow_run_end_encoded_data_type_get_value_data_type(
   return garrow_data_type_new_raw(&arrow_value_data_type);
 }
 
+enum {
+  PROP_LIST_SIZE = 1
+};
+
+G_DEFINE_TYPE(GArrowFixedSizeListDataType,
+              garrow_fixed_size_list_data_type,
+              GARROW_TYPE_BASE_LIST_DATA_TYPE)
+
+static void
+garrow_fixed_size_list_data_type_get_property(GObject *object,
+                                              guint prop_id,
+                                              GValue *value,
+                                              GParamSpec *pspec)
+{
+  auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(object));
+  const auto arrow_fixed_size_list_type =
+    std::static_pointer_cast<arrow::FixedSizeListType>(arrow_data_type);
+
+  switch (prop_id) {
+  case PROP_LIST_SIZE:
+    g_value_set_int(value, arrow_fixed_size_list_type->list_size());
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+garrow_fixed_size_list_data_type_class_init(GArrowFixedSizeListDataTypeClass 
*klass)
+{
+  GObjectClass *gobject_class;
+  GParamSpec *spec;
+
+  gobject_class = G_OBJECT_CLASS(klass);
+  gobject_class->get_property = garrow_fixed_size_list_data_type_get_property;
+
+  spec = g_param_spec_int("list-size",
+                          "List size",
+                          "The list size of the elements",
+                          0,
+                          G_MAXINT,
+                          0,
+                          G_PARAM_READABLE);
+  g_object_class_install_property(gobject_class, PROP_LIST_SIZE, spec);
+}
+
+static void
+garrow_fixed_size_list_data_type_init(GArrowFixedSizeListDataType *object)
+{
+}
+
+/**
+ * garrow_fixed_size_list_data_type_new_data_type:
+ * @value_type: The data type of an element of each list.
+ * @list_size: The size of each list.
+ *
+ * Returns: A newly created fixed size list data type.
+ *
+ * Since: 21.0.0
+ */
+GArrowFixedSizeListDataType *
+garrow_fixed_size_list_data_type_new_data_type(GArrowDataType *value_type,
+                                               gint32 list_size)
+{
+  auto arrow_value_type = garrow_data_type_get_raw(value_type);
+  auto arrow_fixed_size_list_data_type =
+    arrow::fixed_size_list(arrow_value_type, list_size);
+  return GARROW_FIXED_SIZE_LIST_DATA_TYPE(
+    garrow_data_type_new_raw(&arrow_fixed_size_list_data_type));
+}
+
+/**
+ * garrow_fixed_size_list_data_type_new_field:
+ * @field: The field of lists.
+ * @list_size: The size of value.
+ *
+ * Returns: A newly created fixed size list data type.
+ *
+ * Since: 21.0.0
+ */
+GArrowFixedSizeListDataType *
+garrow_fixed_size_list_data_type_new_field(GArrowField *field, gint32 
list_size)
+{
+  auto arrow_field = garrow_field_get_raw(field);
+  auto arrow_fixed_size_list_data_type = arrow::fixed_size_list(arrow_field, 
list_size);
+  return GARROW_FIXED_SIZE_LIST_DATA_TYPE(
+    garrow_data_type_new_raw(&arrow_fixed_size_list_data_type));
+}
 G_END_DECLS
diff --git a/c_glib/arrow-glib/composite-data-type.h 
b/c_glib/arrow-glib/composite-data-type.h
index de9449c41c..207647bd46 100644
--- a/c_glib/arrow-glib/composite-data-type.h
+++ b/c_glib/arrow-glib/composite-data-type.h
@@ -38,6 +38,10 @@ struct _GArrowBaseListDataTypeClass
   GArrowDataTypeClass parent_class;
 };
 
+GARROW_AVAILABLE_IN_21_0
+GArrowField *
+garrow_base_list_data_type_get_field(GArrowBaseListDataType 
*base_list_data_type);
+
 #define GARROW_TYPE_LIST_DATA_TYPE (garrow_list_data_type_get_type())
 GARROW_AVAILABLE_IN_ALL
 G_DECLARE_DERIVABLE_TYPE(GArrowListDataType,
@@ -256,4 +260,25 @@ GArrowDataType *
 garrow_run_end_encoded_data_type_get_value_data_type(
   GArrowRunEndEncodedDataType *data_type);
 
+#define GARROW_TYPE_FIXED_SIZE_LIST_DATA_TYPE                                  
          \
+  (garrow_fixed_size_list_data_type_get_type())
+GARROW_AVAILABLE_IN_21_0
+G_DECLARE_DERIVABLE_TYPE(GArrowFixedSizeListDataType,
+                         garrow_fixed_size_list_data_type,
+                         GARROW,
+                         FIXED_SIZE_LIST_DATA_TYPE,
+                         GArrowBaseListDataType)
+struct _GArrowFixedSizeListDataTypeClass
+{
+  GArrowBaseListDataTypeClass parent_class;
+};
+
+GARROW_AVAILABLE_IN_21_0
+GArrowFixedSizeListDataType *
+garrow_fixed_size_list_data_type_new_data_type(GArrowDataType *value_type,
+                                               gint32 list_size);
+
+GARROW_AVAILABLE_IN_21_0
+GArrowFixedSizeListDataType *
+garrow_fixed_size_list_data_type_new_field(GArrowField *field, gint32 
list_size);
 G_END_DECLS
diff --git a/c_glib/test/test-fixed-size-list-data-type.rb 
b/c_glib/test/test-fixed-size-list-data-type.rb
new file mode 100644
index 0000000000..8266fbccf3
--- /dev/null
+++ b/c_glib/test/test-fixed-size-list-data-type.rb
@@ -0,0 +1,61 @@
+# 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 TestFixedSizeListDataType < Test::Unit::TestCase
+  sub_test_case(".new") do
+    def test_field
+      list_size = 5
+      field_name = "bool_field"
+      field = Arrow::Field.new("bool_field", Arrow::BooleanDataType.new)
+      data_type = Arrow::FixedSizeListDataType.new(field, list_size)
+      assert_equal([field, list_size], [data_type.field, data_type.list_size])
+    end
+
+    def test_data_type
+      value_type = Arrow::BooleanDataType.new
+      list_size = 5
+      data_type = Arrow::FixedSizeListDataType.new(value_type, list_size)
+      field = Arrow::Field.new("item", value_type)
+      assert_equal([field, list_size], [data_type.field, data_type.list_size])
+    end
+  end
+
+  sub_test_case("instance_methods") do
+    def setup
+      @list_size = 5
+      @value_type = Arrow::BooleanDataType.new
+      @data_type = Arrow::FixedSizeListDataType.new(@value_type, @list_size)
+    end
+
+    def test_name
+      assert_equal("fixed_size_list", @data_type.name);
+    end
+
+    def test_to_s
+      assert_equal("fixed_size_list<item: bool>[5]", @data_type.to_s)
+    end
+
+    def test_list_size
+      assert_equal(@list_size, @data_type.list_size)
+    end
+
+    def test_field
+      field = Arrow::Field.new("item", @value_type)
+      assert_equal(field, @data_type.field)
+    end
+  end
+end

Reply via email to