Skip to content

Add JSON.CLEAR command #306

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

Merged
merged 9 commits into from
May 3, 2021
Merged

Add JSON.CLEAR command #306

merged 9 commits into from
May 3, 2021

Conversation

oshadmi
Copy link
Collaborator

@oshadmi oshadmi commented Apr 19, 2021

Currently only handling the first path argument

@oshadmi oshadmi requested review from gkorland, rafie and gavrie April 19, 2021 20:22
@oshadmi
Copy link
Collaborator Author

oshadmi commented Apr 19, 2021

test:testClear - has tests for when multi-paths are handled - currently only the first is handled.
❌ (FAIL): '42' == [42, 44, {'a': 1, 'b': 2}, ['to', 'be', 'cleared', 4]] test.py:413
❌ (FAIL): '42' == [42, 44, {}, []] test.py:435
test:testSetInvalidPathShouldFail - also fails without this PR. Will need to be reviewed later.

@oshadmi
Copy link
Collaborator Author

oshadmi commented Apr 20, 2021

test:testSetInvalidPathShouldFail - it turns out this test does not fails on master. Reviewing it.

src/lib.rs Outdated
let mut paths: Vec<Path> = vec![];
let path = backwards_compat_path(arg);
paths.push(Path::new(path));
while let Ok(mut arg) = args.next_string() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@oshadmi why do you need multi paths support? with the support of full JSONPath I don't see the need.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@gkorland Do you mean that since multi paths could be expressed using a single JSONPath with wildcard, union iterator, recursive descent or slices?
It could still be useful to allow specifying several paths, either when they are plain/explicit, or when a complex path, with wildcards, etc., might yield unwanted paths, e.g., $..attr is too "permissive" when user only wants 2 specific paths out of many others, so $.sub1.attr and $.sub2.attr could be easily specified, while finding the exact single complex path could be harder.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes single "path" can be a union of multi paths.
And it's consistent with: JSON.DEL <key> [path]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@gkorland
The current doc specifies one or more path args only for JSON.GET (using three dots)

JSON.GET <key>
         [INDENT indentation-string]
         [NEWLINE line-break-string]
         [SPACE space-string]
         [NOESCAPE]
         [path ...]

But for JSON.DEL only a single path is specified:
JSON.DEL <key> [path]

For JSON.CLEAR we aimed to eventually support multi-paths, right?
So it would eventually be documented with three dots as:
JSON.CLEAR <key> [path ...]
With the return value being the number of paths cleared, similar to JSON.DEL.

Additional question (also related to single path which could use wildcards, union iterator, etc. to match several elements):
What should be done if one or more paths do not exist or do not resolve to an array or an object:

  1. Should the command be atomic, and avoid doing just part of the job? Should it then return the error messages reporting
    the wrong paths, or just do nothing or return nil?
    Or
  2. Should the command report on erroneous path and resume with the rest of the paths, clearing only existing and matching arrays/objects and skipping the rest? (if the command is not atomic, the return value would be an array of numbers and/or error messages?)

@oshadmi oshadmi requested a review from gavrie April 29, 2021 21:56
@oshadmi oshadmi merged commit ac32737 into master May 3, 2021
@oshadmi oshadmi deleted the omer_add_json_clear branch May 3, 2021 16:13
oshadmi added a commit that referenced this pull request May 5, 2021
* Update to Redis 6.2.2 (#332)

* Fix json.arrappend performance (#324)

* improve arr_pop, arr_insert & arr_trim performance 
* refactor do_json_* functions

* normalize index for backward (#327)

* normalize index for backward
* adpat for full backward with 1.0.x

* fix #318 (#333)

* CircleCI: macOS and benchmark fixes (#337)

* Update config.yml (#338)

* Add JSON.CLEAR command (#306)

* Restore optional path (default is $) for JSON.DEL

* Add JSON.CLEAR

* Handle JSON.CLEAR with $ path

* Add JSON.CLEAR - Fix failure in test:testSetInvalidPathShouldFail

* Idiomatic fixes per Gavrie review

Co-authored-by: Guy Korland <gkorland@gmail.com>

* Update RS_VERSIONS

last promoted builds

* Document flags for running tests

* fix arr_pop backward to 1.0 (#345)

* JSON.INSERTARR backward compatability for 1.0 (#343)

* Fix JSON.INSERTARR backward compatibility with 1.0.x
* Update test.py

* Fix build error
(use of undeclared crate or module `rawmod`)

* Fix format

Co-authored-by: Guy Korland <gkorland@gmail.com>
Co-authored-by: Omer Shadmi <76992134+oshadmi@users.noreply.github.com>
Co-authored-by: tomerhekredis <72793005+tomerhekredis@users.noreply.github.com>
Co-authored-by: Gavrie Philipson <gavrie@philipson.co.il>
Co-authored-by: oshadmi <omer.shadmi@redislabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants