Skip to content

Commit 8b03120

Browse files
committed
GH-55258: [C++] Move Azure to Filesystem Registry
1 parent fc390cd commit 8b03120

3 files changed

Lines changed: 29 additions & 13 deletions

File tree

‎cpp/src/arrow/filesystem/azurefs.cc‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,4 +3561,15 @@ Result<std::string> AzureFileSystem::PathFromUri(const std::string& uri_string)
35613561
return path;
35623562
}
35633563

3564+
static Result<std::shared_ptr<FileSystem>> AzureFileSystemFactory(
3565+
const Uri& uri, const io::IOContext& io_context, std::string* out_path) {
3566+
ARROW_ASSIGN_OR_RAISE(auto options, AzureOptions::FromUri(uri, out_path));
3567+
return AzureFileSystem::Make(options, io_context);
3568+
}
3569+
3570+
FileSystemRegistrar kAzureFileSystemRegistrar[]{
3571+
ARROW_REGISTER_FILESYSTEM("abfs", AzureFileSystemFactory, {}),
3572+
ARROW_REGISTER_FILESYSTEM("abfss", AzureFileSystemFactory, {}),
3573+
};
3574+
35643575
} // namespace arrow::fs

‎cpp/src/arrow/filesystem/azurefs_test.cc‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,24 @@ TEST(AzureFileSystem, InitializingFilesystemWithoutAccountNameFails) {
509509
ASSERT_RAISES(Invalid, AzureFileSystem::Make(options));
510510
}
511511

512+
TEST(AzureFileSystem, FileSystemFromUriRegistry) {
513+
std::string path;
514+
for (const auto& scheme : {"abfs", "abfss"}) {
515+
ASSERT_OK_AND_ASSIGN(
516+
auto fs, FileSystemFromUri(std::string(scheme) +
517+
"://account.blob.core.windows.net/container/dir/"
518+
"blob?credential_kind=anonymous",
519+
&path));
520+
EXPECT_EQ(fs->type_name(), "abfs");
521+
EXPECT_EQ(path, "container/dir/blob");
522+
}
523+
EXPECT_RAISES_WITH_MESSAGE_THAT(
524+
NotImplemented, ::testing::HasSubstr("Filesystem factory does not support"),
525+
FileSystemFromUriAndOptions(
526+
"abfs://account.blob.core.windows.net/container?credential_kind=anonymous",
527+
{{"foo", std::string{"bar"}}}));
528+
}
529+
512530
TEST(AzureFileSystem, InitializeWithDefaultCredential) {
513531
AzureOptions options;
514532
options.account_name = "dummy-account-name";

‎cpp/src/arrow/filesystem/filesystem.cc‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
#include "arrow/util/config.h"
2626

2727
#include "arrow/filesystem/filesystem.h"
28-
#ifdef ARROW_AZURE
29-
# include "arrow/filesystem/azurefs.h"
30-
#endif
3128
#ifdef ARROW_HDFS
3229
# include "arrow/filesystem/hdfs.h"
3330
#endif
@@ -909,16 +906,6 @@ Result<std::shared_ptr<FileSystem>> FileSystemFromUriReal(
909906
scheme, "', got ", options.size(), " option(s)");
910907
}
911908

912-
if (scheme == "abfs" || scheme == "abfss") {
913-
#ifdef ARROW_AZURE
914-
ARROW_ASSIGN_OR_RAISE(auto options, AzureOptions::FromUri(uri, out_path));
915-
return AzureFileSystem::Make(options, io_context);
916-
#else
917-
return Status::NotImplemented(
918-
"Got Azure Blob File System URI but Arrow compiled without Azure Blob File "
919-
"System support");
920-
#endif
921-
}
922909
if (scheme == "hdfs" || scheme == "viewfs") {
923910
#ifdef ARROW_HDFS
924911
ARROW_ASSIGN_OR_RAISE(auto options, HdfsOptions::FromUri(uri));

0 commit comments

Comments
 (0)