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

Support for the JSON.ARRPOP command #1874

Merged
merged 4 commits into from
Nov 5, 2023
Merged

Conversation

jyf111
Copy link
Contributor

@jyf111 jyf111 commented Nov 3, 2023

This PR adds support for the JSON.ARRPOP command.

closes #1810.

src/types/json.h Outdated
Comment on lines 225 to 230
auto popped_iter = val.array_range().begin();
if (index == -1 || index >= static_cast<int64_t>(val.size())) {
popped_iter = val.array_range().end() - 1;
} else if (index > 0) {
popped_iter += index;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think if the index is negative, we need to calculate the real position from the end.

127.0.0.1:6666> json.set a $ [1,2,3,4]
OK
127.0.0.1:6666> json.arrpop a $ -2
1) "3"
127.0.0.1:6666>

I recommend you to try it by yourself : )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry I misunderstood Out-of-range indexes round to their respective array ends stated in the doc.

I've fixed it based on the below code in RedisJson.

impl ArrayIndex for i64 {
    fn normalize(self, len: i64) -> usize {
        let index = if self < 0 {
            len - len.min(-self)
        } else if len > 0 {
            (len - 1).min(self)
        } else {
            0
        };
        index as usize
    }
}

@PragmaTwice
Copy link
Member

PragmaTwice commented Nov 4, 2023

Could you try to fix these issue reported by clang-tidy in CI?

https://github.com/apache/kvrocks/actions/runs/6754872818/job/18363385655?pr=1874

@jyf111
Copy link
Contributor Author

jyf111 commented Nov 5, 2023

Could you try to fix these issue reported by clang-tidy in CI?

Fixed.

Copy link

sonarcloud bot commented Nov 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@PragmaTwice PragmaTwice merged commit e0fec89 into apache:unstable Nov 5, 2023
30 checks passed
@PragmaTwice
Copy link
Member

Thank you for your contribution!

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

Successfully merging this pull request may close these issues.

Add support for the JSON.ARRPOP command
2 participants