kou commented on code in PR #41564:
URL: https://github.com/apache/arrow/pull/41564#discussion_r1599248880


##########
cpp/src/arrow/filesystem/s3fs.cc:
##########
@@ -1568,26 +1589,38 @@ class ObjectOutputStream final : public 
io::OutputStream {
     io::internal::CloseFromDestructor(this);
   }
 
-  Status Init() {
-    ARROW_ASSIGN_OR_RAISE(auto client_lock, holder_->Lock());
+  template <typename ObjectRequest>
+  Status SetMetadataInRequest(ObjectRequest* request) {
+    std::shared_ptr<const KeyValueMetadata> metadata;
 
-    // Initiate the multi-part upload
-    S3Model::CreateMultipartUploadRequest req;
-    req.SetBucket(ToAwsString(path_.bucket));
-    req.SetKey(ToAwsString(path_.key));
     if (metadata_ && metadata_->size() != 0) {
-      RETURN_NOT_OK(SetObjectMetadata(metadata_, &req));
+      metadata = metadata_;
     } else if (default_metadata_ && default_metadata_->size() != 0) {
-      RETURN_NOT_OK(SetObjectMetadata(default_metadata_, &req));
+      metadata = default_metadata_;
     }
 
-    // If we do not set anything then the SDK will default to application/xml
-    // which confuses some tools (https://github.com/apache/arrow/issues/11934)
-    // So we instead default to application/octet-stream which is less 
misleading
-    if (!req.ContentTypeHasBeenSet()) {
-      req.SetContentType("application/octet-stream");
+    if (metadata == nullptr ||
+        
!metadata->Contains(ObjectMetadataSetter<ObjectRequest>::CONTENT_TYPE_KEY)) {
+      // If we do not set anything then the SDK will default to application/xml
+      // which confuses some tools 
(https://github.com/apache/arrow/issues/11934)
+      // So we instead default to application/octet-stream which is less 
misleading
+      request->SetContentType("application/octet-stream");
+    } else {
+      RETURN_NOT_OK(SetObjectMetadata(metadata, request));
     }

Review Comment:
   How about swapping these clauses for easy to read?
   
   ```cpp
   if (metadata && 
metadata->Contains(ObjectMetadataSetter<ObjectRequest>::CONTENT_TYPE_KEY)) {
     RETURN_NOT_OK(SetObjectMetadata(metadata, request));
   } else {
     request->SetContentType("application/octet-stream");
   }
   ```
   



##########
cpp/src/arrow/filesystem/s3fs.cc:
##########
@@ -1568,26 +1589,38 @@ class ObjectOutputStream final : public 
io::OutputStream {
     io::internal::CloseFromDestructor(this);
   }
 
-  Status Init() {
-    ARROW_ASSIGN_OR_RAISE(auto client_lock, holder_->Lock());
+  template <typename ObjectRequest>
+  Status SetMetadataInRequest(ObjectRequest* request) {
+    std::shared_ptr<const KeyValueMetadata> metadata;
 
-    // Initiate the multi-part upload
-    S3Model::CreateMultipartUploadRequest req;
-    req.SetBucket(ToAwsString(path_.bucket));
-    req.SetKey(ToAwsString(path_.key));
     if (metadata_ && metadata_->size() != 0) {
-      RETURN_NOT_OK(SetObjectMetadata(metadata_, &req));
+      metadata = metadata_;
     } else if (default_metadata_ && default_metadata_->size() != 0) {
-      RETURN_NOT_OK(SetObjectMetadata(default_metadata_, &req));
+      metadata = default_metadata_;
     }
 
-    // If we do not set anything then the SDK will default to application/xml
-    // which confuses some tools (https://github.com/apache/arrow/issues/11934)
-    // So we instead default to application/octet-stream which is less 
misleading
-    if (!req.ContentTypeHasBeenSet()) {
-      req.SetContentType("application/octet-stream");
+    if (metadata == nullptr ||

Review Comment:
   ```suggestion
       if (!metadata ||
   ```



-- 
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]

Reply via email to