chaoyli commented on a change in pull request #3898: URL: https://github.com/apache/incubator-doris/pull/3898#discussion_r442097496
########## File path: be/src/olap/utils.cpp ########## @@ -1264,6 +1265,15 @@ bool valid_datetime(const string &value_str) { } } +bool valid_bool(const std::string& value_str) { + if (value_str == "0" || value_str == "1") { + return true; + } + StringParser::ParseResult result; + StringParser::string_to_bool(value_str.c_str(), value_str.length(), &result); Review comment: I found string_to_bool will convert "Truetest" to be true, it is ok? ``` 543 inline bool StringParser::string_to_bool_internal(const char* s, int len, ParseResult* result) { 544 *result = PARSE_SUCCESS; 545 546 if (len >= 4 && (s[0] == 't' || s[0] == 'T')) { 547 bool match = (s[1] == 'r' || s[1] == 'R') && 548 (s[2] == 'u' || s[2] == 'U') && 549 (s[3] == 'e' || s[3] == 'E'); 550 if (match && LIKELY(is_all_whitespace(s + 4, len - 4))) { 551 return true; 552 } 553 } else if (len >= 5 && (s[0] == 'f' || s[0] == 'F')) { 554 bool match = (s[1] == 'a' || s[1] == 'A') && 555 (s[2] == 'l' || s[2] == 'L') && 556 (s[3] == 's' || s[3] == 'S') && 557 (s[4] == 'e' || s[4] == 'E'); 558 if (match && LIKELY(is_all_whitespace(s + 5, len - 5))){ 559 return false; 560 } 561 } ``` ########## File path: be/src/exprs/cast_functions.cpp ########## @@ -229,6 +229,17 @@ StringVal CastFunctions::cast_to_string_val(FunctionContext* ctx, const StringVa return sv; } +BooleanVal CastFunctions::cast_to_boolean_val(FunctionContext* ctx, const StringVal& val) { + if (val.is_null) return BooleanVal::null(); + StringParser::ParseResult result; + BooleanVal ret; + ret.val = StringParser::string_to_bool(reinterpret_cast<char*>(val.ptr), val.len, &result); + if (UNLIKELY(result != StringParser::PARSE_SUCCESS || std::isnan(ret.val) || std::isinf(ret.val))) { + return BooleanVal::null(); + } Review comment: Brackets is not aligned. ---------------------------------------------------------------- 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 --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org