Python: adds JSON.ARRPOP command#2407
Merged
shohamazon merged 6 commits intorelease-1.2from Nov 3, 2024
Merged
Conversation
b378399 to
a52ebf5
Compare
| For JSONPath (`path` starts with `$`): | ||
| Returns a list of bytes string replies for every possible path, representing the popped JSON values, | ||
| or None for JSON values matching the path that are not an array or are an empty array. | ||
| If a value is not an array, its corresponding return value is null. |
There was a problem hiding this comment.
Suggested change
| If a value is not an array, its corresponding return value is null. |
Signed-off-by: Shoham Elias <shohame@amazon.com>
Signed-off-by: Shoham Elias <shohame@amazon.com>
a52ebf5 to
e10015a
Compare
shohamazon
commented
Oct 31, 2024
Signed-off-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com>
ikolomi
approved these changes
Oct 31, 2024
Collaborator
ikolomi
left a comment
There was a problem hiding this comment.
Please address the comments
| >>> await json.arrpop(client, "doc", JsonArrPopOptions(path="$.a", index=1)) | ||
| [b'2'] # Pop second element from array at path $.a | ||
| >>> await json.arrpop(client, "doc", JsonArrPopOptions(path="$..a")) | ||
| [b'true', b'5', None] # Pop last elements from all arrays matching path `..a` |
There was a problem hiding this comment.
Suggested change
| [b'true', b'5', None] # Pop last elements from all arrays matching path `..a` | |
| [b'true', b'5', None] # Pop last elements from all arrays matching path `$..a` |
| b"1" # First match popped (from array at path ..a) | ||
|
|
||
| #### Even though only one value is returned from `..a`, subsequent arrays are also affected | ||
| >>> await json.get(client, "doc", "$..a") |
There was a problem hiding this comment.
Suggested change
| >>> await json.get(client, "doc", "$..a") | |
| >>> await json.get(client, "doc", "..a") |
Collaborator
Author
There was a problem hiding this comment.
No I wanted to show that even if we used ..a and just one value was returned, the rest of the matching paths were popped as well
acarbonetto
approved these changes
Nov 1, 2024
| glide_client, key, JsonArrPopOptions(path="non_existing_path") | ||
| ) | ||
|
|
||
| with pytest.raises(RequestError): |
Contributor
There was a problem hiding this comment.
we should make sure to include more comments for tests. it's not always obvious to readers what you're doing here.
Signed-off-by: Shoham Elias <shohame@amazon.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Pull Request is linked to issue (URL): #645
Checklist
Before submitting the PR make sure the following are checked: