Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonLiTree committed Apr 17, 2024
1 parent 0f44252 commit aec50d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
22 changes: 11 additions & 11 deletions be/src/util/jsonb_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions be/src/vec/functions/function_jsonb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit aec50d9

Please sign in to comment.