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

Python: adds JSON.ARRPOP command #2407

Merged
merged 6 commits into from
Nov 3, 2024
Merged

Conversation

shohamazon
Copy link
Collaborator

@shohamazon shohamazon commented Oct 9, 2024

This Pull Request is linked to issue (URL): #645

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.

@shohamazon shohamazon requested a review from a team as a code owner October 9, 2024 08:53
@shohamazon shohamazon added the python Python wrapper label Oct 9, 2024
@shohamazon shohamazon changed the base branch from main to release-1.2 October 10, 2024 13:14
@shohamazon shohamazon mentioned this pull request Oct 10, 2024
22 tasks
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

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

Add changelog please

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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

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>
Signed-off-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com>
Copy link
Collaborator

@ikolomi ikolomi left a comment

Choose a reason for hiding this comment

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

Please address the comments

Signed-off-by: Shoham Elias <shohame@amazon.com>
Signed-off-by: Shoham Elias <shohame@amazon.com>
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

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

CI is red

>>> 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`
Copy link
Collaborator

Choose a reason for hiding this comment

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

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")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
>>> await json.get(client, "doc", "$..a")
>>> await json.get(client, "doc", "..a")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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

glide_client, key, JsonArrPopOptions(path="non_existing_path")
)

with pytest.raises(RequestError):
Copy link
Contributor

Choose a reason for hiding this comment

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

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>
@shohamazon shohamazon merged commit b091804 into release-1.2 Nov 3, 2024
16 checks passed
@shohamazon shohamazon deleted the python/json.arrpop branch November 3, 2024 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Python wrapper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants