From a9e42da9cf797c3541534f3d546c48400617c3be Mon Sep 17 00:00:00 2001 From: Kaijie Chen Date: Tue, 12 Mar 2024 16:40:33 +0800 Subject: [PATCH] [fix](cast) return error when numerical cast out-of-range --- be/src/vec/functions/function_cast.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/be/src/vec/functions/function_cast.h b/be/src/vec/functions/function_cast.h index 79762af86ce0088..b03f2596940b5e1 100644 --- a/be/src/vec/functions/function_cast.h +++ b/be/src/vec/functions/function_cast.h @@ -432,6 +432,16 @@ struct ConvertImpl { block.get_by_position(result).column = ColumnNullable::create(std::move(col_to), std::move(col_null_map_to)); return Status::OK(); + } else if constexpr (IsDataTypeNumber && + IsDataTypeNumber) { + for (size_t i = 0; i < size; ++i) { + if (vec_from[i] < min_result || vec_from[i] > max_result) { + return Status::InternalError( + "Out of range value for column '{}' at row {}", + col_to->get_name(), i); + } + vec_to[i] = static_cast(vec_from[i]); + } } else { for (size_t i = 0; i < size; ++i) { vec_to[i] = static_cast(vec_from[i]);