Skip to content

Commit

Permalink
GH-44686: [GLib] Add GArrowStringViewDataType
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroyuki-sato committed Nov 9, 2024
1 parent ac6b8ff commit 2d6db0a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
30 changes: 30 additions & 0 deletions c_glib/arrow-glib/basic-data-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ G_BEGIN_DECLS
* #GArrowExtensionDataTypeRegistry is a class to manage extension
* data types.
*
* #GArrowStringViewDataType is a class for the string view data type.
*
* #GArrowBinaryViewDataType is a class for the binary view data type.
*/

Expand Down Expand Up @@ -2237,6 +2239,34 @@ garrow_binary_view_data_type_new(void)
return data_type;
}

G_DEFINE_TYPE(GArrowStringViewDataType,
garrow_string_view_data_type,
GARROW_TYPE_BINARY_VIEW_DATA_TYPE)

static void
garrow_string_view_data_type_init(GArrowStringViewDataType *object)
{
}

static void
garrow_string_view_data_type_class_init(GArrowStringViewDataTypeClass *klass)
{
}

/**
* garrow_string_view_data_type_new:
*
* Returns: The newly created string view data type.
*/
GArrowStringViewDataType *
garrow_string_view_data_type_new(void)
{
auto arrow_data_type = arrow::utf8_view();
GArrowStringViewDataType *data_type = GARROW_STRING_VIEW_DATA_TYPE(
g_object_new(GARROW_TYPE_STRING_VIEW_DATA_TYPE, "data-type", &arrow_data_type, NULL));
return data_type;
}

G_END_DECLS

GArrowDataType *
Expand Down
16 changes: 16 additions & 0 deletions c_glib/arrow-glib/basic-data-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -786,4 +786,20 @@ GARROW_AVAILABLE_IN_19_0
GArrowBinaryViewDataType *
garrow_binary_view_data_type_new(void);

#define GARROW_TYPE_STRING_VIEW_DATA_TYPE (garrow_string_view_data_type_get_type())
GARROW_AVAILABLE_IN_19_0
G_DECLARE_DERIVABLE_TYPE(GArrowStringViewDataType,
garrow_string_view_data_type,
GARROW,
STRING_VIEW_DATA_TYPE,
GArrowBinaryViewDataType)
struct _GArrowStringViewDataTypeClass
{
GArrowBinaryViewDataTypeClass parent_class;
};

GARROW_AVAILABLE_IN_19_0
GArrowStringViewDataType *
garrow_string_view_data_type_new(void);

G_END_DECLS
2 changes: 2 additions & 0 deletions c_glib/arrow-glib/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ garrow_type_from_raw(arrow::Type::type type)
return GARROW_TYPE_MONTH_DAY_NANO_INTERVAL;
case arrow::Type::type::RUN_END_ENCODED:
return GARROW_TYPE_RUN_END_ENCODED;
case arrow::Type::type::STRING_VIEW:
return GARROW_TYPE_STRING_VIEW;
case arrow::Type::type::BINARY_VIEW:
return GARROW_TYPE_BINARY_VIEW;
default:
Expand Down
6 changes: 4 additions & 2 deletions c_glib/arrow-glib/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ G_BEGIN_DECLS
* @GARROW_TYPE_LARGE_LIST: A list of some logical data type with 64-bit offsets.
* @GARROW_TYPE_MONTH_DAY_NANO_INTERVAL: MONTH_DAY_NANO interval in SQL style.
* @GARROW_TYPE_RUN_END_ENCODED: Run-end encoded data.
* @GARROW_TYPE_STRING_VIEW: String (UTF8) view type with 4-byte prefix and inline small
* string optimization.
* @GARROW_TYPE_BINARY_VIEW: Bytes view type with 4-byte prefix and inline small string
* optimization.
* @GARROW_TYPE_DECIMAL32: Precision- and scale-based decimal
Expand Down Expand Up @@ -118,8 +120,8 @@ typedef enum {
GARROW_TYPE_LARGE_LIST,
GARROW_TYPE_MONTH_DAY_NANO_INTERVAL,
GARROW_TYPE_RUN_END_ENCODED,
/* TODO: Remove = 40 when we add STRING_VIEW(39) */
GARROW_TYPE_BINARY_VIEW = 40,
GARROW_TYPE_STRING_VIEW,
GARROW_TYPE_BINARY_VIEW,
/* TODO: Remove = 43 when we add LIST_VIEW(41)..LARGE_LIST_VIEW(42). */
GARROW_TYPE_DECIMAL32 = 43,
GARROW_TYPE_DECIMAL64,
Expand Down
33 changes: 33 additions & 0 deletions c_glib/test/test-string-view-data-type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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 TestStringViewDataType < Test::Unit::TestCase
def test_type
data_type = Arrow::StringViewDataType.new
assert_equal(Arrow::Type::STRING_VIEW, data_type.id)
end

def test_name
data_type = Arrow::StringViewDataType.new
assert_equal("utf8_view", data_type.name)
end

def test_to_s
data_type = Arrow::StringViewDataType.new
assert_equal("string_view", data_type.to_s)
end
end

0 comments on commit 2d6db0a

Please sign in to comment.