yangzhg commented on a change in pull request #6504:
URL: https://github.com/apache/incubator-doris/pull/6504#discussion_r698921023



##########
File path: be/src/exprs/json_functions.cpp
##########
@@ -107,6 +107,89 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* 
context, const StringV
         return DoubleVal::null();
     }
 }
+StringVal JsonFunctions::json_array(FunctionContext* context, int num_args,
+                                    const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Value array_obj(rapidjson::kArrayType);
+    rapidjson::Document document;
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    //flag: The number it contains represents the type of previous parameters
+    std::string flag((char*)json_str[num_args - 1].ptr, json_str[num_args - 
1].len);
+    for (int i = 0; i < num_args - 1; ++i) {
+        std::string arg((char*)json_str[i].ptr, json_str[i].len);
+        rapidjson::Value val = parse_str_with_flag(arg, flag, i, allocator);
+        array_obj.PushBack(val, allocator);
+    }
+    rapidjson::StringBuffer buf;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
+    array_obj.Accept(writer);
+    return AnyValUtil::from_string_temp(context, std::string(buf.GetString()));
+}
+
+StringVal JsonFunctions::json_object(FunctionContext* context, int num_args,
+                                     const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Document document(rapidjson::kObjectType);
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    std::string flag((char*)json_str[num_args - 1].ptr, json_str[num_args - 
1].len);
+    document.SetObject();
+    for (int i = 1; i < num_args - 1; i = i + 2) {
+        std::string arg((char*)json_str[i].ptr, json_str[i].len);
+        rapidjson::Value key(rapidjson::kStringType);
+        key.SetString((char*)json_str[i - 1].ptr, json_str[i - 1].len, 
allocator);
+        rapidjson::Value val = parse_str_with_flag(arg, flag, i, allocator);
+        document.AddMember(key, val, allocator);
+    }
+    rapidjson::StringBuffer buf;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
+    document.Accept(writer);
+    return AnyValUtil::from_string_temp(context, std::string(buf.GetString()));
+}
+
+rapidjson::Value JsonFunctions::parse_str_with_flag(const std::string& arg, 
const std::string& flag,
+                                                    const int& num,

Review comment:
       primitive type is no need to be reference




-- 
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

Reply via email to