hiroyuki-sato commented on code in PR #46774: URL: https://github.com/apache/arrow/pull/46774#discussion_r2148104469
########## c_glib/test/test-fixed-size-list-data-type.rb: ########## @@ -0,0 +1,51 @@ +# 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 setup + @value_type = Arrow::BooleanDataType.new + @list_size = 5 + @field_name = "bool_field" + end + + def test_field + field = Arrow::Field.new(@field_name, @value_type) + data_type = Arrow::FixedSizeListDataType.new(field, @list_size); + assert_equal(Arrow::Type::FIXED_SIZE_LIST, data_type.id); Review Comment: I implemented `list_size` property. Shall I update this PR or create another PR? ```ruby def setup @value_type = Arrow::BooleanDataType.new @list_size = 5 @field_name = "bool_field" end def test_field field = Arrow::Field.new(@field_name, @value_type) data_type = Arrow::FixedSizeListDataType.new(field, @list_size) assert_equal(["bool_field", @value_type, @list_size], [data_type.field.name, data_type.field.data_type, data_type.list_size]) end ``` ```diff diff --git a/c_glib/arrow-glib/composite-data-type.cpp b/c_glib/arrow-glib/composite-data-type.cpp index 035846bad1..1193ca9b42 100644 --- a/c_glib/arrow-glib/composite-data-type.cpp +++ b/c_glib/arrow-glib/composite-data-type.cpp @@ -67,6 +67,25 @@ 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 @@ -118,16 +137,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) @@ -769,17 +786,55 @@ 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_init(GArrowFixedSizeListDataType *object) -{ +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", + G_MININT, + 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) { } diff --git a/c_glib/arrow-glib/composite-data-type.h b/c_glib/arrow-glib/composite-data-type.h index 8369ae4987..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, diff --git a/c_glib/test/test-fixed-size-list-data-type.rb b/c_glib/test/test-fixed-size-list-data-type.rb index d8faddb9d9..9546d27405 100644 --- a/c_glib/test/test-fixed-size-list-data-type.rb +++ b/c_glib/test/test-fixed-size-list-data-type.rb @@ -26,20 +26,26 @@ class TestFixedSizeListDataType < Test::Unit::TestCase def test_field field = Arrow::Field.new(@field_name, @value_type) data_type = Arrow::FixedSizeListDataType.new(field, @list_size) - # TODO: check value_field and list_size separately. - assert_equal("fixed_size_list<bool_field: bool>[5]", data_type.to_s) + assert_equal(["bool_field", @value_type, @list_size], + [data_type.field.name, + data_type.field.data_type, + data_type.list_size]) end def test_data_type data_type = Arrow::FixedSizeListDataType.new(@value_type, @list_size) - # TODO: check value_field and list_size separately. - assert_equal("fixed_size_list<item: bool>[5]", data_type.to_s) + assert_equal(["item", @value_type, @list_size], + [data_type.field.name, + data_type.field.data_type, + data_type.list_size]) end end sub_test_case("instance_methods") do def setup - @data_type = Arrow::FixedSizeListDataType.new(Arrow::BooleanDataType.new, 5) + @list_size = 5 + @value_type =Arrow::BooleanDataType.new + @data_type = Arrow::FixedSizeListDataType.new(@value_type, @list_size) end def test_name @@ -49,5 +55,14 @@ class TestFixedSizeListDataType < Test::Unit::TestCase 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 ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
