From d16ea4efc909ee5a5b26aae544153a5073716cba Mon Sep 17 00:00:00 2001 From: Yan Ma Date: Mon, 27 Nov 2023 17:00:33 +0800 Subject: [PATCH] fix UT castDecimalToDecimal and varcharToDecimal (#449) --- velox/type/DecimalUtil.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/velox/type/DecimalUtil.h b/velox/type/DecimalUtil.h index 7c6b80b9df35..b7dc97e78d08 100644 --- a/velox/type/DecimalUtil.h +++ b/velox/type/DecimalUtil.h @@ -175,7 +175,17 @@ class DecimalUtil { } // Check overflow. if (!valueInPrecisionRange(rescaledValue, toPrecision) || isOverflow) { - return std::nullopt; + if (throwIfOverflow) { + VELOX_USER_FAIL( + "Cannot cast DECIMAL '{}' to DECIMAL({}, {})", + DecimalUtil::toString( + inputValue, DECIMAL(fromPrecision, fromScale)), + toPrecision, + toScale); + } else { + isOverflow = true; + return std::nullopt; + } } return static_cast(rescaledValue); }