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 bc553c37cfd GH-51816: [GLib] Add filesystem GType registration 
mechanism (#55464)
bc553c37cfd is described below

commit bc553c37cfd768122e0fd9823fb04feedebec137
Author: alytantawyy <[email protected]>
AuthorDate: Mon Nov 23 17:37:17 2026 -0800

    GH-51816: [GLib] Add filesystem GType registration mechanism (#55464)
    
    ### Rationale for this change
    
    Provide filesystem wrapper registration so separately packaged bindings can 
supply their own GLib types. This prepares for the S3 GLib bindings split in 
#51608.
    
    Closes #51816.
    
    ### What changes are included in this PR?
    
    - Add `garrow_file_system_register_type()` backed by GIO's 
`arrow-file-system` extension point.
    - Select registered filesystem wrappers through GIO while preserving the 
built-in mappings.
    - Validate names and concrete wrapper types, and reject duplicate names and 
wrapper aliases.
    - Document initialization-only registration, including direct GIO 
registration and registrations triggered by module loading.
    - Add Ruby regression tests for registration and validation.
    
    ### Are these changes tested?
    
    Verified locally on macOS arm64:
    
    - 84 Ruby filesystem tests passed; 12 optional Dataset tests were omitted 
because Arrow Dataset was unavailable.
    - Build, formatting, and all applicable pre-commit checks passed.
    
    These are local results for commit `a75348d944`. GitHub CI results are 
reported separately in the PR checks.
    
    ### Are there any user-facing changes?
    
    Adds a filesystem type-registration API. Each wrapper type has one 
registration name within the extension point. `GArrowFileSystem` remains 
abstract; changes to unknown-filesystem handling are deferred.
    
    Registration must finish sequentially during initialization, before 
concurrent filesystem wrapper lookups begin. This requirement also applies to 
direct GIO registration and registrations triggered by GIO module loading. 
Concurrent registration is not supported.
    
    Moving the S3 bindings into a separate library is outside this PR's scope.
    
    ### Was AI used for this PR?
    
    Codex generated the implementation and tests and helped draft this 
description.
    
    I personally reviewed the full implementation and tests.
    
    * GitHub Issue: #51816
    
    Authored-by: alytantawyy <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 c_glib/arrow-glib/file-system.cpp | 126 ++++++++++++++++++++++++++++++++++----
 c_glib/arrow-glib/file-system.h   |   4 ++
 c_glib/test/test-file-system.rb   |  61 ++++++++++++++++++
 3 files changed, 179 insertions(+), 12 deletions(-)

diff --git a/c_glib/arrow-glib/file-system.cpp 
b/c_glib/arrow-glib/file-system.cpp
index 9ba494e4059..0fa8deb3186 100644
--- a/c_glib/arrow-glib/file-system.cpp
+++ b/c_glib/arrow-glib/file-system.cpp
@@ -17,6 +17,10 @@
  * under the License.
  */
 
+#include <string>
+
+#include <gio/gio.h>
+
 #include <arrow-glib/enums.h>
 
 #include <arrow-glib/error.hpp>
@@ -545,6 +549,37 @@ garrow_file_selector_class_init(GArrowFileSelectorClass 
*klass)
 
 /* arrow::fs::FileSystem */
 
+static const gchar garrow_file_system_extension_point_name[] = 
"arrow-file-system";
+
+static GIOExtensionPoint *
+garrow_file_system_get_extension_point(void)
+{
+  static auto extension_point = [] {
+    auto point = 
g_io_extension_point_register(garrow_file_system_extension_point_name);
+    g_io_extension_point_set_required_type(point, GARROW_TYPE_FILE_SYSTEM);
+    const struct
+    {
+      const gchar *name;
+      GType gtype;
+    } builtins[] = {
+      {"local", GARROW_TYPE_LOCAL_FILE_SYSTEM},
+      {"hdfs", GARROW_TYPE_HDFS_FILE_SYSTEM},
+      {"s3", GARROW_TYPE_S3_FILE_SYSTEM},
+      {"gcs", GARROW_TYPE_GCS_FILE_SYSTEM},
+      {"abfs", GARROW_TYPE_AZURE_FILE_SYSTEM},
+      {"mock", GARROW_TYPE_MOCK_FILE_SYSTEM},
+    };
+    for (const auto &builtin : builtins) {
+      g_io_extension_point_implement(garrow_file_system_extension_point_name,
+                                     builtin.gtype,
+                                     builtin.name,
+                                     0);
+    }
+    return point;
+  }();
+  return extension_point;
+}
+
 typedef struct GArrowFileSystemPrivate_
 {
   std::shared_ptr<arrow::fs::FileSystem> file_system;
@@ -614,6 +649,80 @@ garrow_file_system_class_init(GArrowFileSystemClass *klass)
   g_object_class_install_property(gobject_class, PROP_FILE_SYSTEM, spec);
 }
 
+/**
+ * garrow_file_system_register_type:
+ * @type_name: A non-empty Arrow C++ file system type name.
+ * @gtype: A non-abstract #GArrowFileSystem type.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Registers @gtype as the GLib wrapper type for @type_name. The type name
+ * is copied and the registration lasts for the lifetime of the process.
+ * Built-in file system wrapper types are registered automatically.
+ * Registering a name that is already registered is an error.
+ * Each wrapper type can be registered under only one name.
+ *
+ * Registration must be completed sequentially during initialization,
+ * before concurrent file system wrapper lookups begin. This function is
+ * not thread-safe. The same restriction applies to registration directly
+ * through GIO's `arrow-file-system` extension point, including any
+ * registration triggered by GIO module loading.
+ *
+ * Returns: %TRUE on success, %FALSE on error.
+ *
+ * Since: 27.0.0
+ */
+gboolean
+garrow_file_system_register_type(const gchar *type_name, GType gtype, GError 
**error)
+{
+  const gchar *context = "[file-system][register-type]";
+  if (!type_name || !*type_name) {
+    g_set_error(error,
+                GARROW_ERROR,
+                GARROW_ERROR_INVALID,
+                "%s type name must not be NULL or empty",
+                context);
+    return FALSE;
+  }
+  if (!g_type_is_a(gtype, GARROW_TYPE_FILE_SYSTEM) || 
G_TYPE_IS_ABSTRACT(gtype)) {
+    g_set_error(error,
+                GARROW_ERROR,
+                GARROW_ERROR_INVALID,
+                "%s GType must be a non-abstract GArrowFileSystem type",
+                context);
+    return FALSE;
+  }
+
+  auto extension_point = garrow_file_system_get_extension_point();
+  const auto duplicate =
+    g_io_extension_point_get_extension_by_name(extension_point, type_name) != 
NULL;
+  GIOExtension *extension = NULL;
+  if (!duplicate) {
+    extension = 
g_io_extension_point_implement(garrow_file_system_extension_point_name,
+                                               gtype,
+                                               type_name,
+                                               0);
+  }
+  if (duplicate) {
+    g_set_error(error,
+                GARROW_ERROR,
+                GARROW_ERROR_KEY,
+                "%s file system type is already registered: %s",
+                context,
+                type_name);
+    return FALSE;
+  }
+  if (g_strcmp0(g_io_extension_get_name(extension), type_name) != 0) {
+    g_set_error(error,
+                GARROW_ERROR,
+                GARROW_ERROR_KEY,
+                "%s wrapper type is already registered under another name: %s",
+                context,
+                g_io_extension_get_name(extension));
+    return FALSE;
+  }
+  return TRUE;
+}
+
 /**
  * garrow_file_system_create:
  * @uri: An URI to specify file system with options. If you only have an
@@ -1598,18 +1707,11 @@ 
garrow_file_system_new_raw(std::shared_ptr<arrow::fs::FileSystem> *arrow_file_sy
   const auto &type_name = (*arrow_file_system)->type_name();
 
   GType file_system_type = GARROW_TYPE_FILE_SYSTEM;
-  if (type_name == "local") {
-    file_system_type = GARROW_TYPE_LOCAL_FILE_SYSTEM;
-  } else if (type_name == "hdfs") {
-    file_system_type = GARROW_TYPE_HDFS_FILE_SYSTEM;
-  } else if (type_name == "s3") {
-    file_system_type = GARROW_TYPE_S3_FILE_SYSTEM;
-  } else if (type_name == "gcs") {
-    file_system_type = GARROW_TYPE_GCS_FILE_SYSTEM;
-  } else if (type_name == "abfs") {
-    file_system_type = GARROW_TYPE_AZURE_FILE_SYSTEM;
-  } else if (type_name == "mock") {
-    file_system_type = GARROW_TYPE_MOCK_FILE_SYSTEM;
+  auto extension_point = garrow_file_system_get_extension_point();
+  auto extension =
+    g_io_extension_point_get_extension_by_name(extension_point, 
type_name.c_str());
+  if (extension) {
+    file_system_type = g_io_extension_get_type(extension);
   }
 
   return GARROW_FILE_SYSTEM(
diff --git a/c_glib/arrow-glib/file-system.h b/c_glib/arrow-glib/file-system.h
index 9a903c6af68..666271956df 100644
--- a/c_glib/arrow-glib/file-system.h
+++ b/c_glib/arrow-glib/file-system.h
@@ -100,6 +100,10 @@ struct _GArrowFileSystemClass
   GObjectClass parent_class;
 };
 
+GARROW_AVAILABLE_IN_27_0
+gboolean
+garrow_file_system_register_type(const gchar *type_name, GType gtype, GError 
**error);
+
 GARROW_AVAILABLE_IN_3_0
 GArrowFileSystem *
 garrow_file_system_create(const gchar *uri, GError **error);
diff --git a/c_glib/test/test-file-system.rb b/c_glib/test/test-file-system.rb
new file mode 100644
index 00000000000..281f3d0804f
--- /dev/null
+++ b/c_glib/test/test-file-system.rb
@@ -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 TestFileSystem < Test::Unit::TestCase
+  class RegisteredFileSystem < Arrow::FileSystem
+    type_register
+  end
+
+  class DuplicateFileSystem < Arrow::FileSystem
+    type_register
+  end
+
+  sub_test_case(".register_type") do
+    def test_valid
+      assert_true(Arrow::FileSystem.register_type("test-file-system-valid",
+                                                  RegisteredFileSystem.gtype))
+    end
+
+    def test_duplicate
+      type_name = "test-file-system-duplicate"
+      Arrow::FileSystem.register_type(type_name, DuplicateFileSystem.gtype)
+      assert_raise(Arrow::Error::Key) do
+        Arrow::FileSystem.register_type(type_name, 
Arrow::LocalFileSystem.gtype)
+      end
+    end
+
+    def test_type_alias
+      assert_raise(Arrow::Error::Key) do
+        Arrow::FileSystem.register_type("test-file-system-alias",
+                                        Arrow::MockFileSystem.gtype)
+      end
+    end
+
+    def test_empty_name
+      assert_raise(Arrow::Error::Invalid) do
+        Arrow::FileSystem.register_type("", Arrow::MockFileSystem.gtype)
+      end
+    end
+
+    def test_unrelated_type
+      assert_raise(Arrow::Error::Invalid) do
+        Arrow::FileSystem.register_type("test-file-system-unrelated",
+                                        Arrow::Int32Array.gtype)
+      end
+    end
+  end
+end

Reply via email to