Skip to content

added generic json path implementation - #336

Merged
MeirShpilraien merged 60 commits into
masterfrom
generic_json_path_impl
Jul 4, 2021
Merged

MeirShpilraien merged 60 commits into
masterfrom
generic_json_path_impl

Conversation

@MeirShpilraien

Copy link
Copy Markdown

No description provided.

gavrie
gavrie previously requested changes May 3, 2021
Comment thread src/select/cmp.rs Resolved
Comment thread src/redisjson.rs Resolved
Comment thread src/lib.rs Resolved
Comment thread src/json_node.rs Resolved
Comment thread Cargo.toml Resolved
Comment thread src/select/expr_term.rs Resolved
Comment thread src/json_node.rs Resolved
Comment thread src/json_node.rs Resolved
Comment thread src/json_node.rs Resolved
Comment thread src/json_node.rs Resolved
@MeirShpilraien
MeirShpilraien force-pushed the generic_json_path_impl branch from 065c086 to 1c5f86f Compare May 25, 2021 17:10
Comment thread src/manager.rs Resolved
Comment thread src/commands.rs Resolved
Comment thread src/commands.rs
if paths.len() > 0 {
let mut res = None;
for p in paths {
res = Some(redis_key.str_append(p, json.clone())?);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • Will not report on paths leading to non-String values (different behavior than before)

  • Might modify only a sub-set of paths and fail in the middle - not "atomic" (to be addressed by another PR?)

  • Only reporting the first encountered error (using the ? operator)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

  • Yes but we need to decide this behavior, I believe we can decide it when redefine the API on 2.0
  • Looking at the API it can happened but looking at the impl it can not, again we should give an api that can expose such errors
  • Yes but again this is an api limitation

Comment thread src/manager.rs
fn set_root(&mut self, v: Option<Value>) -> Result<(), RedisError> {
match v {
Some(inner) => {
let v = self.key.get_value::<RedisJSON>(&REDIS_JSON_TYPE)?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Calling get_value could be redundant here, such as when coming from command_json_set calling WriteHolder::set_value calling set_root, where the value was already obtained before in command_json_set by
let current = redis_key.get_value()?;

Comment thread src/commands.rs
if path == JSON_ROOT_PATH {
if *op != SetOptions::NotExists {
redis_key.set_value(Vec::new(), val)?;
redis_key.apply_changes(ctx, "json.set")?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should apply_changes be called only when the return value from redis_key.set_value is Ok(true)?
(although currently it seems to be possible to get only Ok(false) or Err)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Well, its updating the root so it can not failed (return false). We can assert it, WDYT?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There are more calls to apply_changes, some consider the result of the "write" operation (set_value, del, etc.),
But some don't, or only consider the last result of a for iteration, such as in command_json_num_op , command_json_bool_toggle , command_json_str_append , command_json_arr_append , command_json_arr_insert , command_json_arr_trim , command_json_clear
However, this is also related to atomicity and the behavior needs to be decided as commented here
(also for command_json_arr_pop)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, the assumption is that the last result should be the same as the first result. but I agree this all story need to be handled together with the API changed

Comment thread src/manager.rs Resolved
Comment thread src/manager.rs Resolved

@oshadmi oshadmi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

More questions...😊

Comment thread src/commands.rs Resolved
Comment thread src/commands.rs
}
}
if SetOptions::AlreadyExists != *option {
self.find_add_paths(path)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If option is NotExists we will reach here - may find_add_paths find and return an existing value?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes this only gives you what need to be done, but the WriteHolder implementation will not let you set an existing value in a dictionary so it will be catch after.

oshadmi
oshadmi previously approved these changes Jun 30, 2021

@oshadmi oshadmi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👏🏼 Amazing job ❗

@gkorland
gkorland requested review from gavrie and oshadmi July 4, 2021 07:24
oshadmi
oshadmi previously approved these changes Jul 4, 2021
@MeirShpilraien
MeirShpilraien dismissed gavrie’s stale review July 4, 2021 08:01

All comments was fixed, I do not know why github still not allow merge.

@MeirShpilraien
MeirShpilraien merged commit 5cf6b36 into master Jul 4, 2021
@MeirShpilraien
MeirShpilraien deleted the generic_json_path_impl branch July 4, 2021 08:01
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.

4 participants