Skip to content

Commit cfff4d5

Browse files
GH-46556: [GLib] Add GArrowUUIDDataType (#46558)
### Rationale for this change GLib should be able to use `arrow::extension:UuidType`. ### What changes are included in this PR? Add `GArrowUuidDataType` ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * GitHub Issue: #46556 Authored-by: Hiroyuki Sato <hiroysato@gmail.com> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
1 parent 7f1a951 commit cfff4d5

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

c_glib/arrow-glib/basic-data-type.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <arrow/c/bridge.h>
2929
#include <arrow/extension/fixed_shape_tensor.h>
30+
#include <arrow/extension/uuid.h>
3031

3132
G_BEGIN_DECLS
3233

@@ -134,6 +135,8 @@ G_BEGIN_DECLS
134135
* #GArrowBinaryViewDataType is a class for the binary view data type.
135136
*
136137
* #GArrowFixedShapeTensorDataType is a class for the fixed shape tensor data type.
138+
*
139+
* #GArrowUUIDDataType is a class for UUID data type.
137140
*/
138141

139142
struct GArrowDataTypePrivate
@@ -2483,6 +2486,40 @@ garrow_fixed_shape_tensor_data_type_get_strides(GArrowFixedShapeTensorDataType *
24832486
*length = arrow_strides.size();
24842487
return arrow_strides.data();
24852488
}
2489+
2490+
G_DEFINE_TYPE(GArrowUUIDDataType, garrow_uuid_data_type, GARROW_TYPE_EXTENSION_DATA_TYPE)
2491+
2492+
static void
2493+
garrow_uuid_data_type_init(GArrowUUIDDataType *object)
2494+
{
2495+
}
2496+
2497+
static void
2498+
garrow_uuid_data_type_class_init(GArrowUUIDDataTypeClass *klass)
2499+
{
2500+
}
2501+
2502+
/*
2503+
* garrow_uuid_data_type_new:
2504+
* @error: (nullable): Return location for a #GError or %NULL.
2505+
*
2506+
* Returns: (nullable):
2507+
* The newly created UUID data type on success, %NULL on error.
2508+
*
2509+
* Since: 21.0.0
2510+
*/
2511+
GArrowUUIDDataType *
2512+
garrow_uuid_data_type_new(GError **error)
2513+
{
2514+
auto arrow_data_type_result = arrow::extension::UuidType::Make();
2515+
if (garrow::check(error, arrow_data_type_result, "[uuid-data-type][new]")) {
2516+
auto arrow_data_type = *arrow_data_type_result;
2517+
return GARROW_UUID_DATA_TYPE(
2518+
g_object_new(GARROW_TYPE_UUID_DATA_TYPE, "data-type", &arrow_data_type, NULL));
2519+
} else {
2520+
return NULL;
2521+
}
2522+
}
24862523
G_END_DECLS
24872524

24882525
GArrowDataType *

c_glib/arrow-glib/basic-data-type.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,4 +845,20 @@ GARROW_AVAILABLE_IN_21_0
845845
const gint64 *
846846
garrow_fixed_shape_tensor_data_type_get_strides(GArrowFixedShapeTensorDataType *data_type,
847847
gsize *length);
848+
849+
#define GARROW_TYPE_UUID_DATA_TYPE (garrow_uuid_data_type_get_type())
850+
GARROW_AVAILABLE_IN_21_0
851+
G_DECLARE_DERIVABLE_TYPE(GArrowUUIDDataType,
852+
garrow_uuid_data_type,
853+
GARROW,
854+
UUID_DATA_TYPE,
855+
GArrowExtensionDataType)
856+
struct _GArrowUUIDDataTypeClass
857+
{
858+
GArrowExtensionDataTypeClass parent_class;
859+
};
860+
861+
GARROW_AVAILABLE_IN_21_0
862+
GArrowUUIDDataType *
863+
garrow_uuid_data_type_new(GError **error);
848864
G_END_DECLS

c_glib/test/test-uuid-data-type.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
class TestUUIDDataType < Test::Unit::TestCase
19+
def setup
20+
@data_type = Arrow::UUIDDataType.new
21+
end
22+
23+
def test_id
24+
assert_equal(Arrow::Type::EXTENSION, @data_type.id)
25+
end
26+
27+
def test_name
28+
assert_equal(["extension", "arrow.uuid"],
29+
[@data_type.name, @data_type.extension_name])
30+
end
31+
32+
def test_to_s
33+
assert_equal("extension<arrow.uuid>", @data_type.to_s)
34+
end
35+
end

0 commit comments

Comments
 (0)