You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "taptao (via GitHub)" <gi...@apache.org> on 2023/08/15 12:18:36 UTC
[GitHub] [doris] taptao commented on a diff in pull request #22911: [feature](json-function):Add json_merge_preserve
taptao commented on code in PR #22911:
URL: https://github.com/apache/doris/pull/22911#discussion_r1294521967
##########
regression-test/suites/query_p0/sql_functions/json_functions/test_json_function.groovy:
##########
@@ -83,4 +83,14 @@ suite("test_json_function") {
qt_sql "SELECT JSON_CONTAINS('{\"name\": \"John\", \"age\": 30, \"projects\": [{\"name\": \"Project A\", \"year\": 2020}, {\"name\": \"Project B\", \"year\": 2021}]}', '{\"projects\": [{\"name\": \"Project A\"}]}', '\$.');"
qt_sql "SELECT JSON_CONTAINS('{\"name\": \"John\", \"age\": 30, \"address\": {\"city\": \"New York\", \"country\": \"USA\"}}', '{\"address\": {\"city\": \"New York\"}}', '\$.');"
+ qt_sql "SELECT JSON_MERGE_PRESERVE('[]','[]');"
Review Comment:
done
##########
be/src/vec/functions/function_json.cpp:
##########
@@ -936,6 +937,186 @@ class FunctionJsonValid : public IFunction {
}
};
+class FunctionJsonMergePreserve : public IFunction {
+public:
+ static constexpr auto name = "json_merge_preserve";
+ static FunctionPtr create() { return std::make_shared<FunctionJsonMergePreserve>(); }
+
+ String get_name() const override { return name; }
+
+ size_t get_number_of_arguments() const override { return 0; }
+
+ bool is_variadic() const override { return true; }
+
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
+ return make_nullable(std::make_shared<DataTypeString>());
+ }
+
+ bool use_default_implementation_for_nulls() const override { return false; }
+
+ rapidjson::Value* merge_list(std::vector<rapidjson::Value*> jsons,
+ rapidjson::Document::AllocatorType& allocator) {
+ rapidjson::Value* result =
+ static_cast<rapidjson::Value*>(allocator.Malloc(sizeof(rapidjson::Value)));
+
+ (*result).SetArray();
+ for (auto json : jsons) {
+ if (json->IsArray()) {
+ for (auto itr = json->Begin(); itr != json->End(); itr++) {
+ rapidjson::Value* node = static_cast<rapidjson::Value*>(
+ allocator.Malloc(sizeof(rapidjson::Value)));
+ node->CopyFrom(*itr, allocator);
+ result->PushBack(*node, allocator);
+ }
+ } else {
+ rapidjson::Value* node =
+ static_cast<rapidjson::Value*>(allocator.Malloc(sizeof(rapidjson::Value)));
+ node->CopyFrom(*json, allocator);
+ result->PushBack(*node, allocator);
+ }
+ }
+ return result;
+ }
+
+ rapidjson::Value* merge_obejcts(std::vector<rapidjson::Value*> objs,
Review Comment:
done
--
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-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org