Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add builder.copy for external retry logic #1228

Open
injae-kim opened this issue Oct 14, 2024 · 2 comments
Open

[FEATURE] Add builder.copy for external retry logic #1228

injae-kim opened this issue Oct 14, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@injae-kim
Copy link

injae-kim commented Oct 14, 2024

Is your feature request related to a problem?

index = ..;
targetId = ..;
Bool.QueryBuilder queryBuilder = builder(index, targetId, ..);

return search(queryBuilder);

--

public doc search(queryBuilder) { 
  RxJava.retry(retry -> {
    opensearchClient.search(queryBuilder, ..); // ⭐ on retry, re-use same query builder
  });
}

protected void _checkSingleUse() {
if (this._used) {
throw new IllegalStateException("Object builders can only be used once");
}

java.lang.IllegalStateException: Object builders can only be used once

Users can use external retry logic with query builder like above.
But we can't re-use the same query builder on open search so IllegalStateException exception thrown.

What solution would you like?

Bool.QueryBuilder queryBuilder = builder(index, targetId, ..);
return search(queryBuilder);

--

public doc search(queryBuilder) { 
  RxJava.retry(retry -> {
    opensearchClient.search(queryBuilder.copy(), ..); // ⭐ add builder.copy()
  });
}

If we can use queryBudiler.copy(), it's really useful for several cases!

@injae-kim injae-kim added enhancement New feature or request untriaged labels Oct 14, 2024
@injae-kim
Copy link
Author

I think builder.copy() is usually supported on many other db-client library so it's okay to add it on openserach java client too. and I think many opensearch user need this feature.

I'm contributor on other opensource so I can make PR so PTAL 🙇

@Xtansia Xtansia removed the untriaged label Oct 15, 2024
@Xtansia
Copy link
Collaborator

Xtansia commented Oct 15, 2024

Thanks for bringing this up. It should be relatively easy to implement on the generated code. Some things to consider:

  • Would you expect this to be a surface-level copy or a clone/deep-copy? Lists & Maps would need to be properly copied as we append to them in builders. But what do we do with nested objects.
  • Which use-cases require the builder implementing copy versus just re-using the built object from the builder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants