Skip to content

Add JSON.CLEAR command - #306

Merged
oshadmi merged 9 commits into
masterfrom
omer_add_json_clear
May 3, 2021
Merged

oshadmi merged 9 commits into
masterfrom
omer_add_json_clear

Conversation

@oshadmi

@oshadmi oshadmi commented Apr 19, 2021

Copy link
Copy Markdown
Collaborator

Currently only handling the first path argument

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

oshadmi commented Apr 19, 2021

Copy link
Copy Markdown
Collaborator Author

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

oshadmi commented Apr 20, 2021

Copy link
Copy Markdown
Collaborator Author

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

Comment thread 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?)

Comment thread src/lib.rs Resolved
Comment thread src/redisjson.rs Resolved
Comment thread src/lib.rs Resolved
@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