This is an automated email from the ASF dual-hosted git repository.

zhouyuan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new ad96f33f7f [GLUTEN-13645][VL] Fix per-bucket S3A configs for bucket 
names containing dots (#13646)
ad96f33f7f is described below

commit ad96f33f7f3204f0a22465ae80d7eacd0fbe63ae
Author: Pratham Manja <[email protected]>
AuthorDate: Wed Nov 18 04:11:16 2026 +0530

    [GLUTEN-13645][VL] Fix per-bucket S3A configs for bucket names containing 
dots (#13646)
    
    Per-bucket options (spark.hadoop.fs.s3a.bucket.<bucket>.<option>) were split
    at the first dot, so for a bucket such as `my.data.bucket` the bucket name
    was parsed as `my` and the option was silently dropped. Match a known option
    suffix at the end of the key instead (longest match wins), as Hadoop S3A
    does, and add a unit test for dotted and undotted bucket names.
---
 cpp/velox/tests/GlutenS3FileSystemTest.cc | 38 +++++++++++++++++++++++++++++++
 cpp/velox/utils/ConfigExtractor.cc        | 33 ++++++++++++++++-----------
 2 files changed, 58 insertions(+), 13 deletions(-)

diff --git a/cpp/velox/tests/GlutenS3FileSystemTest.cc 
b/cpp/velox/tests/GlutenS3FileSystemTest.cc
index 772843b50f..a09729c25c 100644
--- a/cpp/velox/tests/GlutenS3FileSystemTest.cc
+++ b/cpp/velox/tests/GlutenS3FileSystemTest.cc
@@ -68,5 +68,43 @@ TEST(GlutenS3FileSystemTest, extractsAsyncUploadConfigs) {
   EXPECT_EQ(hiveConfig->get<std::string>(prefix + "upload-threads"), "32");
 }
 
+TEST(GlutenS3FileSystemTest, extractsPerBucketConfigs) {
+  using Keys = filesystems::S3Config::Keys;
+  auto config = 
std::make_shared<velox::config::ConfigBase>(std::unordered_map<std::string, 
std::string>{
+      {"spark.hadoop.fs.s3a.bucket.plain-bucket.endpoint", 
"http://plain:9000"},
+      {"spark.hadoop.fs.s3a.bucket.my.data.bucket.endpoint", 
"http://dotted:9000"},
+      {"spark.hadoop.fs.s3a.bucket.my.data.bucket.access.key", 
"dotted-access"},
+      {"spark.hadoop.fs.s3a.bucket.my.data.bucket.endpoint.region", 
"us-west-2"},
+      {"spark.hadoop.fs.s3a.bucket.my.data.bucket.iam.role.session.name", 
"dotted-session"},
+      {"spark.hadoop.fs.s3a.bucket.my.data.bucket.unknown.option", "ignored"},
+      // Malformed keys are ignored too: no bucket name, empty bucket name, no 
dot before the option.
+      {"spark.hadoop.fs.s3a.bucket.endpoint", "ignored"},
+      {"spark.hadoop.fs.s3a.bucket..endpoint", "ignored"},
+      {"spark.hadoop.fs.s3a.bucket.myendpoint", "ignored"}});
+
+  const auto hiveConfig = createHiveConnectorConfig(config, 
FileSystemType::kS3);
+
+  auto bucketValue = [&](Keys key, std::string_view bucket) {
+    return 
hiveConfig->get<std::string>(filesystems::S3Config::bucketConfigKey(key, 
bucket));
+  };
+  EXPECT_EQ(bucketValue(Keys::kEndpoint, "plain-bucket"), "http://plain:9000";);
+  EXPECT_EQ(bucketValue(Keys::kEndpoint, "my.data.bucket"), 
"http://dotted:9000";);
+  EXPECT_EQ(bucketValue(Keys::kAccessKey, "my.data.bucket"), "dotted-access");
+  EXPECT_EQ(bucketValue(Keys::kEndpointRegion, "my.data.bucket"), "us-west-2");
+  EXPECT_EQ(bucketValue(Keys::kIamRoleSessionName, "my.data.bucket"), 
"dotted-session");
+
+  // Nothing is registered under a bucket name truncated at the first dot.
+  EXPECT_FALSE(bucketValue(Keys::kEndpoint, "my").has_value());
+
+  // Only the five recognized options above produce per-bucket Velox configs.
+  size_t numBucketConfigs = 0;
+  for (const auto& [key, value] : hiveConfig->rawConfigs()) {
+    if (key.rfind(filesystems::S3Config::kS3BucketPrefix, 0) == 0) {
+      ++numBucketConfigs;
+    }
+  }
+  EXPECT_EQ(numBucketConfigs, 5);
+}
+
 } // namespace
 } // namespace gluten
