Skip to content

feat(binding/java): add list & remove_all support#3333

Merged
tisonkun merged 23 commits intoapache:mainfrom
G-XD:java_binding_list
Oct 25, 2023
Merged

feat(binding/java): add list & remove_all support#3333
tisonkun merged 23 commits intoapache:mainfrom
G-XD:java_binding_list

Conversation

@G-XD
Copy link
Copy Markdown
Contributor

@G-XD G-XD commented Oct 18, 2023

Related: #3169

@github-actions github-actions Bot added the releases-note/feat The PR implements a new feature or has a title that begins with "feat" label Oct 18, 2023
@tisonkun
Copy link
Copy Markdown
Member

tisonkun commented Oct 18, 2023

Let's wait a bit for the refactor PR #3332 and do a rebase. I assume that rebase this PR is simpler than rebase that one (for behavior tests). Sorry to make such conflicts.

@tisonkun
Copy link
Copy Markdown
Member

Now you can do the rebase and I'll review this PR in about days - I'm a bit busy in today and tomorrow.

G-XD added 2 commits October 18, 2023 22:28
# Conflicts:
#	bindings/java/src/test/java/org/apache/opendal/test/behavior/AbstractBehaviorTest.java
Comment thread .gitattributes
Comment thread bindings/java/src/main/java/org/apache/opendal/args/OpList.java Outdated
Comment thread bindings/java/src/lib.rs Outdated
Comment thread bindings/java/src/main/java/org/apache/opendal/BlockingOperator.java Outdated
@G-XD
Copy link
Copy Markdown
Contributor Author

G-XD commented Oct 20, 2023

Hi @tisonkun @Xuanwo , PTAL

Copy link
Copy Markdown
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I support the changes for:

  • remove all
  • list without args

Perhaps we can have another round to think of how to pass over args via JNI. But as long as we don't populate a large amount methods in this flavor, I can support to give it a try (as a baseline to improve).

BTW, how to convert list is another issue, you can take a look at this PR for another flavor. I don't have a strong preference for this point but we may align the pattern.

@Xuanwo
Copy link
Copy Markdown
Member

Xuanwo commented Oct 23, 2023

BTW, how to convert list is another issue, you can take a look at this PR for another flavor. I don't have a strong preference for this point but we may align the pattern.

I'm not sure if builder pattern is a good idea in java like:

op.list_with()
    .limit(5)
    .startAfter(someElement)
    .join();

But anyway, I do agree with @tisonkun's comment that we can merge remove_all and list support first. We can try and discuss the api for list_with in following PRs.

@G-XD
Copy link
Copy Markdown
Contributor Author

G-XD commented Oct 23, 2023

BTW, how to convert list is another issue, you can take a look at this PR for another flavor. I don't have a strong preference for this point but we may align the pattern.

Since the List is not returned directly in Operator, but rather CompletableFuture, I modified loadEnabledServices().

@tisonkun
Copy link
Copy Markdown
Member

@G-XD One things to be verified:

  • set_object_array_element is a native JNI call;
  • List with put via JNI is crossing the language boundary.

Do you check which one is more efficient?

I prefer set_object_array_element and construct List with a preset array to avoid too many cross boundary invocations. But I don't do a performance test yet.

@G-XD
Copy link
Copy Markdown
Contributor Author

G-XD commented Oct 23, 2023

Do you check which one is more efficient?

I didn't do a performance comparison test, but I think minimize marshalling of resources across the JNI layer is correct.

@Xuanwo
Copy link
Copy Markdown
Member

Xuanwo commented Oct 23, 2023

What's the difference of List and Entry[]?

@tisonkun
Copy link
Copy Markdown
Member

tisonkun commented Oct 24, 2023

op.list_with()
    .limit(5)
    .startAfter(someElement)
    .join();

This is exactly what I expected to implement in Java API. Let's investigate it in a following PR.

Maybe

class Lister {
  private final Operator op;
  private int limit;
  public Lister limit(int limit) {
    this.limit = limit;
    return this;
  }

  public CompletableFuture<T> execute() {
   return executeNative(op, limit, <other args>); 
  }

  private static native executeNative( ... );
}

Comment thread bindings/java/src/main/java/org/apache/opendal/BlockingOperator.java Outdated
Comment thread bindings/java/src/main/java/org/apache/opendal/Operator.java Outdated
Comment thread bindings/java/src/main/java/org/apache/opendal/Operator.java Outdated
Comment thread bindings/java/src/main/java/org/apache/opendal/Operator.java Outdated
Copy link
Copy Markdown
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good. Comments inline.

Comment thread bindings/java/src/operator.rs Outdated
Copy link
Copy Markdown
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other LGTM from my side.

Comment thread .github/workflows/bindings_java.yml Outdated
Comment thread bindings/java/src/main/java/org/apache/opendal/Operator.java Outdated
@tisonkun
Copy link
Copy Markdown
Member

Merging...

Thanks for your excellent work!

@tisonkun tisonkun merged commit c5333ea into apache:main Oct 25, 2023
@G-XD G-XD deleted the java_binding_list branch October 25, 2023 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

releases-note/feat The PR implements a new feature or has a title that begins with "feat"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants