FrankChen021 commented on code in PR #20629:
URL: https://github.com/apache/druid/pull/20629#discussion_r4324965893
##########
processing/src/main/java/org/apache/druid/query/context/QueryContextParameter.java:
##########
@@ -338,16 +339,36 @@ static <T> T exactNumber(
{
final String expectedFormat = "in " + typeName + " format";
final BigDecimal decimal;
- try {
- if (value instanceof BigDecimal) {
- decimal = (BigDecimal) value;
- } else if (value instanceof Number || value instanceof String) {
+ if (value instanceof BigDecimal) {
+ decimal = (BigDecimal) value;
+ } else if (value instanceof Number) {
+ try {
decimal = new BigDecimal(value.toString());
- } else {
+ }
+ catch (NumberFormatException e) {
+ // Such as NaN or infinity
throw QueryContextParameters.invalidValueException(name,
expectedFormat, value);
}
- }
- catch (NumberFormatException e) {
+ } else if (value instanceof String) {
+ // A plain number, or a human-readable number with a unit suffix, such
as 10K or 256MiB
+ BigDecimal parsed;
+ try {
+ parsed = new BigDecimal((String) value);
+ }
+ catch (NumberFormatException e) {
+ try {
+ parsed = BigDecimal.valueOf(HumanReadableBytes.parse((String) value,
true));
Review Comment:
[P2] Reject unsupported negative maxParseExceptions values
**Finding:** The shared human-readable fallback accepts values such as -2K
for maxParseExceptions, whose descriptor has no constraint. MSQ later rejects
the resulting negative value because only -1 or nonnegative counts are valid.
**Suggestion:** Add a descriptor-specific constraint allowing exactly -1 or
nonnegative values, with a regression test.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]