diff --git a/cpp/velox/utils/ConfigExtractor.cc 
b/cpp/velox/utils/ConfigExtractor.cc
index 0d551a93eb..1f87ac8848 100644
--- a/cpp/velox/utils/ConfigExtractor.cc
+++ b/cpp/velox/utils/ConfigExtractor.cc
@@ -84,14 +84,25 @@ void getS3HiveConfig(
       {S3Config::Keys::kIMDSEnabled, std::make_pair("aws.imds.enabled", 
"true")},
   };
 
-  // get Velox S3 config key from Spark Suffix.
-  auto getVeloxKey = [&](std::string_view suffix) {
+  // Split "<bucket>.<suffix>" into the bucket name and the Velox S3 config 
key. Bucket names may contain dots,
+  // so match a known Spark suffix at the end instead of splitting at the 
first dot. The longest matching suffix
+  // wins, e.g. "endpoint.region" over "endpoint".
+  auto parseBucketConfig = [&](std::string_view bucketAndSuffix) {
+    std::optional<std::pair<S3Config::Keys, std::string_view>> result;
+    size_t matchedSuffixSize = 0;
     for (const auto& [key, value] : sparkSuffixes) {
-      if (value.first == suffix) {
-        return std::optional<S3Config::Keys>(key);
+      const std::string_view suffix = value.first;
+      // At least one character for the bucket name plus the separating dot.
+      if (bucketAndSuffix.size() < suffix.size() + 2 || suffix.size() <= 
matchedSuffixSize) {
+        continue;
+      }
+      const auto dotPos = bucketAndSuffix.size() - suffix.size() - 1;
+      if (bucketAndSuffix[dotPos] == '.' && bucketAndSuffix.substr(dotPos + 1) 
== suffix) {
+        result = std::make_pair(key, bucketAndSuffix.substr(0, dotPos));
+        matchedSuffixSize = suffix.size();
       }
     }
-    return std::optional<S3Config::Keys>(std::nullopt);
+    return result;
   };
 
   auto sparkBaseConfigValue = [&](S3Config::Keys key) {
@@ -162,14 +173,10 @@ void getS3HiveConfig(
   for (const auto& [key, value] : conf->rawConfigs()) {
     if (key.find(kSparkHadoopS3BucketPrefix) == 0) {
       std::string_view skey = key;
-      auto remaining = skey.substr(kSparkHadoopS3BucketPrefix.size());
-      int dot = remaining.find(".");
-      auto bucketName = remaining.substr(0, dot);
-      auto suffix = remaining.substr(dot + 1);
-      auto veloxKey = getVeloxKey(suffix);
-
-      if (veloxKey.has_value()) {
-        hiveConfMap[S3Config::bucketConfigKey(veloxKey.value(), bucketName)] = 
value;
+      auto bucketConfig = 
parseBucketConfig(skey.substr(kSparkHadoopS3BucketPrefix.size()));
+      if (bucketConfig.has_value()) {
+        const auto& [veloxKey, bucketName] = bucketConfig.value();
+        hiveConfMap[S3Config::bucketConfigKey(veloxKey, bucketName)] = value;
       }
     }
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to