-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(json): JSON.DEL recursive descent duplicate counting for nested same-key elements #5312
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
Conversation
@@ -1261,6 +1261,24 @@ TEST_F(JsonFamilyTest, Del) { | |||
|
|||
resp = Run({"JSON.GET", "json"}); | |||
EXPECT_THAT(resp, ArgType(RespExpr::NIL)); | |||
|
|||
if (absl::GetFlag(FLAGS_jsonpathv2)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please add a test in jsonpath_test.cc as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unit test was added to jsonpath_test.cc
src/core/json/detail/jsoncons_dfs.cc
Outdated
stack.emplace_back(json); | ||
|
||
// Collect nodes to delete - but simplified without complex filtering | ||
std::vector<JsonType*> nodes_to_delete; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need nodes_to_delete
? what exactly breaks if you delete during the traversal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/core/json/detail/jsoncons_dfs.cc
Outdated
} while (!stack.empty()); | ||
|
||
// Apply deletions with filtering for recursive descent to avoid parent-child duplication | ||
const PathSegment& terminal_segment = path.back(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we delete immediately without nodes_to_delete
, we won't need all this code below, since if we delete parent first, we won't traverse its children.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it seems, you are exactly right.
Fixes: #5259
Issue:
JSON.DEL doc "$..a"
was returning 2 instead of 1 when deleting nested objects with the same key name, because both parent and child deletions were counted separately.Solution:
Added filtering logic to avoid counting child nodes that are automatically deleted when their parent is removed. Only applies to recursive descent deletion operations where one object directly contains another with the same target key.
Testing:
poetry run pytest -s test/test_json/test_json.py -k test_json_delete_with_dollar