mrdrivingduck commented on code in PR #205:
URL: https://github.com/apache/paimon-cpp/pull/205#discussion_r3804005868
##########
CMakeLists.txt:
##########
@@ -85,6 +88,9 @@ endif()
if(PAIMON_ENABLE_JINDO)
add_definitions(-DPAIMON_ENABLE_JINDO)
endif()
+if(PAIMON_ENABLE_OSS)
Review Comment:
Done.
##########
src/paimon/fs/oss/oss_file_system_factory.cpp:
##########
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2026-present Alibaba Inc.
+ *
+ * Licensed 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 "paimon/fs/oss/oss_file_system_factory.h"
+
+#include <algorithm>
+#include <cctype>
+#include <memory>
+#include <string>
+
+#include "alibabacloud/oss2/ClientConfiguration.h"
+#include "alibabacloud/oss2/OSSClient.h"
+#include "alibabacloud/oss2/credentials/CredentialsProvider.h"
+#include "fmt/format.h"
+#include "paimon/common/utils/path_util.h"
+#include "paimon/factories/factory.h"
+#include "paimon/fs/oss/oss_file_system.h"
+
+namespace paimon::oss {
+namespace {
+
+namespace oss2 = alibabacloud::oss2;
+
+std::string GetOption(const std::map<std::string, std::string>& options, const
std::string& bucket,
+ const std::string& suffix) {
+ auto bucket_option = options.find("fs.oss.bucket." + bucket + "." +
suffix);
+ if (bucket_option != options.end()) {
+ return bucket_option->second;
+ }
+ auto global_option = options.find("fs.oss." + suffix);
+ return global_option == options.end() ? "" : global_option->second;
+}
+
+Result<std::string> GetRequiredOption(const std::map<std::string,
std::string>& options,
+ const std::string& bucket, const
std::string& suffix) {
+ std::string value = GetOption(options, bucket, suffix);
+ if (value.empty()) {
+ return Status::Invalid(fmt::format("OSS option 'fs.oss.{}' must not be
empty", suffix));
+ }
+ return value;
+}
+
+Result<bool> ParseBool(std::string value, const std::string& option) {
+ std::transform(value.begin(), value.end(), value.begin(),
+ [](unsigned char c) { return
static_cast<char>(std::tolower(c)); });
+ if (value == "true" || value == "1" || value == "yes" || value == "on") {
+ return true;
+ }
+ if (value == "false" || value == "0" || value == "no" || value == "off") {
+ return false;
+ }
+ return Status::Invalid(
+ fmt::format("invalid boolean value '{}' for OSS option '{}'", value,
option));
+}
+
+std::string InferRegion(std::string endpoint) {
+ constexpr std::string_view kPrefix = "oss-";
+ constexpr std::string_view kSuffix = ".aliyuncs.com";
+ size_t scheme = endpoint.find("://");
+ if (scheme != std::string::npos) {
+ endpoint.erase(0, scheme + 3);
+ }
+ size_t slash = endpoint.find('/');
+ if (slash != std::string::npos) {
+ endpoint.erase(slash);
+ }
+ if (endpoint.rfind(kPrefix, 0) != 0) {
+ return "";
+ }
+ size_t suffix = endpoint.find(kSuffix);
+ if (suffix == std::string::npos) {
+ return "";
+ }
+ std::string region = endpoint.substr(kPrefix.size(), suffix -
kPrefix.size());
+ constexpr std::string_view kInternal = "-internal";
+ if (region.size() > kInternal.size() &&
+ region.compare(region.size() - kInternal.size(), kInternal.size(),
kInternal) == 0) {
+ region.erase(region.size() - kInternal.size());
+ }
+ return region;
+}
+
+std::string NormalizeEndpoint(std::string endpoint) {
+ if (!endpoint.empty() && endpoint.find("://") == std::string::npos) {
+ endpoint = "https://" + endpoint;
+ }
+ return endpoint;
+}
+
+} // namespace
+
+const char OssFileSystemFactory::IDENTIFIER[] = "oss";
+
+Result<std::unique_ptr<FileSystem>> OssFileSystemFactory::Create(
+ const std::string& path, const std::map<std::string, std::string>&
options) const {
+ PAIMON_ASSIGN_OR_RAISE(Path parsed_path, PathUtil::ToPath(path));
+ if (parsed_path.scheme != "oss" || parsed_path.authority.empty()) {
+ return Status::Invalid(fmt::format("invalid OSS path '{}'", path));
+ }
+ const std::string& bucket = parsed_path.authority;
+ PAIMON_ASSIGN_OR_RAISE(std::string access_key_id,
+ GetRequiredOption(options, bucket, "accessKeyId"));
+ PAIMON_ASSIGN_OR_RAISE(std::string access_key_secret,
+ GetRequiredOption(options, bucket,
"accessKeySecret"));
+ std::string endpoint = GetOption(options, bucket, "endpoint");
+ std::string region = GetOption(options, bucket, "region");
+ if (region.empty()) {
+ region = InferRegion(endpoint);
+ }
+ if (endpoint.empty() && region.empty()) {
+ return Status::Invalid("OSS endpoint or region must be configured");
+ }
+ std::string security_token = GetOption(options, bucket, "securityToken");
+ if (security_token.empty()) {
+ security_token = GetOption(options, bucket, "sessionToken");
+ }
+
+ oss2::ClientConfiguration config =
oss2::ClientConfiguration::loadDefault();
+ if (!endpoint.empty()) {
+ config.endpoint = NormalizeEndpoint(endpoint);
+ }
+ config.region = region;
Review Comment:
Done.
##########
cmake_modules/ThirdpartyToolchain.cmake:
##########
@@ -1967,6 +2081,9 @@ if(PAIMON_ENABLE_JINDO)
build_jindosdk_c()
build_jindosdk_nextarch()
endif()
+if(PAIMON_ENABLE_OSS)
+ resolve_dependency(OSS_SDK_V2)
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]