Skip to content

Conversation

@suketkar
Copy link
Contributor

@suketkar suketkar commented Nov 13, 2025

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

Copy link
Contributor

@mynameborat mynameborat left a 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.

Comment on lines +175 to +176
@Test
public void testGetLastUpdateTimestampWithCollectionFields() {
Copy link
Contributor

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?

Comment on lines +161 to +174
// 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());
}
Copy link
Contributor

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) {
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants