Skip to content

Python: adds JSON.ARRPOP command#2407

Merged
shohamazon merged 6 commits intorelease-1.2from
python/json.arrpop
Nov 3, 2024
Merged

Python: adds JSON.ARRPOP command#2407
shohamazon merged 6 commits intorelease-1.2from
python/json.arrpop

Conversation

@shohamazon
Copy link
Copy Markdown
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
Copy Markdown

@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
Copy Markdown

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
Copy Markdown
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
Copy Markdown

@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
Copy Markdown

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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
@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