github-actions[bot] commented on code in PR #69170:
URL: https://github.com/apache/doris/pull/69170#discussion_r4291217250


##########
be/src/util/jsonb_document.h:
##########
@@ -1751,8 +1783,10 @@ inline bool JsonbPath::parse_member(Stream* stream, 
JsonbPath* path) {
         stream->add_leg_len();
     }
 
+    // An empty member name is only valid when it is written explicitly as 
`""`.
     if ((left_quotation_marks != nullptr && right_quotation_marks == nullptr) 
||
-        stream->get_leg_ptr() == nullptr || stream->get_leg_len() == 0) {
+        stream->get_leg_ptr() == nullptr ||
+        (left_quotation_marks == nullptr && stream->get_leg_len() == 0)) {

Review Comment:
   [P2] Consume identity array legs when modifying empty-key paths. Accepting 
empty members makes `JSON_SET('{"":{"x":1},"b":1}', '$.""[0].x', 2)` valid, but 
it produces `{"":2,"b":1}` instead of `{"":{"x":2},"b":1}`; JSON_REPLACE has 
the same behavior. `findValue` correctly treats `[0]` on the object as an 
identity step, while `build_parents_by_path` returns immediately when that step 
returns its input and never traverses `.x`. Reconstruction then replaces the 
whole empty-key object. Advance the path cursor through identity legs instead 
of terminating parent discovery, and cover this newly accepted path in the 
modify tests.



##########
be/src/util/jsonb_document.cpp:
##########
@@ -100,8 +100,7 @@ JsonbFindResult JsonbValue::findValue(JsonbPath& path) 
const {
             switch (path.get_leg_from_leg_vector(i)->type) {
             case MEMBER_CODE: {
                 if (LIKELY(pval->type == JsonbType::T_Object)) {
-                    if (path.get_leg_from_leg_vector(i)->leg_len == 1 &&
-                        *path.get_leg_from_leg_vector(i)->leg_ptr == WILDCARD) 
{
+                    if (path.get_leg_from_leg_vector(i)->is_wildcard) {

Review Comment:
   [P2] Preserve trailing siblings when inserting below literal keys. Once a 
quoted `*` resolves literally, `JSON_SET('{"*":{},"b":1}', '$."*".x', 2)` 
reaches nested insertion and produces `{"*":{"x":2}}`, losing `b`; JSON_INSERT 
and an empty-key parent have the same problem. In `write_json_value`, the 
redundant `writeStartObject` in the missing-member branch fails, but its 
matching end and the outer end close both child and root; subsequent sibling 
writes fail silently. The new nested-insert test places the literal parent 
last, hiding this. Fix the writer balance and add a case with siblings after 
the literal parent before enabling these paths.



##########
be/src/util/jsonb_document.h:
##########
@@ -979,7 +991,8 @@ struct ObjectVal : public ContainerVal {
     }
 
     const_iterator search(const char* key, unsigned int klen) const {
-        if (!key || !klen) {
+        // An empty key is a valid object key, so klen == 0 is still searched.
+        if (!key) {

Review Comment:
   [P2] Apply resolved selectors when removing through empty keys. Empty-name 
lookup now enables paths such as `JSON_REMOVE('{"":{"x":1},"b":1}', 
'$.""[0].x')`, but the call leaves `x` untouched even though `findValue` 
locates it. `clone_object_without_path` copies the object when the next leg is 
ARRAY_CODE instead of consuming the non-array `[0]` identity. Likewise 
`JSON_REMOVE('{"":[1,2]}', '$.""[last]')` leaves both elements because 
`clone_array_without_path` compares the encoded -1 directly with nonnegative 
indices. Normalize these selectors consistently with lookup before cloning, and 
add empty-parent removal tests; these paths were previously rejected by the 
parser.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to