-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-38309: [C++] build filesystems as separate modules #39067
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| // 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/filesystem.h> | ||
| #include <arrow/filesystem/filesystem_library.h> | ||
| #include <arrow/io/memory.h> | ||
| #include <arrow/result.h> | ||
| #include <arrow/util/uri.h> | ||
|
|
||
| // Demonstrate registering a user-defined Arrow FileSystem outside | ||
| // of the Arrow source tree. | ||
|
|
||
| using arrow::Result; | ||
| using arrow::Status; | ||
| namespace io = arrow::io; | ||
| namespace fs = arrow::fs; | ||
|
|
||
| class ExampleFileSystem : public fs::FileSystem { | ||
| public: | ||
| explicit ExampleFileSystem(const io::IOContext& io_context) | ||
| : fs::FileSystem{io_context} {} | ||
|
|
||
| // This is a mock filesystem whose root directory contains a single file. | ||
| // All operations which would mutate will simply raise an error. | ||
| static constexpr std::string_view kPath = "example_file"; | ||
| static constexpr std::string_view kContents = "hello world"; | ||
| static fs::FileInfo info() { | ||
| fs::FileInfo info; | ||
| info.set_path(std::string{kPath}); | ||
| info.set_type(fs::FileType::File); | ||
| info.set_size(kContents.size()); | ||
| return info; | ||
| } | ||
|
|
||
| static Status NotFound(std::string_view path) { | ||
| return Status::IOError("Path does not exist '", path, "'"); | ||
| } | ||
|
|
||
| static Status NoMutation() { | ||
| return Status::IOError("operations which would mutate are not permitted"); | ||
| } | ||
|
|
||
| Result<std::string> PathFromUri(const std::string& uri_string) const override { | ||
| ARROW_ASSIGN_OR_RAISE(auto uri, arrow::util::Uri::FromString(uri_string)); | ||
| return uri.path(); | ||
| } | ||
|
|
||
| std::string type_name() const override { return "example"; } | ||
|
|
||
| bool Equals(const FileSystem& other) const override { | ||
| return type_name() == other.type_name(); | ||
| } | ||
|
|
||
| /// \cond FALSE | ||
| using FileSystem::CreateDir; | ||
| using FileSystem::DeleteDirContents; | ||
| using FileSystem::GetFileInfo; | ||
| using FileSystem::OpenAppendStream; | ||
| using FileSystem::OpenOutputStream; | ||
| /// \endcond | ||
|
|
||
| Result<fs::FileInfo> GetFileInfo(const std::string& path) override { | ||
| if (path == kPath) { | ||
| return info(); | ||
| } | ||
| return NotFound(path); | ||
| } | ||
|
|
||
| Result<std::vector<fs::FileInfo>> GetFileInfo(const fs::FileSelector& select) override { | ||
| if (select.base_dir == "/" || select.base_dir == "") { | ||
| return std::vector<fs::FileInfo>{info()}; | ||
| } | ||
| if (select.allow_not_found) { | ||
| return std::vector<fs::FileInfo>{}; | ||
| } | ||
| return NotFound(select.base_dir); | ||
| } | ||
|
|
||
| Status CreateDir(const std::string& path, bool recursive) override { | ||
| return NoMutation(); | ||
| } | ||
|
|
||
| Status DeleteDir(const std::string& path) override { return NoMutation(); } | ||
|
|
||
| Status DeleteDirContents(const std::string& path, bool missing_dir_ok) override { | ||
| return NoMutation(); | ||
| } | ||
|
|
||
| Status DeleteRootDirContents() override { return NoMutation(); } | ||
|
|
||
| Status DeleteFile(const std::string& path) override { return NoMutation(); } | ||
|
|
||
| Status Move(const std::string& src, const std::string& dest) override { | ||
| return NoMutation(); | ||
| } | ||
|
|
||
| Status CopyFile(const std::string& src, const std::string& dest) override { | ||
| return NoMutation(); | ||
| } | ||
|
|
||
| Result<std::shared_ptr<io::InputStream>> OpenInputStream( | ||
| const std::string& path) override { | ||
| return OpenInputFile(path); | ||
| } | ||
|
|
||
| Result<std::shared_ptr<io::RandomAccessFile>> OpenInputFile( | ||
| const std::string& path) override { | ||
| if (path == kPath) { | ||
| return io::BufferReader::FromString(std::string{kContents}); | ||
| } | ||
| return NotFound(path); | ||
| } | ||
|
|
||
| Result<std::shared_ptr<io::OutputStream>> OpenOutputStream( | ||
| const std::string& path, | ||
| const std::shared_ptr<const arrow::KeyValueMetadata>& metadata) override { | ||
| return NoMutation(); | ||
| } | ||
|
|
||
| Result<std::shared_ptr<io::OutputStream>> OpenAppendStream( | ||
| const std::string& path, | ||
| const std::shared_ptr<const arrow::KeyValueMetadata>& metadata) override { | ||
| return NoMutation(); | ||
| } | ||
| }; | ||
|
|
||
| fs::FileSystemRegistrar kExampleFileSystemModule{ | ||
| "example", | ||
| [](const arrow::util::Uri& uri, const io::IOContext& io_context, | ||
| std::string* out_path) -> Result<std::shared_ptr<fs::FileSystem>> { | ||
| auto fs = std::make_shared<ExampleFileSystem>(io_context); | ||
| if (out_path) { | ||
| ARROW_ASSIGN_OR_RAISE(*out_path, fs->PathFromUri(uri.ToString())); | ||
| } | ||
| return fs; | ||
| }, | ||
| }; | ||
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,55 @@ | ||
| // 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 <iostream> | ||
|
|
||
| #include <arrow/filesystem/filesystem.h> | ||
| #include <arrow/result.h> | ||
|
|
||
| namespace fs = arrow::fs; | ||
|
|
||
| // Demonstrate dynamically loading a user-defined Arrow FileSystem | ||
|
|
||
| arrow::Status Execute() { | ||
| ARROW_RETURN_NOT_OK(arrow::fs::LoadFileSystemFactories(FILESYSTEM_EXAMPLE_LIBPATH)); | ||
|
|
||
| std::string uri = "example:///example_file"; | ||
| std::cout << "Uri: " << uri << std::endl; | ||
|
|
||
| std::string path; | ||
| ARROW_ASSIGN_OR_RAISE(auto fs, arrow::fs::FileSystemFromUri(uri, &path)); | ||
| std::cout << "Path: " << path << std::endl; | ||
|
|
||
| fs::FileSelector sel; | ||
| sel.base_dir = "/"; | ||
| ARROW_ASSIGN_OR_RAISE(auto infos, fs->GetFileInfo(sel)); | ||
|
|
||
| std::cout << "Root directory contains:" << std::endl; | ||
| for (const auto& info : infos) { | ||
| std::cout << "- " << info << std::endl; | ||
| } | ||
| return arrow::Status::OK(); | ||
| } | ||
|
|
||
| int main() { | ||
| auto status = Execute(); | ||
| if (!status.ok()) { | ||
| std::cerr << "Error occurred : " << status.message() << std::endl; | ||
| return EXIT_FAILURE; | ||
| } | ||
| return EXIT_SUCCESS; | ||
| } |
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
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.