diff --git a/cpp/src/arrow/filesystem/azurefs.cc b/cpp/src/arrow/filesystem/azurefs.cc index 20b0a655d8e..7e97d74b4cc 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 250e3572bd9..f5adbb8e1f2 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 c15bc06681d..6b49f05eb0b 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));