-
Notifications
You must be signed in to change notification settings - Fork 113
Modify RmdUtils:getLastUpdateTimestamp to fix class cast exception #2283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
mynameborat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make sure there is enough coverage in unit test? Looks like some of the code coverage checks are failing.
| @Test | ||
| public void testGetLastUpdateTimestampWithCollectionFields() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is not an existing test, can you add one for the top level field that contributes to maximum?
| // Handle DELETED_ELEM_TS_FIELD_NAME as a List/Collection | ||
| Object deletedTimestamps = fieldRecord.get(DELETED_ELEM_TS_FIELD_NAME); | ||
| if (deletedTimestamps instanceof List) { | ||
| for (Object ts: (List<?>) deletedTimestamps) { | ||
| lastUpdatedTimestamp = Math.max(lastUpdatedTimestamp, ((Number) ts).longValue()); | ||
| } | ||
| } | ||
| for (long timestamp: (long[]) ((GenericRecord) ((GenericRecord) timestampRecord).get(field.name())) | ||
| .get(ACTIVE_ELEM_TS_FIELD_NAME)) { | ||
| lastUpdatedTimestamp = Math.max(lastUpdatedTimestamp, timestamp); | ||
|
|
||
| // Handle ACTIVE_ELEM_TS_FIELD_NAME as a List/Collection | ||
| Object activeTimestamps = fieldRecord.get(ACTIVE_ELEM_TS_FIELD_NAME); | ||
| if (activeTimestamps instanceof List) { | ||
| for (Object ts: (List<?>) activeTimestamps) { | ||
| lastUpdatedTimestamp = Math.max(lastUpdatedTimestamp, ((Number) ts).longValue()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we extract maximum inference to a method? Looks boiler plate.
|
|
||
| // Handle DELETED_ELEM_TS_FIELD_NAME as a List/Collection | ||
| Object deletedTimestamps = fieldRecord.get(DELETED_ELEM_TS_FIELD_NAME); | ||
| if (deletedTimestamps instanceof List) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does instanceof List check covers all types of collection in avro?
Problem Statement
Caused by: java.lang.ClassCastException: class org.apache.avro.generic.GenericData$Array cannot be cast to class [J (org.apache.avro.generic.GenericData$Array is in unnamed module of loader 'app'; [J is in module java.base of loader 'bootstrap')
GenericDataArray treats the collection as list opposed to long[] array. Fixing the same.
Solution
Treat DELETED_ELEM_TS_FIELD_NAME and ACTIVE_ELEM_TS_FIELD_NAME as List/Collection instead of long array
How was this PR tested?
Unit tests