From 8b03120ff0855b00a77b703d73ce65eeedc83367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Wed, 28 Oct 2026 10:47:01 +0100 Subject: [PATCH] GH-55258: [C++] Move Azure to Filesystem Registry --- cpp/src/arrow/filesystem/azurefs.cc | 11 +++++++++++ cpp/src/arrow/filesystem/azurefs_test.cc | 18 ++++++++++++++++++ cpp/src/arrow/filesystem/filesystem.cc | 13 ------------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/cpp/src/arrow/filesystem/azurefs.cc b/cpp/src/arrow/filesystem/azurefs.cc index 20b0a655d8e2..7e97d74b4ccb 100644 --- a/cpp/src/arrow/filesystem/azurefs.cc +++ b/cpp/src/arrow/filesystem/azurefs.cc @@ -3561,4 +3561,15 @@ Result AzureFileSystem::PathFromUri(const std::string& uri_string) return path; } +static Result> AzureFileSystemFactory( + const Uri& uri, const io::IOContext& io_context, std::string* out_path) { + ARROW_ASSIGN_OR_RAISE(auto options, AzureOptions::FromUri(uri, out_path)); + return AzureFileSystem::Make(options, io_context); +} + +FileSystemRegistrar kAzureFileSystemRegistrar[]{ + ARROW_REGISTER_FILESYSTEM("abfs", AzureFileSystemFactory, {}), + ARROW_REGISTER_FILESYSTEM("abfss", AzureFileSystemFactory, {}), +}; + } // namespace arrow::fs diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index 250e3572bd9b..f5adbb8e1f2d 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -509,6 +509,24 @@ TEST(AzureFileSystem, InitializingFilesystemWithoutAccountNameFails) { ASSERT_RAISES(Invalid, AzureFileSystem::Make(options)); } +TEST(AzureFileSystem, FileSystemFromUriRegistry) { + std::string path; + for (const auto& scheme : {"abfs", "abfss"}) { + ASSERT_OK_AND_ASSIGN( + auto fs, FileSystemFromUri(std::string(scheme) + + "://account.blob.core.windows.net/container/dir/" + "blob?credential_kind=anonymous", + &path)); + EXPECT_EQ(fs->type_name(), "abfs"); + EXPECT_EQ(path, "container/dir/blob"); + } + EXPECT_RAISES_WITH_MESSAGE_THAT( + NotImplemented, ::testing::HasSubstr("Filesystem factory does not support"), + FileSystemFromUriAndOptions( + "abfs://account.blob.core.windows.net/container?credential_kind=anonymous", + {{"foo", std::string{"bar"}}})); +} + TEST(AzureFileSystem, InitializeWithDefaultCredential) { AzureOptions options; options.account_name = "dummy-account-name"; diff --git a/cpp/src/arrow/filesystem/filesystem.cc b/cpp/src/arrow/filesystem/filesystem.cc index c15bc06681d6..6b49f05eb0b1 100644 --- a/cpp/src/arrow/filesystem/filesystem.cc +++ b/cpp/src/arrow/filesystem/filesystem.cc @@ -25,9 +25,6 @@ #include "arrow/util/config.h" #include "arrow/filesystem/filesystem.h" -#ifdef ARROW_AZURE -# include "arrow/filesystem/azurefs.h" -#endif #ifdef ARROW_HDFS # include "arrow/filesystem/hdfs.h" #endif @@ -909,16 +906,6 @@ Result> FileSystemFromUriReal( scheme, "', got ", options.size(), " option(s)"); } - if (scheme == "abfs" || scheme == "abfss") { -#ifdef ARROW_AZURE - ARROW_ASSIGN_OR_RAISE(auto options, AzureOptions::FromUri(uri, out_path)); - return AzureFileSystem::Make(options, io_context); -#else - return Status::NotImplemented( - "Got Azure Blob File System URI but Arrow compiled without Azure Blob File " - "System support"); -#endif - } if (scheme == "hdfs" || scheme == "viewfs") { #ifdef ARROW_HDFS ARROW_ASSIGN_OR_RAISE(auto options, HdfsOptions::FromUri(uri));