Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error message for Decimals utility methods #11149

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions core/trino-spi/src/main/java/io/trino/spi/type/Decimals.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ public static long encodeShortScaledValue(BigDecimal value, int scale)

public static long encodeShortScaledValue(BigDecimal value, int scale, RoundingMode roundingMode)
{
checkArgument(scale >= 0);
if (scale < 0) {
throw new IllegalArgumentException("scale is negative: " + scale);
}
return value.setScale(scale, roundingMode).unscaledValue().longValueExact();
}

Expand All @@ -141,7 +143,9 @@ public static Int128 encodeScaledValue(BigDecimal value, int scale)

public static Int128 encodeScaledValue(BigDecimal value, int scale, RoundingMode roundingMode)
{
checkArgument(scale >= 0);
if (scale < 0) {
throw new IllegalArgumentException("scale is negative: " + scale);
}
return valueOf(value.setScale(scale, roundingMode));
}

Expand Down Expand Up @@ -265,13 +269,6 @@ public static boolean isLongDecimal(Type type)
return type instanceof LongDecimalType;
}

private static void checkArgument(boolean condition)
{
if (!condition) {
throw new IllegalArgumentException();
}
}

/**
* Converts {@link BigDecimal} to {@link Int128} representing it for long {@link DecimalType}.
* It is caller responsibility to ensure that {@code value.scale()} equals to {@link DecimalType#getScale()}.
Expand Down