yangzhg commented on a change in pull request #6504: URL: https://github.com/apache/incubator-doris/pull/6504#discussion_r699800543
########## File path: be/src/exprs/json_functions.cpp ########## @@ -108,6 +108,96 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV } } +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); + DCHECK(num_args-1==flag.length()); Review comment: ```suggestion DCHECK_EQ(num_args - 1, flag.length()); ``` ########## File path: be/src/exprs/json_functions.cpp ########## @@ -108,6 +108,96 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV } } +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); + DCHECK(num_args-1==flag.length()); + 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); Review comment: use stringVal ########## File path: be/src/exprs/json_functions.cpp ########## @@ -108,6 +109,96 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV } } +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 + StringVal flag(json_str[num_args - 1].ptr, json_str[num_args - 1].len); Review comment: ```suggestion StringVal* flag = json_str[num_args - 1]; ``` ########## File path: be/src/exprs/json_functions.cpp ########## @@ -108,6 +109,96 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV } } +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 + StringVal flag(json_str[num_args - 1].ptr, json_str[num_args - 1].len); + DCHECK_EQ(num_args - 1, flag.len); + for (int i = 0; i < num_args - 1; ++i) { + StringVal arg(json_str[i].ptr, json_str[i].len); + rapidjson::Value val = parse_str_with_flag(arg, flag, i, allocator); Review comment: ```suggestion rapidjson::Value val = parse_str_with_flag(arg, *flag, i, allocator); ``` -- 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