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 437d361d4e GH-44686: [GLib] Add GArrowStringViewDataType (#44687)
437d361d4e is described below

commit 437d361d4eb3b36c30498e8eb6a9829c55d8bc56
Author: Hiroyuki Sato <[email protected]>
AuthorDate: Sat Nov 9 15:43:17 2024 +0900

    GH-44686: [GLib] Add GArrowStringViewDataType (#44687)
    
    
    
    ### Rationale for this change
    
    The `arrow::StringViewType` has been introduced.
    GLib needs to be implemented as the `GArrowStringViewDataType`.
    
    ### What changes are included in this PR?
    
    Introduce `GArrowStringViewDataType`
    
    ### Are these changes tested?
    
    Yes.
    
    ### Are there any user-facing changes?
    
    Yes.
    
    * GitHub Issue: #44686
    
    Authored-by: Hiroyuki Sato <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 c_glib/arrow-glib/basic-data-type.cpp     | 30 ++++++++++++++++++++++++++++
 c_glib/arrow-glib/basic-data-type.h       | 16 +++++++++++++++
 c_glib/arrow-glib/type.cpp                |  2 ++
 c_glib/arrow-glib/type.h                  |  6 ++++--
 c_glib/test/test-string-view-data-type.rb | 33 +++++++++++++++++++++++++++++++
 5 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/c_glib/arrow-glib/basic-data-type.cpp 
b/c_glib/arrow-glib/basic-data-type.cpp
index f922106065..f5130e9344 100644
--- a/c_glib/arrow-glib/basic-data-type.cpp
+++ b/c_glib/arrow-glib/basic-data-type.cpp
@@ -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.
  */
 
@@ -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 *
diff --git a/c_glib/arrow-glib/basic-data-type.h 
b/c_glib/arrow-glib/basic-data-type.h
index b98488211a..b692395e48 100644
--- a/c_glib/arrow-glib/basic-data-type.h
+++ b/c_glib/arrow-glib/basic-data-type.h
@@ -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
diff --git a/c_glib/arrow-glib/type.cpp b/c_glib/arrow-glib/type.cpp
index 42372bc8dd..cc1d35127e 100644
--- a/c_glib/arrow-glib/type.cpp
+++ b/c_glib/arrow-glib/type.cpp
@@ -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:
diff --git a/c_glib/arrow-glib/type.h b/c_glib/arrow-glib/type.h
index f85cf3f2ee..8a6f62d02d 100644
--- a/c_glib/arrow-glib/type.h
+++ b/c_glib/arrow-glib/type.h
@@ -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
@@ -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,
diff --git a/c_glib/test/test-string-view-data-type.rb 
b/c_glib/test/test-string-view-data-type.rb
new file mode 100644
index 0000000000..f1f3655493
--- /dev/null
+++ b/c_glib/test/test-string-view-data-type.rb
@@ -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

Reply via email to