-
Notifications
You must be signed in to change notification settings - Fork 119
feat(io): add ResolvingFileIO to resolve FileIO by location scheme and forward vended credentials #828
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
Open
plusplusjiajia
wants to merge
8
commits into
apache:main
Choose a base branch
from
plusplusjiajia:feat-resolving-fileio
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(io): add ResolvingFileIO to resolve FileIO by location scheme and forward vended credentials #828
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bf4dcfa
feat(io): add ResolvingFileIO to resolve FileIO by location scheme an…
plusplusjiajia 03f6964
fix(io): own ResolvingFileIO cache keys and warn when no vended crede…
plusplusjiajia 025a5a2
fix(io): apply oss:// vended credentials and keep resolver delegates …
plusplusjiajia ea519fc
test(rest): round-trip real bytes through the registered local Arrow …
plusplusjiajia e8881f1
refactor(io): emit the credential warning through ICEBERG_LOG_WARN
plusplusjiajia d5c4c15
style(test): satisfy cmake-format in add_rest_iceberg_test
plusplusjiajia b322574
test(rest): assert scheme routing and widen the full-stack test's bui…
plusplusjiajia 1fa7619
test(io): cover every accepted credential prefix and scope the S3-onl…
plusplusjiajia 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,124 @@ | ||
| /* | ||
| * 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 "iceberg/resolving_file_io.h" | ||
|
|
||
| #include <utility> | ||
|
|
||
| #include "iceberg/file_io_registry.h" | ||
| #include "iceberg/resolving_file_io_internal.h" | ||
| #include "iceberg/util/macros.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| ResolvingFileIO::ResolvingFileIO(std::unordered_map<std::string, std::string> properties) | ||
| : properties_(std::move(properties)) {} | ||
|
|
||
| ResolvingFileIO::~ResolvingFileIO() = default; | ||
|
|
||
| Result<std::string_view> ResolveFileIOName(std::string_view location) { | ||
| const auto pos = location.find("://"); | ||
| if (pos == std::string_view::npos) { | ||
| return FileIORegistry::kArrowLocalFileIO; | ||
| } | ||
|
|
||
| const auto scheme = location.substr(0, pos); | ||
| if (scheme == "file") { | ||
| return FileIORegistry::kArrowLocalFileIO; | ||
| } | ||
| // S3-compatible schemes served by the S3 FileIO (Java: SCHEME_TO_FILE_IO). | ||
| // Keep in sync with CanonicalizeS3Scheme in arrow_s3_file_io.cc. | ||
| if (scheme == "s3" || scheme == "s3a" || scheme == "s3n" || scheme == "oss") { | ||
| return FileIORegistry::kArrowS3FileIO; | ||
| } | ||
|
|
||
| return NotSupported("URI scheme '{}' is not supported for FileIO resolution", scheme); | ||
| } | ||
|
|
||
| Result<FileIO*> ResolvingFileIO::FileIOForPath(std::string_view location) { | ||
| ICEBERG_ASSIGN_OR_RAISE(const auto name, ResolveFileIOName(location)); | ||
|
|
||
| std::lock_guard lock(mutex_); | ||
| auto it = io_by_name_.find(name); | ||
| if (it == io_by_name_.end()) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto io, | ||
| FileIORegistry::Load(std::string(name), properties_)); | ||
| // Forward all credentials; each implementation applies the prefixes it | ||
| // understands. | ||
| if (!storage_credentials_.empty()) { | ||
| if (auto* credentialed = io->AsSupportsStorageCredentials()) { | ||
| ICEBERG_RETURN_UNEXPECTED( | ||
| credentialed->SetStorageCredentials(storage_credentials_)); | ||
| } | ||
| } | ||
| it = io_by_name_.emplace(std::string(name), std::move(io)).first; | ||
| } | ||
| return it->second.get(); | ||
| } | ||
|
|
||
| Result<std::unique_ptr<InputFile>> ResolvingFileIO::NewInputFile( | ||
| std::string file_location) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto* io, FileIOForPath(file_location)); | ||
| return io->NewInputFile(std::move(file_location)); | ||
| } | ||
|
|
||
| Result<std::unique_ptr<InputFile>> ResolvingFileIO::NewInputFile( | ||
| std::string file_location, size_t length) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto* io, FileIOForPath(file_location)); | ||
| return io->NewInputFile(std::move(file_location), length); | ||
| } | ||
|
|
||
| Result<std::unique_ptr<OutputFile>> ResolvingFileIO::NewOutputFile( | ||
| std::string file_location) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto* io, FileIOForPath(file_location)); | ||
| return io->NewOutputFile(std::move(file_location)); | ||
| } | ||
|
|
||
| Status ResolvingFileIO::DeleteFile(const std::string& file_location) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto* io, FileIOForPath(file_location)); | ||
| return io->DeleteFile(file_location); | ||
| } | ||
|
|
||
| Status ResolvingFileIO::DeleteFiles(const std::vector<std::string>& file_locations) { | ||
| std::unordered_map<FileIO*, std::vector<std::string>> locations_by_io; | ||
| for (const auto& file_location : file_locations) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto* io, FileIOForPath(file_location)); | ||
| locations_by_io[io].push_back(file_location); | ||
| } | ||
| for (auto& [io, locations] : locations_by_io) { | ||
| ICEBERG_RETURN_UNEXPECTED(io->DeleteFiles(locations)); | ||
| } | ||
| return {}; | ||
| } | ||
|
|
||
| Status ResolvingFileIO::SetStorageCredentials( | ||
| const std::vector<StorageCredential>& storage_credentials) { | ||
| // Rebuild delegates lazily with the new credentials. Updating live delegates | ||
| // instead would leave the resolver inconsistent if one of them rejected them. | ||
| std::lock_guard lock(mutex_); | ||
| storage_credentials_ = storage_credentials; | ||
|
wgtmac marked this conversation as resolved.
|
||
| io_by_name_.clear(); | ||
| return {}; | ||
| } | ||
|
|
||
| const std::vector<StorageCredential>& ResolvingFileIO::credentials() const { | ||
| return storage_credentials_; | ||
| } | ||
|
|
||
| } // namespace iceberg | ||
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.
Uh oh!
There was an error while loading. Please reload this page.