-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-35903: [C++] Skeleton for Azure Blob Storage filesystem implementation #35701
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
95032c0
Initial Skeleton Commit
srilman e8a6641
Updates to Match GcsFileSystem
srilman 93511ec
Some Initial Reccommendations
srilman 586a1fe
Comments
srilman 40caec3
Addressing Comments
srilman 9a5298c
Add Azure Backend Enum
srilman aa04585
Some Last Cleanup
srilman 45d9c8f
Fix Format Mistake
srilman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// 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. | ||
|
||
#include "arrow/filesystem/azurefs.h" | ||
|
||
#include "arrow/result.h" | ||
#include "arrow/util/checked_cast.h" | ||
|
||
namespace arrow { | ||
namespace fs { | ||
|
||
// ----------------------------------------------------------------------- | ||
// AzureOptions Implementation | ||
|
||
AzureOptions::AzureOptions() {} | ||
|
||
bool AzureOptions::Equals(const AzureOptions& other) const { | ||
return (account_dfs_url == other.account_dfs_url && | ||
account_blob_url == other.account_blob_url && | ||
credentials_kind == other.credentials_kind); | ||
} | ||
|
||
// ----------------------------------------------------------------------- | ||
// AzureFilesystem Implementation | ||
|
||
class AzureFileSystem::Impl { | ||
public: | ||
io::IOContext io_context_; | ||
bool is_hierarchical_namespace_enabled_; | ||
AzureOptions options_; | ||
|
||
explicit Impl(AzureOptions options, io::IOContext io_context) | ||
: io_context_(io_context), options_(std::move(options)) {} | ||
|
||
Status Init() { | ||
if (options_.backend == AzureBackend::Azurite) { | ||
// gen1Client_->GetAccountInfo().Value.IsHierarchicalNamespaceEnabled | ||
// throws error in azurite | ||
is_hierarchical_namespace_enabled_ = false; | ||
} | ||
return Status::OK(); | ||
} | ||
|
||
const AzureOptions& options() const { return options_; } | ||
}; | ||
|
||
const AzureOptions& AzureFileSystem::options() const { return impl_->options(); } | ||
|
||
bool AzureFileSystem::Equals(const FileSystem& other) const { | ||
if (this == &other) { | ||
return true; | ||
} | ||
if (other.type_name() != type_name()) { | ||
return false; | ||
} | ||
const auto& azure_fs = ::arrow::internal::checked_cast<const AzureFileSystem&>(other); | ||
return options().Equals(azure_fs.options()); | ||
} | ||
|
||
Result<FileInfo> AzureFileSystem::GetFileInfo(const std::string& path) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Result<FileInfoVector> AzureFileSystem::GetFileInfo(const FileSelector& select) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Status AzureFileSystem::CreateDir(const std::string& path, bool recursive) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Status AzureFileSystem::DeleteDir(const std::string& path) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Status AzureFileSystem::DeleteDirContents(const std::string& path, bool missing_dir_ok) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Status AzureFileSystem::DeleteRootDirContents() { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Status AzureFileSystem::DeleteFile(const std::string& path) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Status AzureFileSystem::Move(const std::string& src, const std::string& dest) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Status AzureFileSystem::CopyFile(const std::string& src, const std::string& dest) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Result<std::shared_ptr<io::InputStream>> AzureFileSystem::OpenInputStream( | ||
const std::string& path) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Result<std::shared_ptr<io::InputStream>> AzureFileSystem::OpenInputStream( | ||
const FileInfo& info) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Result<std::shared_ptr<io::RandomAccessFile>> AzureFileSystem::OpenInputFile( | ||
const std::string& path) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Result<std::shared_ptr<io::RandomAccessFile>> AzureFileSystem::OpenInputFile( | ||
const FileInfo& info) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Result<std::shared_ptr<io::OutputStream>> AzureFileSystem::OpenOutputStream( | ||
const std::string& path, const std::shared_ptr<const KeyValueMetadata>& metadata) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Result<std::shared_ptr<io::OutputStream>> AzureFileSystem::OpenAppendStream( | ||
const std::string&, const std::shared_ptr<const KeyValueMetadata>&) { | ||
return Status::NotImplemented("The Azure FileSystem is not fully implemented"); | ||
} | ||
|
||
Result<std::shared_ptr<AzureFileSystem>> AzureFileSystem::Make( | ||
const AzureOptions& options, const io::IOContext& io_context) { | ||
std::shared_ptr<AzureFileSystem> ptr(new AzureFileSystem(options, io_context)); | ||
RETURN_NOT_OK(ptr->impl_->Init()); | ||
return ptr; | ||
} | ||
|
||
AzureFileSystem::AzureFileSystem(const AzureOptions& options, | ||
const io::IOContext& io_context) | ||
: FileSystem(io_context), impl_(std::make_unique<Impl>(options, io_context)) { | ||
default_async_is_sync_ = false; | ||
} | ||
|
||
} // namespace fs | ||
} // namespace arrow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
// 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. | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "arrow/filesystem/filesystem.h" | ||
#include "arrow/util/macros.h" | ||
#include "arrow/util/uri.h" | ||
|
||
namespace Azure { | ||
namespace Core { | ||
namespace Credentials { | ||
|
||
class TokenCredential; | ||
|
||
} // namespace Credentials | ||
} // namespace Core | ||
namespace Storage { | ||
|
||
class StorageSharedKeyCredential; | ||
|
||
} // namespace Storage | ||
} // namespace Azure | ||
|
||
namespace arrow { | ||
namespace fs { | ||
|
||
enum class AzureCredentialsKind : int8_t { | ||
/// Anonymous access (no credentials used), public | ||
Anonymous, | ||
/// Use explicitly-provided access key pair | ||
StorageCredentials, | ||
/// Use ServicePrincipleCredentials | ||
ServicePrincipleCredentials, | ||
/// Use Sas Token to authenticate | ||
Sas, | ||
/// Use Connection String | ||
ConnectionString | ||
}; | ||
|
||
enum class AzureBackend : bool { | ||
/// Official Azure Remote Backend | ||
Azure, | ||
/// Local Simulated Storage | ||
Azurite | ||
}; | ||
|
||
/// Options for the AzureFileSystem implementation. | ||
struct ARROW_EXPORT AzureOptions { | ||
std::string account_dfs_url; | ||
std::string account_blob_url; | ||
AzureBackend backend = AzureBackend::Azure; | ||
AzureCredentialsKind credentials_kind = AzureCredentialsKind::Anonymous; | ||
|
||
std::string sas_token; | ||
std::string connection_string; | ||
std::shared_ptr<Azure::Storage::StorageSharedKeyCredential> | ||
storage_credentials_provider; | ||
std::shared_ptr<Azure::Core::Credentials::TokenCredential> | ||
service_principle_credentials_provider; | ||
|
||
AzureOptions(); | ||
|
||
bool Equals(const AzureOptions& other) const; | ||
}; | ||
|
||
/// \brief Azure-backed FileSystem implementation for ABFS and ADLS. | ||
/// | ||
/// ABFS (Azure Blob Storage - https://azure.microsoft.com/en-us/products/storage/blobs/) | ||
/// object-based cloud storage system. | ||
/// | ||
/// ADLS (Azure Data Lake Storage - | ||
/// https://azure.microsoft.com/en-us/products/storage/data-lake-storage/) | ||
/// is a scalable data storage system designed for big-data applications. | ||
/// ADLS provides filesystem semantics, file-level security, and Hadoop | ||
/// compatibility. Gen1 exists as a separate object that will retired | ||
/// on Feb 29, 2024. New ADLS accounts will use Gen2 instead, which is | ||
/// implemented on top of ABFS. | ||
/// | ||
/// TODO: GH-18014 Complete the internal implementation | ||
/// and review the documentation | ||
class ARROW_EXPORT AzureFileSystem : public FileSystem { | ||
public: | ||
~AzureFileSystem() override = default; | ||
|
||
std::string type_name() const override { return "abfs"; } | ||
|
||
/// Return the original Azure options when constructing the filesystem | ||
const AzureOptions& options() const; | ||
|
||
bool Equals(const FileSystem& other) const override; | ||
|
||
Result<FileInfo> GetFileInfo(const std::string& path) override; | ||
|
||
Result<FileInfoVector> GetFileInfo(const FileSelector& select) override; | ||
|
||
Status CreateDir(const std::string& path, bool recursive = true) override; | ||
|
||
Status DeleteDir(const std::string& path) override; | ||
|
||
Status DeleteDirContents(const std::string& path, bool missing_dir_ok = false) override; | ||
|
||
Status DeleteRootDirContents() override; | ||
|
||
Status DeleteFile(const std::string& path) override; | ||
|
||
Status Move(const std::string& src, const std::string& dest) override; | ||
|
||
Status CopyFile(const std::string& src, const std::string& dest) override; | ||
|
||
Result<std::shared_ptr<io::InputStream>> OpenInputStream( | ||
const std::string& path) override; | ||
|
||
Result<std::shared_ptr<io::InputStream>> OpenInputStream(const FileInfo& info) override; | ||
|
||
Result<std::shared_ptr<io::RandomAccessFile>> OpenInputFile( | ||
const std::string& path) override; | ||
|
||
Result<std::shared_ptr<io::RandomAccessFile>> OpenInputFile( | ||
const FileInfo& info) override; | ||
|
||
Result<std::shared_ptr<io::OutputStream>> OpenOutputStream( | ||
const std::string& path, | ||
const std::shared_ptr<const KeyValueMetadata>& metadata = {}) override; | ||
|
||
Result<std::shared_ptr<io::OutputStream>> OpenAppendStream( | ||
const std::string& path, | ||
const std::shared_ptr<const KeyValueMetadata>& metadata = {}) override; | ||
|
||
static Result<std::shared_ptr<AzureFileSystem>> Make( | ||
const AzureOptions& options, const io::IOContext& = io::default_io_context()); | ||
|
||
private: | ||
explicit AzureFileSystem(const AzureOptions& options, const io::IOContext& io_context); | ||
|
||
class Impl; | ||
std::unique_ptr<Impl> impl_; | ||
}; | ||
|
||
} // namespace fs | ||
} // namespace arrow |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the filesystem implementation can provide access to both storage types? If so, then nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, it should. I did an initial test a while ago on the original PR and was able to.