Skip to content

Conversation

@cuichenli
Copy link
Contributor

Rationale for this change

Currently, the java binding only support list current directory, it would be nice to have the ability to list recursively. Given opendal itself already supported this, I think it is reasonable to add this to the java binding as well. But I am not sure if that is suitable, so please feel free to correct me if I missed anything. It is a little bit tricky to add the unit test directly, given fs service it self does not support recursively list. But I have tested in my java program with s3 and gcs, they are working as expected.

What changes are included in this PR?

Added one paramater to support list recursively. Also fixed one unit test.

Are there any user-facing changes?

Java binding's list API changed.

@cuichenli cuichenli requested a review from tisonkun as a code owner March 9, 2025 16:15
@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 Mar 9, 2025
@cuichenli
Copy link
Contributor Author

i also fixed one unit test failing on my local machine, but looks like it is failing in ci. i will revert it later

@Xuanwo
Copy link
Member

Xuanwo commented Mar 9, 2025

Considering that we will be adding more arguments for the list, how about following the same pattern to add this? #5664

It is a little bit tricky to add the unit test directly, given fs service it self does not support recursively list.

fs should support recursive list since we have applied some wrapper for it

@cuichenli
Copy link
Contributor Author

fs should support recursive list since we have applied some wrapper for it

which service should i use? do i need to verify the capability as well? i observed error when specify the capability.list_with_recursive.

i will update the code later to align with the pr you provided.

@Xuanwo
Copy link
Member

Xuanwo commented Mar 10, 2025

which service should i use? do i need to verify the capability as well? i observed error when specify the capability.list_with_recursive.

I remember that all services implementing list will automatically support recursive. I will double-check this later.

@cuichenli
Copy link
Contributor Author

I remember that all services implementing list will automatically support recursive. I will double-check this later.

again, i may be wrong, but looks like the option for fs list is not used. so i think there is no recursive supprot for fs

async fn list(&self, path: &str, _: OpList) -> Result<(RpList, Self::Lister)> {

@Xuanwo
Copy link
Member

Xuanwo commented Mar 10, 2025

again, i may be wrong, but looks like the option for fs list is not used. so i think there is no recursive supprot for fs

Hi, it's implemeneted outsides at

async fn complete_list(
&self,
path: &str,
args: OpList,
) -> Result<(RpList, CompleteLister<A, A::Lister>)> {
let cap = self.info.native_capability();
let recursive = args.recursive();
match (recursive, cap.list_with_recursive) {
// - If service can list_with_recursive, we can forward list to it directly.
(_, true) => {
let (rp, p) = self.inner.list(path, args).await?;
Ok((rp, CompleteLister::One(p)))
}
// If recursive is true but service can't list_with_recursive
(true, false) => {
// Forward path that ends with /
if path.ends_with('/') {
let p = FlatLister::new(self.inner.clone(), path);
Ok((RpList::default(), CompleteLister::Two(p)))
} else {
let parent = get_parent(path);
let p = FlatLister::new(self.inner.clone(), parent);
let p = PrefixLister::new(p, path);
Ok((RpList::default(), CompleteLister::Four(p)))
}
}
// If recursive and service doesn't support list_with_recursive, we need to handle
// list prefix by ourselves.
(false, false) => {
// Forward path that ends with /
if path.ends_with('/') {
let (rp, p) = self.inner.list(path, args).await?;
Ok((rp, CompleteLister::One(p)))
} else {
let parent = get_parent(path);
let (rp, p) = self.inner.list(parent, args).await?;
let p = PrefixLister::new(p, path);
Ok((rp, CompleteLister::Three(p)))
}
}
}
}

Sorry for making you feel confused. We have a plan to refactor this part to make it more clear.

@cuichenli cuichenli force-pushed the add-java-recursive-list branch from 883f37b to e83ea59 Compare March 18, 2025 14:54
@cuichenli cuichenli marked this pull request as draft March 18, 2025 15:11

let path = jstring_to_string(env, &path)?;

let recursive = if env.call_method(&options, "isRecursive", "()Z", &[])?.z()? {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i had some trouble on passing the options to the async block so that is the best way i can do. please let me know if that is not suitable, i may need some help on how to pass this arround. thanks

@cuichenli cuichenli requested review from Xuanwo and tisonkun March 18, 2025 15:23
@cuichenli cuichenli marked this pull request as ready for review March 18, 2025 15:23
Copy link
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.

Hi, I'm a bit confused why we need to apply CompleteLayer?


mod complete;
pub(crate) use complete::CompleteLayer;
pub use complete::CompleteLayer;
Copy link
Member

Choose a reason for hiding this comment

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

CompleteLayer is applied by default. We don't need to apply it again.

@cuichenli cuichenli requested a review from Xuanwo March 20, 2025 01:54
Copy link
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.

Thank you @cuichenli for working on this. This PR looks good to me. Wait for @tisonkun and @G-XD for another look.

@Xuanwo Xuanwo changed the title feat(binding/java) add list with recursive support feat(binding/java): Add list with recursive support Mar 20, 2025
@tisonkun
Copy link
Member

Make some code style change and approved. Keep all the binding mappings follow a similar structure and avoid some unnecessary clone.

@Xuanwo
Copy link
Member

Xuanwo commented Mar 20, 2025

Thank you @cuichenli and @tisonkun for working on this!

@Xuanwo Xuanwo merged commit 2f404e4 into apache:main Mar 20, 2025
65 checks passed
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