-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-40343: [C++] Move S3FileSystem to the registry #41559
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -876,6 +876,19 @@ if(ARROW_FILESYSTEM) | |
| foreach(ARROW_FILESYSTEM_TARGET ${ARROW_FILESYSTEM_TARGETS}) | ||
| target_link_libraries(${ARROW_FILESYSTEM_TARGET} PRIVATE ${AWSSDK_LINK_LIBRARIES}) | ||
| endforeach() | ||
|
|
||
| if(ARROW_S3_MODULE) | ||
| if(NOT ARROW_BUILD_SHARED) | ||
| message(FATAL_ERROR "ARROW_S3_MODULE without shared libarrow (-DARROW_BUILD_SHARED=ON) is not supported" | ||
| ) | ||
| endif() | ||
|
|
||
| add_library(arrow_s3fs MODULE filesystem/s3fs_module.cc filesystem/s3fs.cc) | ||
| target_link_libraries(arrow_s3fs PRIVATE ${AWSSDK_LINK_LIBRARIES} arrow_shared) | ||
| set_source_files_properties(filesystem/s3fs.cc filesystem/s3fs_module.cc | ||
| PROPERTIES SKIP_PRECOMPILE_HEADERS ON | ||
| SKIP_UNITY_BUILD_INCLUSION ON) | ||
|
||
| endif() | ||
| endif() | ||
|
|
||
| list(APPEND ARROW_TESTING_SHARED_LINK_LIBS ${ARROW_GTEST_GMOCK}) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| #include "arrow/adapters/orc/util.h" | ||
|
|
||
| #include <cmath> | ||
| #include <sstream> | ||
|
||
| #include <string> | ||
| #include <string_view> | ||
| #include <vector> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,6 +138,7 @@ | |
| #include "arrow/util/string.h" | ||
| #include "arrow/util/task_group.h" | ||
| #include "arrow/util/thread_pool.h" | ||
| #include "arrow/util/value_parsing.h" | ||
|
|
||
| namespace arrow::fs { | ||
|
|
||
|
|
@@ -169,6 +170,8 @@ static constexpr const char kAwsEndpointUrlEnvVar[] = "AWS_ENDPOINT_URL"; | |
| static constexpr const char kAwsEndpointUrlS3EnvVar[] = "AWS_ENDPOINT_URL_S3"; | ||
| static constexpr const char kAwsDirectoryContentType[] = "application/x-directory"; | ||
|
|
||
| using namespace std::string_literals; // NOLINT(build/namespaces) | ||
|
|
||
| // ----------------------------------------------------------------------- | ||
| // S3ProxyOptions implementation | ||
|
|
||
|
|
@@ -3082,6 +3085,30 @@ Result<std::string> S3FileSystem::PathFromUri(const std::string& uri_string) con | |
| internal::AuthorityHandlingBehavior::kPrepend); | ||
| } | ||
|
|
||
| Result<std::string> S3FileSystem::MakeUri(std::string path) const { | ||
| if (path.length() <= 1 || path[0] != '/') { | ||
| return Status::Invalid("MakeUri requires an absolute, non-root path, got ", path); | ||
| } | ||
| ARROW_ASSIGN_OR_RAISE(auto uri, util::UriFromAbsolutePath(path)); | ||
| if (!options().GetAccessKey().empty()) { | ||
| uri = "s3://" + options().GetAccessKey() + ":" + options().GetSecretKey() + "@" + | ||
| uri.substr("file:///"s.size()); | ||
|
||
| } else { | ||
| uri = "s3" + uri.substr("file"s.size()); | ||
| } | ||
| uri += "?"; | ||
| uri += "region=" + util::UriEscape(options().region); | ||
| uri += "&"; | ||
| uri += "scheme=" + util::UriEscape(options().scheme); | ||
| uri += "&"; | ||
| uri += "endpoint_override=" + util::UriEscape(options().endpoint_override); | ||
| uri += "&"; | ||
| uri += "allow_bucket_creation="s + (options().allow_bucket_creation ? "1" : "0"); | ||
| uri += "&"; | ||
| uri += "allow_bucket_deletion="s + (options().allow_bucket_deletion ? "1" : "0"); | ||
| return uri; | ||
| } | ||
felipecrv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| S3Options S3FileSystem::options() const { return impl_->options(); } | ||
|
|
||
| std::string S3FileSystem::region() const { return impl_->region(); } | ||
|
|
@@ -3572,32 +3599,33 @@ bool IsS3Finalized() { return GetAwsInstance()->IsFinalized(); } | |
|
|
||
| S3GlobalOptions S3GlobalOptions::Defaults() { | ||
| auto log_level = S3LogLevel::Fatal; | ||
|
|
||
| auto result = arrow::internal::GetEnvVar("ARROW_S3_LOG_LEVEL"); | ||
|
|
||
| if (result.ok()) { | ||
| // Extract, trim, and downcase the value of the environment variable | ||
| auto value = | ||
| arrow::internal::AsciiToLower(arrow::internal::TrimString(result.ValueUnsafe())); | ||
|
|
||
| if (value == "fatal") { | ||
| log_level = S3LogLevel::Fatal; | ||
| } else if (value == "error") { | ||
| log_level = S3LogLevel::Error; | ||
| } else if (value == "warn") { | ||
| log_level = S3LogLevel::Warn; | ||
| } else if (value == "info") { | ||
| log_level = S3LogLevel::Info; | ||
| } else if (value == "debug") { | ||
| log_level = S3LogLevel::Debug; | ||
| } else if (value == "trace") { | ||
| log_level = S3LogLevel::Trace; | ||
| } else if (value == "off") { | ||
| log_level = S3LogLevel::Off; | ||
| } | ||
| } | ||
|
|
||
| return S3GlobalOptions{log_level}; | ||
| int num_event_loop_threads = 1; | ||
| // Extract, trim, and downcase the value of the environment variable | ||
| auto value = arrow::internal::GetEnvVar("ARROW_S3_LOG_LEVEL") | ||
| .Map(arrow::internal::AsciiToLower) | ||
| .Map(arrow::internal::TrimString) | ||
| .ValueOr("fatal"); | ||
| if (value == "fatal") { | ||
| log_level = S3LogLevel::Fatal; | ||
| } else if (value == "error") { | ||
| log_level = S3LogLevel::Error; | ||
| } else if (value == "warn") { | ||
| log_level = S3LogLevel::Warn; | ||
| } else if (value == "info") { | ||
| log_level = S3LogLevel::Info; | ||
| } else if (value == "debug") { | ||
| log_level = S3LogLevel::Debug; | ||
| } else if (value == "trace") { | ||
| log_level = S3LogLevel::Trace; | ||
| } else if (value == "off") { | ||
| log_level = S3LogLevel::Off; | ||
| } | ||
|
|
||
| value = arrow::internal::GetEnvVar("ARROW_S3_THREADS").ValueOr("1"); | ||
| if (uint32_t u; ::arrow::internal::ParseUnsigned(value.data(), value.size(), &u)) { | ||
| num_event_loop_threads = u; | ||
| } | ||
| return S3GlobalOptions{log_level, num_event_loop_threads}; | ||
| } | ||
|
|
||
| // ----------------------------------------------------------------------- | ||
|
|
@@ -3615,4 +3643,14 @@ Result<std::string> ResolveS3BucketRegion(const std::string& bucket) { | |
| return resolver->ResolveRegion(bucket); | ||
| } | ||
|
|
||
| auto kS3FileSystemModule = ARROW_REGISTER_FILESYSTEM( | ||
| "s3", | ||
| [](const arrow::util::Uri& uri, const io::IOContext& io_context, | ||
| std::string* out_path) -> Result<std::shared_ptr<fs::FileSystem>> { | ||
| RETURN_NOT_OK(EnsureS3Initialized()); | ||
| ARROW_ASSIGN_OR_RAISE(auto options, S3Options::FromUri(uri, out_path)); | ||
| return S3FileSystem::Make(options, io_context); | ||
| }, | ||
| [] { DCHECK_OK(EnsureS3Finalized()); }); | ||
|
|
||
| } // namespace arrow::fs | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // 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_library.h" |
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.
@raulcd @pitrou I have rebased and enabled the S3 module build and test here on conda-cpp. Unless there are further comments, I'll merge on Monday