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

feat(server): implement JSON.TOGGLE & JSON.ARRLEN & JSON.OBJLEN commands #228

Merged
merged 1 commit into from
Aug 16, 2022

Conversation

iko1
Copy link
Contributor

@iko1 iko1 commented Aug 6, 2022

Signed-off-by: iko1 [email protected]

fixes: #241

Copy link
Collaborator

@romange romange left a comment

Choose a reason for hiding this comment

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

Thanks for implementing this!

src/server/json_family.cc Outdated Show resolved Hide resolved
src/server/json_family.cc Outdated Show resolved Hide resolved
src/server/json_family.cc Outdated Show resolved Hide resolved
src/server/json_family_test.cc Outdated Show resolved Hide resolved
src/server/json_family_test.cc Show resolved Hide resolved
(*cntx)->StartArray(result->size());
for (auto& it: *result) {
if (it.has_value()) {
(*cntx)->SendLong(*it);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@romange, Should I implement a function that retrieves a long long value, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

you mean like SendLong? Then no, because on 64bit architectures long long and long is the same and we are only 64bit.

vector<OptLongLong> vec;
auto cb = [&](const string& path, json& val) {
if (val.is_number()) {
auto current_val = val.as<long long>() * num;
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 should return an OVERFLOW error if the result is out of the range of 64-bit IEEE double.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In order to provide fully compatible behavior, we need to setup an elasticache instance and learn how these special cases are handled there. That's out of scope of this assignment at this point.

what I usually do is I write // TODO: .... comments when the code needs further enhancement.

return result.status();
}

vector<OptLongLong> vec;
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add a comment TODO: to check how double and boolean are handled by INCRBY

@romange
Copy link
Collaborator

romange commented Aug 13, 2022

Please see #240. I suggest that you copy json.NUMINCRBY and json.NUMMULTBY changes aside and pull them out of this PR. For several reasons:

  1. the title of this PR corresponds to other commands.
  2. they need a significant rewrite because internally you need to manage doubles and not long long and this PR becomes too big anyway.

@romange romange changed the title feat(server): implement JSON.TOGGLE & JSON.ARRLEN & JSON.OBJLEN commands (#225) feat(server): implement JSON.TOGGLE & JSON.ARRLEN & JSON.OBJLEN commands Aug 13, 2022
@iko1 iko1 force-pushed the Json branch 2 times, most recently from a02b27a to 55c96ea Compare August 15, 2022 05:20
@iko1
Copy link
Contributor Author

iko1 commented Aug 15, 2022

Please see #240. I suggest that you copy json.NUMINCRBY and json.NUMMULTBY changes aside and pull them out of this PR. For several reasons:

1. the title of this PR corresponds to other commands.

2. they need a significant rewrite because internally you need to manage doubles and not long long and this PR becomes too big anyway.

This PR contains only the commands described in the title. Other JSON commands that were related to this PR will copy to another PR with a significant refactor(Thanks for the comments).

@iko1 iko1 requested a review from romange August 15, 2022 05:23
src/server/json_family.cc Outdated Show resolved Hide resolved
src/server/json_family.cc Outdated Show resolved Hide resolved
@iko1 iko1 force-pushed the Json branch 2 times, most recently from 37d8c60 to 1e23005 Compare August 15, 2022 18:32
if (result->empty()) {
(*cntx)->SendNullArray();
} else {
(*cntx)->StartArray(result->size());
Copy link
Collaborator

Choose a reason for hiding this comment

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

there are three repetitions of the same code of sending a long array.
We can factor them out in the next changes.

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 put it as a requirement for the next PR.

@romange romange merged commit 55963f7 into dragonflydb:Json Aug 16, 2022
romange pushed a commit that referenced this pull request Aug 26, 2022
…nds (#228)

feat(server): implement JSON.TOGGLE & JSON.ARRLEN & JSON.OBJLEN commands (#241)

Signed-off-by: iko1 <[email protected]>

Signed-off-by: iko1 <[email protected]>
romange pushed a commit that referenced this pull request Aug 26, 2022
…nds (#228)

feat(server): implement JSON.TOGGLE & JSON.ARRLEN & JSON.OBJLEN commands (#241)

Signed-off-by: iko1 <[email protected]>

Signed-off-by: iko1 <[email protected]>
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.

2 participants