Copilot commented on code in PR #37241:
URL: https://github.com/apache/shardingsphere/pull/37241#discussion_r2575706336
##########
parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/util/SQLUtils.java:
##########
@@ -66,21 +66,26 @@ public final class SQLUtils {
*/
public static Number getExactlyNumber(final String value, final int radix)
{
try {
- return getBigInteger(value, radix);
+ return getExactlyNumber(new BigInteger(value, radix));
} catch (final NumberFormatException ex) {
return new BigDecimal(value);
}
}
- private static Number getBigInteger(final String value, final int radix) {
- BigInteger result = new BigInteger(value, radix);
- if (result.compareTo(new
BigInteger(String.valueOf(Integer.MIN_VALUE))) >= 0 && result.compareTo(new
BigInteger(String.valueOf(Integer.MAX_VALUE))) <= 0) {
- return result.intValue();
+ /**
+ * Get exactly number.
+ *
+ * @param value to be converted value
+ * @return converted value
+ */
+ public static Number getExactlyNumber(final BigInteger value) {
+ if (value.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) >= 0 &&
value.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) <= 0) {
+ return value.intValue();
}
- if (result.compareTo(new BigInteger(String.valueOf(Long.MIN_VALUE)))
>= 0 && result.compareTo(new BigInteger(String.valueOf(Long.MAX_VALUE))) <= 0) {
- return result.longValue();
+ if (value.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) >= 0 &&
value.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) <= 0) {
+ return value.longValue();
}
- return result;
+ return value;
}
Review Comment:
The new public method `getExactlyNumber(BigInteger)` lacks test coverage.
Since this is a newly introduced public API method and the class has
comprehensive test coverage in `SQLUtilsTest.java`, tests should be added to
verify the behavior of this method with various BigInteger inputs (e.g., values
that fit in Integer range, Long range, and those that require BigInteger).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]