mshahid6 opened a new pull request, #18949:
URL: https://github.com/apache/druid/pull/18949
### Description
Some invalid queries, like:
`select SPECTATOR_PERCENTILE(null, '99.99') from "foo"`
throw
```
Error: UNCATEGORIZED (ADMIN)
class org.apache.calcite.util.NlsString cannot be cast to class
java.lang.Number (org.apache.calcite.util.NlsString is in unnamed module of
loader 'app'; java.lang.Number is in module java.base of loader 'bootstrap')
```
which causes Druid to incorrectly return 500 to the user instead of 400
(user error).
This change checks instanceof before casting RexLiteral.value() to Number in
SQL aggregators. When users pass invalid queries (e.g., a string literal
'99.99' where numeric literals are expected), `InvalidSqlInput` exception is
thrown, which returns 400 (USER/INVALID_INPUT) instead of 500
(ADMIN/UNCATEGORIZED). This improves error diagnostics for invalid queries.
##### Key changed/added classes in this PR
* `SpectatorHistogramPercentileSqlAggregator`
* `HllSketchBaseSqlAggregator`
* `DoublesSketchApproxQuantileSqlAggregator`
* `ThetaSketchBaseSqlAggregator`
* `BloomFilterSqlAggregator`
* `QuantileSqlAggregator`
* `ArrayConcatSqlAggregator`
* `ArraySqlAggregator`
* `StringSqlAggregator`
#### Release note
Improved: type validation for numeric literal parameters in SQL aggregator
functions to prevent ClassCastException and provide better error message
categorized as user error
- [ ] been self-reviewed.
- [ ] using the [concurrency
checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md)
(Remove this item if the PR doesn't have any relation to concurrency.)
- [ ] added documentation for new or modified features or behaviors.
- [x] a release note entry in the PR description.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked
related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in
[licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [ ] added comments explaining the "why" and the intent of the code
wherever would not be obvious for an unfamiliar reader.
- [x] added unit tests or modified existing tests to cover new code paths,
ensuring the threshold for [code
coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md)
is met.
- [ ] added integration tests.
- [ ] been tested in a test Druid cluster.
--
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]