Logging the fieldName in the coerce exceptions #14483
Conversation
LakshSingla
left a comment
There was a problem hiding this comment.
Thanks for the PR!
Can you add a SQL test (CalciteQueryTest) and/or an MSQ query that shows the coercion error
| public void testCoerceOfArrayOfPrimitives() | ||
| { | ||
| try { | ||
| ObjectMapper mapper = new ObjectMapper(); |
There was a problem hiding this comment.
nit: I think we should initialize this outside the test case since it would assist any other tests trying to use an object mapper.
There was a problem hiding this comment.
| ObjectMapper mapper = new ObjectMapper(); | |
| ObjectMapper mapper = new DefaultObjectMapper(); |
While it might not affect this use case, DefaultObjectMapper() is preferred since it contains Druid's modules having custom serdes.
| private static String prepareCoerceException(Object value, SqlTypeName sqlTypeName, String fieldName) | ||
| { | ||
| return StringUtils.format( | ||
| "Cannot coerce field [%s] of value with class [%s] to %s", |
There was a problem hiding this comment.
| "Cannot coerce field [%s] of value with class [%s] to %s", | |
| "Cannot coerce field [%s] of value with class [%s] to [%s]", |
There was a problem hiding this comment.
"Cannot coerce field [%s] of type [%s] to type [%s]"
|
|
||
| private static ISE coerceExceptionWithSupressed(Object value, SqlTypeName sqlTypeName, String fieldName, Throwable t) | ||
| { | ||
| ISE e = new ISE(prepareCoerceException(value, sqlTypeName, fieldName)); |
There was a problem hiding this comment.
We should use the newly added DruidException class since it's a using-facing message.
| private static ISE coerceExceptionWithSupressed(Object value, SqlTypeName sqlTypeName, String fieldName, Throwable t) | ||
| { | ||
| ISE e = new ISE(prepareCoerceException(value, sqlTypeName, fieldName)); | ||
| e.addSuppressed(t); |
There was a problem hiding this comment.
I am not very clear with the semantics of adding t as suppressed v/s adding it as a cause.
Since t is directly causing the coercion exception that we are raising, I suppose it should be a cause. right?
There was a problem hiding this comment.
added the new DruidExceptions
| Assert.fail("Should throw an exception"); | ||
| } | ||
| catch (Exception e) { | ||
| Assert.assertEquals("Cannot coerce field [testFieldName] of value with class [[B] to BIGINT", e.getMessage()); |
There was a problem hiding this comment.
can we also more friendly type names such as binary instead of [[B?
There was a problem hiding this comment.
We could add the mapping of primitive array class names to actual names. Following list is standard to Strings for primitive java arrays classnames.
[Z = boolean
[B = byte
[S = short
[I = int
[J = long
[F = float
[D = double
[C = char
[L = any non-primitives(Object)
f9a6840 to
ec7687c
Compare
Coerce error happens while indexing the hll sketch columns with empty values. test framework was not ingesting it as correct long values and I was not able to add test that has byte array in the ingestions. |
|
@LakshSingla @abhishekagarwal87 Can you please review? |
5f6cc9b to
ea6a82c
Compare
| Assert.fail("Should throw an exception"); | ||
| } | ||
| catch (Exception e) { | ||
| Assert.assertEquals("Cannot coerce field [fieldName] class of [[B] to [BIGINT]", e.getMessage()); |
There was a problem hiding this comment.
weren't we going to replace [[B] with a more friendly name such as binary?
| t, | ||
| "Cannot coerce field [%s] class of [%s] to [%s]", | ||
| fieldName, | ||
| value == null ? "null" : value.getClass().getName(), |
There was a problem hiding this comment.
| value == null ? "null" : value.getClass().getName(), | |
| value == null ? "unknown" : value.getClass().getName(), |
| ) | ||
| { | ||
| return new ISE(t, "Cannot coerce [%s] to [%s]", value == null ? "null" : value.getClass().getName(), sqlTypeName); | ||
| return DruidException.forPersona(DruidException.Persona.DEVELOPER) |
There was a problem hiding this comment.
Hmm. I would say that this is for user persona since its an invalid input.
| .ofCategory(DruidException.Category.INVALID_INPUT) | ||
| .build( | ||
| t, | ||
| "Cannot coerce field [%s] class of [%s] to [%s]", |
There was a problem hiding this comment.
How about including an action message here? @clintropolis - any suggestions?
ea6a82c to
c99dd83
Compare
|
@abhishekagarwal87 @clintropolis please review |
c99dd83 to
f0ad7b6
Compare
f0ad7b6 to
dc38717
Compare
9d6e95f to
02ed241
Compare
…java fix the logging Co-authored-by: Abhishek Agarwal <1477457+abhishekagarwal87@users.noreply.github.com>
02ed241 to
4624644
Compare
Logging the fieldName in the coerce exceptions
Description
This PR is improving the logging in coerce exceptions, coerce is currently eating some exceptions esp on JSON and primitive array parsing. This change is adding the exceptions in suppressed. Somehow in ingestion flow, we are getting the Value in coerce as
new byte[0]with SqlType BIGINT which is throwing the following exceptions.Error: Unknown exception Cannot coerce [[B] to BIGINTPeople had hard time in finding out which field is causing the exception while querying. Thus, this change is logging the fieldName along with exception. This will help us identify the issues in the ingestion and we can figure why are we ingesting primitive arrays.
Fixed the bug ...
Renamed the class ...
Added a forbidden-apis entry ...
Release note
Key changed/added classes in this PR
MyFooOurBarTheirBazThis PR has: