diff --git a/be/src/util/jsonb_document.h b/be/src/util/jsonb_document.h index b0a725e3819d66c..368088230359d2b 100644 --- a/be/src/util/jsonb_document.h +++ b/be/src/util/jsonb_document.h @@ -555,7 +555,7 @@ class JsonbValue { int length() const; //Get the depth of jsonbvalue - int base_depth() const; + int depth() const; //Whether to include the jsonbvalue rhs bool contains(JsonbValue* rhs) const; @@ -1272,7 +1272,7 @@ inline int JsonbValue::length() const { } } -inline int JsonbValue::base_depth() const { +inline int JsonbValue::depth() const { switch (type_) { case JsonbType::T_Int8: case JsonbType::T_Int16: @@ -1289,27 +1289,27 @@ inline int JsonbValue::base_depth() const { return 1; } case JsonbType::T_Object: { - int depth = 1; + int base_depth = 1; int numElem = ((ObjectVal*)this)->numElem(); - if (numElem == 0) return depth; + if (numElem == 0) return base_depth; - int max_depth = depth; + int max_depth = base_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(); + int current_depth = base_depth + value->depth(); if (current_depth > max_depth) max_depth = current_depth; } return max_depth; } case JsonbType::T_Array: { - int depth = 1; + int base_depth = 1; int numElem = ((ArrayVal*)this)->numElem(); - if (numElem == 0) return depth; - int max_depth = depth + ((ArrayVal*)this)->get(0)->base_depth(); - for (int i = 1; i < numElem; ++i) { - int current_depth = depth + ((ArrayVal*)this)->get(i)->base_depth(); + if (numElem == 0) return base_depth; + int max_depth = base_depth; + for (int i = 0; i < numElem; ++i) { + int current_depth = base_depth + ((ArrayVal*)this)->get(i)->depth(); if (current_depth > max_depth) max_depth = current_depth; } return max_depth; diff --git a/be/src/vec/functions/function_jsonb.cpp b/be/src/vec/functions/function_jsonb.cpp index ff7cfac09401acf..9a1716136b0700f 100644 --- a/be/src/vec/functions/function_jsonb.cpp +++ b/be/src/vec/functions/function_jsonb.cpp @@ -1329,8 +1329,7 @@ class FunctionJsonbDepth : public IFunction { res_data[i] = 0; continue; } - auto depth = value->base_depth(); - res_data[i] = depth; + res_data[i] = value->depth(); } block.replace_by_position(