Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cpp/src/arrow/filesystem/azurefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3199,4 +3199,31 @@ Result<std::shared_ptr<io::OutputStream>> AzureFileSystem::OpenAppendStream(
return impl_->OpenAppendStream(location, metadata, false, this);
}

Result<std::string> AzureFileSystem::PathFromUri(const std::string& uri_string) const {
/// We can not use `internal::PathFromUriHelper` here because for Azure we have to
/// support different URI schemes where the authority is handled differently.
/// Example (both should yield the same path `container/some/path`):
/// - (1) abfss://storageacc.blob.core.windows.net/container/some/path
/// - (2) abfss://acc:pw@container/some/path
/// The authority handling is different with these two URIs. (1) requires no prepending
/// of the authority to the path, while (2) requires to preprend the authority to the
/// path.
std::string path;
Uri uri;
RETURN_NOT_OK(uri.Parse(uri_string));
RETURN_NOT_OK(AzureOptions::FromUri(uri, &path));

std::vector<std::string> supported_schemes = {"abfs", "abfss"};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It would be nice to have a comment explaining why internal::PathFromUriHelper() can't be used in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I added a comment. 👍

const auto scheme = uri.scheme();
if (std::find(supported_schemes.begin(), supported_schemes.end(), scheme) ==
supported_schemes.end()) {
std::string expected_schemes =
::arrow::internal::JoinStrings(supported_schemes, ", ");
return Status::Invalid("The filesystem expected a URI with one of the schemes (",
expected_schemes, ") but received ", uri_string);
}

return path;
}

} // namespace arrow::fs
2 changes: 2 additions & 0 deletions cpp/src/arrow/filesystem/azurefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ class ARROW_EXPORT AzureFileSystem : public FileSystem {
Result<std::shared_ptr<io::OutputStream>> OpenAppendStream(
const std::string& path,
const std::shared_ptr<const KeyValueMetadata>& metadata) override;

Result<std::string> PathFromUri(const std::string& uri_string) const override;
};

} // namespace arrow::fs
9 changes: 9 additions & 0 deletions cpp/src/arrow/filesystem/azurefs_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2958,5 +2958,14 @@ TEST_F(TestAzuriteFileSystem, OpenInputFileClosed) {
ASSERT_RAISES(Invalid, stream->ReadAt(1, 1));
ASSERT_RAISES(Invalid, stream->Seek(2));
}

TEST_F(TestAzuriteFileSystem, PathFromUri) {
ASSERT_EQ(
"container/some/path",
fs()->PathFromUri("abfss://storageacc.blob.core.windows.net/container/some/path"));
ASSERT_EQ("container/some/path",
fs()->PathFromUri("abfss://acc:pw@container/some/path"));
ASSERT_RAISES(Invalid, fs()->PathFromUri("http://acc:pw@container/some/path"));
}
} // namespace fs
} // namespace arrow