xiaokang commented on code in PR #24801: URL: https://github.com/apache/doris/pull/24801#discussion_r1566588603
########## be/src/util/jsonb_document.h: ########## @@ -1269,6 +1272,53 @@ inline int JsonbValue::length() const { } } +inline int JsonbValue::base_depth() const { + switch (type_) { + case JsonbType::T_Int8: + case JsonbType::T_Int16: + case JsonbType::T_Int32: + case JsonbType::T_Int64: + case JsonbType::T_Double: + case JsonbType::T_Float: + case JsonbType::T_Int128: + case JsonbType::T_String: + case JsonbType::T_Binary: + case JsonbType::T_Null: + case JsonbType::T_True: + case JsonbType::T_False: { + return 1; + } + case JsonbType::T_Object: { + int depth = 1; + int numElem = ((ObjectVal*)this)->numElem(); + if (numElem == 0) return depth; + + int max_depth = depth; + + for (int i = 0; i < numElem; ++i) { + JsonbKeyValue* key = ((ObjectVal*)this)->getJsonbKeyValue(i); + JsonbValue* value = ((ObjectVal*)this)->find(key->getKeyStr(), key->klen()); + int current_depth = depth + value->base_depth(); + if (current_depth > max_depth) max_depth = current_depth; + } + return max_depth; + } + case JsonbType::T_Array: { + int depth = 1; + int numElem = ((ArrayVal*)this)->numElem(); + if (numElem == 0) return depth; + int max_depth = depth + ((ArrayVal*)this)->get(0)->base_depth(); Review Comment: change as object, do not need special code for item 0 -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org