github-actions[bot] commented on code in PR #24801:
URL: https://github.com/apache/doris/pull/24801#discussion_r1334204192
##########
be/src/util/jsonb_document.h:
##########
@@ -1264,6 +1267,56 @@
}
}
+inline int JsonbValue::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;
+
+ JsonbKeyValue* first_key = ((ObjectVal*)this)->getJsonbKeyValue(0);
+ JsonbValue* first_value =
+ ((ObjectVal*)this)->find(first_key->getKeyStr(),
first_key->klen());
+ int max_depth = depth + first_value->depth();
+
+ for (int i = 1; i < numElem; ++i) {
+ JsonbKeyValue* key = ((ObjectVal*)this)->getJsonbKeyValue(i);
+ JsonbValue* value = ((ObjectVal*)this)->find(key->getKeyStr(),
key->klen());
+ int current_depth = depth + value->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;
Review Comment:
warning: statement should be inside braces
[readability-braces-around-statements]
```suggestion
if (numElem == 0) { return depth;
}
```
##########
be/src/util/jsonb_document.h:
##########
@@ -1264,6 +1267,56 @@
}
}
+inline int JsonbValue::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;
+
+ JsonbKeyValue* first_key = ((ObjectVal*)this)->getJsonbKeyValue(0);
+ JsonbValue* first_value =
+ ((ObjectVal*)this)->find(first_key->getKeyStr(),
first_key->klen());
+ int max_depth = depth + first_value->depth();
+
+ for (int i = 1; i < numElem; ++i) {
+ JsonbKeyValue* key = ((ObjectVal*)this)->getJsonbKeyValue(i);
+ JsonbValue* value = ((ObjectVal*)this)->find(key->getKeyStr(),
key->klen());
+ int current_depth = depth + value->depth();
+ if (current_depth > max_depth) max_depth = current_depth;
Review Comment:
warning: statement should be inside braces
[readability-braces-around-statements]
```suggestion
if (current_depth > max_depth) { max_depth = current_depth;
}
```
##########
be/src/util/jsonb_document.h:
##########
@@ -1264,6 +1267,56 @@
}
}
+inline int JsonbValue::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;
Review Comment:
warning: statement should be inside braces
[readability-braces-around-statements]
```suggestion
if (numElem == 0) { return depth;
}
```
##########
be/src/util/jsonb_document.h:
##########
@@ -549,6 +549,9 @@ class JsonbValue {
//Get the number of jsonbvalue elements
int length() const;
+ //Get the depth of jsonbvalue
+ int depth() const;
Review Comment:
warning: function 'depth' should be marked [[nodiscard]]
[modernize-use-nodiscard]
```suggestion
[[nodiscard]] int depth() const;
```
##########
be/src/vec/functions/function_jsonb.cpp:
##########
@@ -1264,6 +1264,56 @@ struct JsonbContainsAndPathImpl {
}
};
+class FunctionJsonbDepth : public IFunction {
+public:
+ static constexpr auto name = "json_depth";
+ String get_name() const override { return name; }
Review Comment:
warning: function 'get_name' should be marked [[nodiscard]]
[modernize-use-nodiscard]
```suggestion
[[nodiscard]] String get_name() const override { return name; }
```
##########
be/src/util/jsonb_document.h:
##########
@@ -1264,6 +1267,56 @@
}
}
+inline int JsonbValue::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;
+
+ JsonbKeyValue* first_key = ((ObjectVal*)this)->getJsonbKeyValue(0);
+ JsonbValue* first_value =
+ ((ObjectVal*)this)->find(first_key->getKeyStr(),
first_key->klen());
+ int max_depth = depth + first_value->depth();
+
+ for (int i = 1; i < numElem; ++i) {
+ JsonbKeyValue* key = ((ObjectVal*)this)->getJsonbKeyValue(i);
+ JsonbValue* value = ((ObjectVal*)this)->find(key->getKeyStr(),
key->klen());
+ int current_depth = depth + value->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)->depth();
+ for (int i = 1; i < numElem; ++i) {
+ int current_depth = depth + ((ArrayVal*)this)->get(i)->depth();
+ if (current_depth > max_depth) max_depth = current_depth;
Review Comment:
warning: statement should be inside braces
[readability-braces-around-statements]
```suggestion
if (current_depth > max_depth) { max_depth = current_depth;
}
```
##########
be/src/vec/functions/function_jsonb.cpp:
##########
@@ -1264,6 +1264,56 @@
}
};
+class FunctionJsonbDepth : public IFunction {
+public:
+ static constexpr auto name = "json_depth";
+ String get_name() const override { return name; }
+ static FunctionPtr create() { return
std::make_shared<FunctionJsonbDepth>(); }
+
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const
override {
Review Comment:
warning: function 'get_return_type_impl' should be marked [[nodiscard]]
[modernize-use-nodiscard]
```suggestion
[[nodiscard]] DataTypePtr get_return_type_impl(const DataTypes&
arguments) const override {
```
##########
be/src/vec/functions/function_jsonb.cpp:
##########
@@ -1264,6 +1264,56 @@
}
};
+class FunctionJsonbDepth : public IFunction {
+public:
+ static constexpr auto name = "json_depth";
+ String get_name() const override { return name; }
+ static FunctionPtr create() { return
std::make_shared<FunctionJsonbDepth>(); }
+
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const
override {
+ return make_nullable(std::make_shared<DataTypeInt32>());
+ }
+
+ size_t get_number_of_arguments() const override { return 1; }
+
+ bool use_default_implementation_for_nulls() const override { return false;
}
+
+ Status execute_impl(FunctionContext* context, Block& block, const
ColumnNumbers& arguments,
+ size_t result, size_t input_rows_count) override {
+ DCHECK_GE(arguments.size(), 1);
+ auto jsonb_data_column = block.get_by_position(arguments[0]).column;
+
+ auto null_map = ColumnUInt8::create(input_rows_count, 0);
+ auto return_type = block.get_data_type(result);
+ MutableColumnPtr res = return_type->create_column();
Review Comment:
warning: variable 'res' is not initialized [cppcoreguidelines-init-variables]
```suggestion
MutableColumnPtr res = 0 = return_type->create_column();
```
##########
be/src/vec/functions/function_jsonb.cpp:
##########
@@ -1264,6 +1264,56 @@
}
};
+class FunctionJsonbDepth : public IFunction {
+public:
+ static constexpr auto name = "json_depth";
+ String get_name() const override { return name; }
+ static FunctionPtr create() { return
std::make_shared<FunctionJsonbDepth>(); }
+
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const
override {
+ return make_nullable(std::make_shared<DataTypeInt32>());
+ }
+
+ size_t get_number_of_arguments() const override { return 1; }
Review Comment:
warning: function 'get_number_of_arguments' should be marked [[nodiscard]]
[modernize-use-nodiscard]
```suggestion
[[nodiscard]] size_t get_number_of_arguments() const override { return
1; }
```
##########
be/src/vec/functions/function_jsonb.cpp:
##########
@@ -1264,6 +1264,56 @@
}
};
+class FunctionJsonbDepth : public IFunction {
+public:
+ static constexpr auto name = "json_depth";
+ String get_name() const override { return name; }
+ static FunctionPtr create() { return
std::make_shared<FunctionJsonbDepth>(); }
+
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const
override {
+ return make_nullable(std::make_shared<DataTypeInt32>());
+ }
+
+ size_t get_number_of_arguments() const override { return 1; }
+
+ bool use_default_implementation_for_nulls() const override { return false;
}
Review Comment:
warning: function 'use_default_implementation_for_nulls' should be marked
[[nodiscard]] [modernize-use-nodiscard]
```suggestion
[[nodiscard]] bool use_default_implementation_for_nulls() const override
{ return false; }
```
--
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]