You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "sunheyi6 (via GitHub)" <gi...@apache.org> on 2025/04/23 09:01:38 UTC
[PR] feat(bindings/java): Add new read API to support passing options [opendal]
sunheyi6 opened a new pull request, #6081:
URL: https://github.com/apache/opendal/pull/6081
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #5591
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!---
If there are any breaking changes to public APIs, please add the `breaking-changes` label.
-->
--
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(bindings/java): Add new read API to support passing options [opendal]
Posted by "sunheyi6 (via GitHub)" <gi...@apache.org>.
sunheyi6 commented on code in PR #6081:
URL: https://github.com/apache/opendal/pull/6081#discussion_r2057732004
##########
bindings/java/src/async_operator.rs:
##########
@@ -325,6 +396,76 @@ pub unsafe extern "system" fn Java_org_apache_opendal_AsyncOperator_delete(
})
}
+async fn do_read_with_offset<'local>(
+ op: &mut Operator,
+ offset: jlong,
+ len: jlong,
+ path: String,
+) -> Result<JObject<'local>> {
+ let offset = offset as u64;
+ let len = len as u64;
+
+ let buffer = op
+ .read_with(&path)
+ .range(offset..(offset + len))
+ .await?
+ .to_bytes();
+ let env = unsafe { get_current_env() };
+ let result = env.byte_array_from_slice(&buffer)?;
+ Ok(result.into())
+}
+
+async fn do_read_with_options<'local>(
+ op: &mut Operator,
+ read_options: JObject,
+ path: String,
+) -> Result<JObject<'local>> {
+ let offset = env.get_field(read_options, "offset", "J")?.j()?;
+ let length = {
+ let jlong = env.get_field(read_options, "length", "J")?.j()?;
+ if jlong == -1 {
+ None
+ } else {
+ Some(jlong as u64)
+ }
+ };
+ let buffer_size = env.get_field(read_options, "bufferSize", "I")?.i()? as usize;
+ let charset_name = env.get_field(read_options, "charset", "Ljava/lang/String;")?;
+ let charset = if !charset_name.is_null() {
+ let charset_str = env.get_string(charset_name.into())?;
+ Encoding::for_label(charset_str.to_bytes()).unwrap_or(UTF_8)
+ } else {
+ UTF_8
+ };
+ let skip_new_line = env.get_field(read_options, "skipNewLine", "Z")?.z()?;
+
+ let options = ReadOptions::builder()
+ .offset(offset)
+ .length(length)
+ .buffer_size(buffer_size)
+ .charset(charset)
+ .skip_new_line(skip_new_line)
+ .build()
+ .map_err(|e| {
+ Error::new(
+ ErrorKind::Other,
+ format!("Failed to build ReadOptions: {}", e),
+ )
+ })?;
+
+ let content = op.read_with(&path, &options).map_err(|e| {
Review Comment:
ok i will take a look.Do you think this readOptions shoud be option type like writeOptions or JObject? i'm not sure
--
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(bindings/java): Add new read API to support passing options [opendal]
Posted by "sunheyi6 (via GitHub)" <gi...@apache.org>.
sunheyi6 commented on PR #6081:
URL: https://github.com/apache/opendal/pull/6081#issuecomment-2854473593
https://github.com/apache/opendal/actions/runs/14728772245/job/41337908308?pr=6081#step:5:3995
It seems to be caused by sqlite itself?
--
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(bindings/java): Add new read API to support passing options [opendal]
Posted by "sunheyi6 (via GitHub)" <gi...@apache.org>.
sunheyi6 closed pull request #6081: feat(bindings/java): Add new read API to support passing options
URL: https://github.com/apache/opendal/pull/6081
--
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(bindings/java): Add new read API to support passing options [opendal]
Posted by "sunheyi6 (via GitHub)" <gi...@apache.org>.
sunheyi6 commented on PR #6081:
URL: https://github.com/apache/opendal/pull/6081#issuecomment-2868821555
Someone has already solved this problem, so I'm closing this PR.
--
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(bindings/java): Add new read API to support passing options [opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #6081:
URL: https://github.com/apache/opendal/pull/6081#issuecomment-2829365119
Hi @sunheyi6, I suggest marking this PR as a `draft` and ensuring the CI passes before requesting a review.
Please feel free to ask any questions directly in the PR if you have questions about implemention.
--
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(bindings/java): Add new read API to support passing options [opendal]
Posted by "sunheyi6 (via GitHub)" <gi...@apache.org>.
sunheyi6 commented on code in PR #6081:
URL: https://github.com/apache/opendal/pull/6081#discussion_r2057725761
##########
bindings/java/src/main/java/org/apache/opendal/ReadOptions.java:
##########
@@ -0,0 +1,36 @@
+package org.apache.opendal;
+
+import lombok.Builder;
+import java.nio.charset.Charset;
+
+/**
+ * Options for reading files. These options can be used to specify various parameters
+ * when reading a file.
+ */
+@Builder
+public class ReadOptions {
+ /**
+ * The starting offset for reading. Defaults to 0, which means reading from the beginning of the file.
+ */
Review Comment:
Of course, so it needs to be discussed. At present, I have only given a basic version.
--
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(bindings/java): Add new read API to support passing options [opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #6081:
URL: https://github.com/apache/opendal/pull/6081#issuecomment-2856830467
> https://github.com/apache/opendal/actions/runs/14728772245/job/41337908308?pr=6081#step:5:3995 It seems to be caused by sqlite itself?
Please take a look over
```
Error: Tests run: 7, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.021 s <<< FAILURE! -- in org.apache.opendal.test.behavior.BlockingReadOnlyTest
Error: org.apache.opendal.test.behavior.BlockingReadOnlyTest.testBlockingReadonlyReadOptions -- Time elapsed: 0.001 s <<< ERROR!
java.lang.UnsatisfiedLinkError: 'byte[] org.apache.opendal.Operator.read_with_options(long, org.apache.opendal.ReadOptions)'
at org.apache.opendal.Operator.read_with_options(Native Method)
at org.apache.opendal.Operator.read(Operator.java:107)
at org.apache.opendal.test.behavior.BlockingReadOnlyTest.testBlockingReadonlyReadOptions(BlockingReadOnlyTest.java:108)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.apache.maven.surefire.junitplatform.LazyLauncher.execute(LazyLauncher.java:56)
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.execute(JUnitPlatformProvider.java:184)
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:148)
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:122)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
```
--
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(bindings/java): Add new read API to support passing options [opendal]
Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #6081:
URL: https://github.com/apache/opendal/pull/6081#discussion_r2057327478
##########
bindings/java/src/async_operator.rs:
##########
@@ -325,6 +396,76 @@ pub unsafe extern "system" fn Java_org_apache_opendal_AsyncOperator_delete(
})
}
+async fn do_read_with_offset<'local>(
+ op: &mut Operator,
+ offset: jlong,
+ len: jlong,
+ path: String,
+) -> Result<JObject<'local>> {
+ let offset = offset as u64;
+ let len = len as u64;
+
+ let buffer = op
+ .read_with(&path)
+ .range(offset..(offset + len))
+ .await?
+ .to_bytes();
+ let env = unsafe { get_current_env() };
+ let result = env.byte_array_from_slice(&buffer)?;
+ Ok(result.into())
+}
+
+async fn do_read_with_options<'local>(
+ op: &mut Operator,
+ read_options: JObject,
+ path: String,
+) -> Result<JObject<'local>> {
+ let offset = env.get_field(read_options, "offset", "J")?.j()?;
+ let length = {
+ let jlong = env.get_field(read_options, "length", "J")?.j()?;
+ if jlong == -1 {
+ None
+ } else {
+ Some(jlong as u64)
+ }
+ };
+ let buffer_size = env.get_field(read_options, "bufferSize", "I")?.i()? as usize;
+ let charset_name = env.get_field(read_options, "charset", "Ljava/lang/String;")?;
+ let charset = if !charset_name.is_null() {
+ let charset_str = env.get_string(charset_name.into())?;
+ Encoding::for_label(charset_str.to_bytes()).unwrap_or(UTF_8)
+ } else {
+ UTF_8
+ };
+ let skip_new_line = env.get_field(read_options, "skipNewLine", "Z")?.z()?;
+
+ let options = ReadOptions::builder()
+ .offset(offset)
+ .length(length)
+ .buffer_size(buffer_size)
+ .charset(charset)
+ .skip_new_line(skip_new_line)
+ .build()
+ .map_err(|e| {
+ Error::new(
+ ErrorKind::Other,
+ format!("Failed to build ReadOptions: {}", e),
+ )
+ })?;
+
+ let content = op.read_with(&path, &options).map_err(|e| {
Review Comment:
I couldn’t find any `Operator::read_with` method that takes ReadOptions as a second parameter. I think we could build out the read by passing in the options similar to how the writes are handled.
But I know there’s an open issue (#5727) about supporting the passing Options like this, which seems super relevant!
--
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(bindings/java): Add new read API to support passing options [opendal]
Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #6081:
URL: https://github.com/apache/opendal/pull/6081#discussion_r2057328830
##########
bindings/java/src/main/java/org/apache/opendal/ReadOptions.java:
##########
@@ -0,0 +1,36 @@
+package org.apache.opendal;
+
+import lombok.Builder;
+import java.nio.charset.Charset;
+
+/**
+ * Options for reading files. These options can be used to specify various parameters
+ * when reading a file.
+ */
+@Builder
+public class ReadOptions {
+ /**
+ * The starting offset for reading. Defaults to 0, which means reading from the beginning of the file.
+ */
Review Comment:
Should we add support for the other write options?
--
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(bindings/java): Add new read API to support passing options [opendal]
Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #6081:
URL: https://github.com/apache/opendal/pull/6081#discussion_r2057328830
##########
bindings/java/src/main/java/org/apache/opendal/ReadOptions.java:
##########
@@ -0,0 +1,36 @@
+package org.apache.opendal;
+
+import lombok.Builder;
+import java.nio.charset.Charset;
+
+/**
+ * Options for reading files. These options can be used to specify various parameters
+ * when reading a file.
+ */
+@Builder
+public class ReadOptions {
+ /**
+ * The starting offset for reading. Defaults to 0, which means reading from the beginning of the file.
+ */
Review Comment:
Should we add support for the other read options?
--
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