From 87f1191995d1243a9cacdc9ad1c5dd3b0ba49561 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/be/src/vec/functions/function_cast.h b/be/src/vec/functions/function_cast.h index 79762af86ce008..7b28d883307cdd 100644 --- a/be/src/vec/functions/function_cast.h +++ b/be/src/vec/functions/function_cast.h @@ -432,6 +432,15 @@ 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::RuntimeError("{}({}) out of range", col_to->get_name(), + vec_from[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]);