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); }