diff --git a/be/src/vec/functions/function_cast.h b/be/src/vec/functions/function_cast.h index 053d44c0f4..144b782554 100644 --- a/be/src/vec/functions/function_cast.h +++ b/be/src/vec/functions/function_cast.h @@ -138,6 +138,13 @@ struct ConvertImpl { vec_to[i] = static_cast(vec_from[i]); } + // TODO: support boolean cast more reasonable + if constexpr (std::is_same_v) { + for (int i = 0; i < size; ++i) { + vec_to[i] = static_cast(vec_to[i]); + } + } + block.replace_by_position(result, std::move(col_to)); } else { return Status::RuntimeError( @@ -315,6 +322,11 @@ bool try_parse_impl(typename DataType::FieldType& x, ReadBuffer& rb, const DateL return try_read_float_text(x, rb); } + // uint8_t now use as boolean in doris + if constexpr (std::is_same_v) { + return try_read_bool_text(x, rb); + } + if constexpr (std::is_integral_v) { return try_read_int_text(x, rb); } diff --git a/be/src/vec/io/io_helper.h b/be/src/vec/io/io_helper.h index 99253c9f84..dafbed63d3 100644 --- a/be/src/vec/io/io_helper.h +++ b/be/src/vec/io/io_helper.h @@ -294,6 +294,23 @@ bool read_decimal_text_impl(T& x, ReadBuffer& buf) { return ans; } +template +bool try_read_bool_text(T& x, ReadBuffer& buf) { + if (read_int_text_impl(x, buf)) { + return x == 0 || x == 1; + } + + StringParser::ParseResult result; + x = StringParser::string_to_bool(buf.position(), buf.count(), &result); + if (UNLIKELY(result != StringParser::PARSE_SUCCESS)) { + return false; + } + + // only to match the is_all_read() check to prevent return null + buf.position() = buf.end(); + return true; +} + template bool try_read_int_text(T& x, ReadBuffer& buf) { return read_int_text_impl(x, buf);