You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "geruh (via GitHub)" <gi...@apache.org> on 2025/02/26 08:49:30 UTC

[PR] feat(java): add WriteOptions for write methods [opendal]

geruh opened a new pull request, #5664:
URL: https://github.com/apache/opendal/pull/5664

   # Which issue does this PR close?
   
   related to #5651 
   
   Closes #.
   
   # Rationale for this change
   
   exposing write options to the java bindings for conditional writes
   
   # What changes are included in this PR?
   
   introduce write options to the exposed `write_with` method in rust
   
   # Are there any user-facing changes?
   
   yes
   


-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(java): add WriteOptions for write methods [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #5664:
URL: https://github.com/apache/opendal/pull/5664#discussion_r1976349174


##########
bindings/java/src/async_operator.rs:
##########
@@ -123,23 +126,58 @@ fn intern_write(
     executor: *const Executor,
     path: JString,
     content: JByteArray,
+    options: JObject,
 ) -> Result<jlong> {
     let op = unsafe { &mut *op };
     let id = request_id(env)?;
 
     let path = jstring_to_string(env, &path)?;
     let content = env.convert_byte_array(content)?;
+    let content_type = get_optional_string_from_object(env, &options, "getContentType")?;
+    let content_disposition = get_optional_string_from_object(env, &options, "getContentDisposition")?;
+    let content_encoding = get_optional_string_from_object(env, &options, "getContentEncoding")?;
+    let cache_control = get_optional_string_from_object(env, &options, "getCacheControl")?;
+    let if_match = get_optional_string_from_object(env, &options, "getIfMatch")?;
+    let if_none_match = get_optional_string_from_object(env, &options, "getIfNoneMatch")?;
+    let append = env.call_method(&options, "isAppend", "()Z", &[])?.z()?;
+    let if_not_exists = env.call_method(&options, "isIfNotExists", "()Z", &[])?.z()?;
+    let user_metadata = get_optional_map_from_object(env, &options, "getUserMetadata");
+
+    let mut write_op = op.write_with(&path, content);
+    if let Some(ct) = content_type {
+        write_op = write_op.content_type(&ct);
+    }
+    if let Some(cd) = content_disposition {
+        write_op = write_op.content_disposition(&cd);
+    }
+    if let Some(ce) = content_encoding {
+        write_op = write_op.content_encoding(&ce);
+    }
+    if let Some(cc) = cache_control {
+        write_op = write_op.cache_control(&cc);
+    }
+    if let Some(im) = if_match {
+        write_op = write_op.if_match(&im);
+    }
+    if let Some(inm) = if_none_match {
+        write_op = write_op.if_none_match(&inm);
+    }
+    if let Ok(Some(um)) = user_metadata {
+        write_op = write_op.user_metadata(um);
+    }
+    write_op = write_op.if_not_exists(if_not_exists);
+    write_op = write_op.append(append);
 
     executor_or_default(env, executor)?.spawn(async move {
-        let result = do_write(op, path, content).await;
+        let result = do_write(write_op).await;
         complete_future(id, result.map(|_| JValueOwned::Void))
     });
 
     Ok(id)
 }
 
-async fn do_write(op: &mut Operator, path: String, content: Vec<u8>) -> Result<()> {
-    Ok(op.write(&path, content).await.map(|_| ())?)
+async fn do_write(writer: FutureWrite<impl Future<Output =opendal::Result<Metadata>>>) -> Result<()> {

Review Comment:
   Maybe we can just remove this API? It seems to be used in only one place, and its signature is longer than its body.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(java): add WriteOptions for write methods [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo merged PR #5664:
URL: https://github.com/apache/opendal/pull/5664


-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(java): add WriteOptions for write methods [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #5664:
URL: https://github.com/apache/opendal/pull/5664#issuecomment-2692031449

   I also started a discussion about the issue I encountered in this PR: https://github.com/apache/opendal/discussions/5674


-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(java): add WriteOptions for write methods [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #5664:
URL: https://github.com/apache/opendal/pull/5664#issuecomment-2693447566

   Hi, @geruh, this PR is almost ready to go. We are waiting for a fix on main branch to bring our CI back.


-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org