morningman commented on a change in pull request #3345: [FIX] fix doris string functions not support multibyte string URL: https://github.com/apache/incubator-doris/pull/3345#discussion_r410261854
########## File path: be/src/exprs/string_functions.cpp ########## @@ -37,19 +37,55 @@ void StringFunctions::init() { // - supported negative positions (count from the end of the string) // - [optional] len. No len indicates longest substr possible StringVal StringFunctions::substring( - FunctionContext* context, const StringVal& str, + FunctionContext* context, const StringVal& str, const IntVal& pos, const IntVal& len) { if (str.is_null || pos.is_null || len.is_null) { return StringVal::null(); } + if (len.val <= 0 || str.len == 0) { + return StringVal(); + } + + // create index indicate every char start byte + // e.g. "hello word 你好" => [0,1,2,3,4,5,6,7,8,9,10,11,14] 你 and 好 are 3 bytes + // why use a vector as index? if theres is no negative pos val it is unnecessary, + // but if has pos is negative it is not easy to determin where to start, so need a + // index save ervery charactor's length Review comment: ```suggestion // index save every character's length ``` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org