Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
66fa6f3
GH-46773: [GLib] Add GArrowFixedSizeListDataType
hiroyuki-sato Jun 2, 2025
d36815a
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 12, 2025
5a3b7dc
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 12, 2025
6e4f754
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 12, 2025
daf545e
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 12, 2025
9af3ecc
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 12, 2025
539d3fa
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 12, 2025
89c0c02
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 12, 2025
0174b5a
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 12, 2025
8b3f71d
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 12, 2025
c7a7f15
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 12, 2025
3378ed6
Update c_glib/test/test-fixed-size-list-data-type.rb
hiroyuki-sato Jun 12, 2025
203b45f
Update c_glib/test/test-fixed-size-list-data-type.rb
hiroyuki-sato Jun 12, 2025
300648a
Update c_glib/test/test-fixed-size-list-data-type.rb
hiroyuki-sato Jun 12, 2025
f68e01c
Update c_glib/test/test-fixed-size-list-data-type.rb
hiroyuki-sato Jun 12, 2025
fad642d
Update c_glib/test/test-fixed-size-list-data-type.rb
hiroyuki-sato Jun 12, 2025
6632e5e
GH-46773: [GLib] Add GArrowFixedSizeListDataType
hiroyuki-sato Jun 12, 2025
9f6894f
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 12, 2025
7703330
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 12, 2025
5359b53
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 12, 2025
64314cc
Update c_glib/arrow-glib/composite-data-type.h
hiroyuki-sato Jun 12, 2025
9a0e7d5
GH-46773: [GLib] Add GArrowFixedSizeListDataType
hiroyuki-sato Jun 12, 2025
3cfa7bf
Fix test
hiroyuki-sato Jun 12, 2025
62d8911
Simplified test
hiroyuki-sato Jun 13, 2025
11ed2b4
Add class description
hiroyuki-sato Jun 14, 2025
5519593
Implement field and list_size
hiroyuki-sato Jun 15, 2025
e2f6c2c
Fix lint
hiroyuki-sato Jun 16, 2025
8a9adec
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 17, 2025
e7b4ea4
Update c_glib/test/test-fixed-size-list-data-type.rb
hiroyuki-sato Jun 17, 2025
bb75305
Update c_glib/arrow-glib/composite-data-type.cpp
hiroyuki-sato Jun 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions c_glib/arrow-glib/basic-data-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
121 changes: 115 additions & 6 deletions c_glib/arrow-glib/composite-data-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
25 changes: 25 additions & 0 deletions c_glib/arrow-glib/composite-data-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
61 changes: 61 additions & 0 deletions c_glib/test/test-fixed-size-list-data-type.rb
Original file line number Diff line number Diff line change
@@ -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
Loading