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

Java: JSON.MGET. #2514

Merged
merged 6 commits into from
Nov 14, 2024
Merged

Conversation

Yury-Fridlyand
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand commented Oct 24, 2024

Issue link

#2430

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one issue.
  • Commit message has a detailed description of what changed and why.
  • Tests are added or updated.
  • CHANGELOG.md and documentation files are updated.
  • Destination branch is correct - main or release
  • Commits will be squashed upon merging.

Signed-off-by: Yury-Fridlyand <[email protected]>
@Yury-Fridlyand Yury-Fridlyand added the java issues and fixes related to the java client label Oct 24, 2024
@Yury-Fridlyand Yury-Fridlyand requested a review from a team as a code owner October 24, 2024 20:56
@Yury-Fridlyand Yury-Fridlyand changed the title JSON.MGET. Java: JSON.MGET. Oct 24, 2024
Copy link
Collaborator

@barshaul barshaul left a comment

Choose a reason for hiding this comment

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

see comments inline

glide-core/redis-rs/redis/src/cluster_routing.rs Outdated Show resolved Hide resolved
glide-core/redis-rs/redis/src/cluster_routing.rs Outdated Show resolved Hide resolved
glide-core/redis-rs/redis/src/cluster_routing.rs Outdated Show resolved Hide resolved
glide-core/redis-rs/redis/src/cluster_routing.rs Outdated Show resolved Hide resolved
@Yury-Fridlyand Yury-Fridlyand dismissed barshaul’s stale review November 7, 2024 21:17

Dropping these comments, becase GLIDE core changes were done in #2587

Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
@Yury-Fridlyand
Copy link
Collaborator Author

{98ADBF6C-401F-4E16-AF46-1358C48C1EE8}

@NonNull BaseClient client, @NonNull String[] keys, @NonNull String path) {
return Json.<Object[]>executeCommand(
client, concatenateArrays(new String[] {JSON_MGET}, keys, new String[] {path}))
.thenApply(res -> castArray(res, String.class));
Copy link
Collaborator

Choose a reason for hiding this comment

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

A bit of confusion here. So 3 things:

  1. the thenApply() call here on line 452
  2. the <Object[]> type hint before invoking executeCommand() on line 450
  3. the final convertion in executeCommand(), which will convert to whatever the method return type is (.thenApply(r -> (T) r)) on line 2709 (for mget(), T is String[])

Not sure why all 3 are needed here. Isn't 3 alone good enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lib.rs returns an arbitrary Object[], it cannot be casted to String[], so we have to use castArray.
So what happens here:

  1. libglide returns Object[]
  2. customCommand returns Object (which is actually array, yes)
  3. with Json.<Object[]> prefix we instruct that we expect Object[]
  4. with .thenApply(r -> (T) r) we safely cast this Object to Object[]
  5. with castArray we convert Object[] to String[]

So in total there is a chained Object -> Object[] -> String[] conversion distrubuted over multiple places of code 🤷
I'd like to refactor this if you give me an idea.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also note: we kind of have to go through Object -> Object[] -> String[].
This is because castArray requires the Object[] type. We cannot cast Object[] to String[] directly, but we need to cast all inner elements (thank you Java).

@NonNull BaseClient client, @NonNull String[] keys, @NonNull String path) {
return Json.<Object[]>executeCommand(
client, concatenateArrays(new String[] {JSON_MGET}, keys, new String[] {path}))
.thenApply(res -> castArray(res, String.class));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also note: we kind of have to go through Object -> Object[] -> String[].
This is because castArray requires the Object[] type. We cannot cast Object[] to String[] directly, but we need to cast all inner elements (thank you Java).

…n.java

Co-authored-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
@Yury-Fridlyand Yury-Fridlyand merged commit d052c4c into release-1.2 Nov 14, 2024
15 checks passed
@Yury-Fridlyand Yury-Fridlyand deleted the java/yuryf-json.mget-valkey-447 branch November 14, 2024 01:02
prateek-kumar-improving pushed a commit that referenced this pull request Nov 14, 2024
* `JSON.MGET`.

Signed-off-by: Yury-Fridlyand <[email protected]>
Co-authored-by: James Xin <[email protected]>
Co-authored-by: Andrew Carbonetto <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java issues and fixes related to the java client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow sending keys from different slots on JSON.MGET for CME
5 participants