FrankChen021 opened a new pull request, #20830:
URL: https://github.com/apache/druid/pull/20830
### Description
#19775 made `QueryResource` return a 400 for native queries that fail with a
`ValueInstantiationException`. Other `JsonMappingException`s raised while
binding well-formed JSON to a `Query` still fall through to the catch-all in
`QueryResource#doPost`. For example:
- an unknown `queryType` (`InvalidTypeIdException`)
- a field of the wrong type, e.g. `"aggregations": "rows"`
(`MismatchedInputException`)
For each such request, the broker logs a full stack trace at `WARN`
("Uncaught exception from query processing. This should be caught and handled
directly.") and returns a 500 `Unhandled exception made it to the top` that
names only the exception class. These are client errors, so they flood the
broker log and don't tell the caller what is wrong.
#### Fix
`readQuery` now also catches `JsonMappingException`, after the existing
`ValueInstantiationException` catch. It is converted into a
`BadJsonQueryException`, so the request goes through the existing `catch
(QueryException e)` path: a 400 `Json parse failed` response with no stack
trace logged. The error message is `Invalid native query: <original message>
(through reference chain: <path>)`, for example:
```
Invalid native query: Cannot deserialize value of type
`java.util.ArrayList<...>` from String value ('rows') ... (through reference
chain: org.apache.druid.query.timeseries.TimeseriesQuery["aggregations"])
```
`errorClass` is the actual Jackson exception class, consistent with the
`ValueInstantiationException` handling from #19775.
#### Release note
Native queries that are valid JSON but cannot be deserialized into a query,
such as an unknown `queryType` or a field of the wrong type, now return HTTP
400 with a descriptive error instead of HTTP 500, and no longer log a stack
trace on the Broker.
<hr>
##### Key changed/added classes in this PR
* `QueryResource`
* `BadJsonQueryException`
* `QueryResourceTest`
<hr>
This PR has:
- [x] been self-reviewed.
- [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.
--
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]