Skip to content

Add support for updating JacksonEvent array elements#5772

Merged
graytaylor0 merged 5 commits into
opensearch-project:mainfrom
graytaylor0:JacksonEventListFix
Jun 12, 2025
Merged

Add support for updating JacksonEvent array elements#5772
graytaylor0 merged 5 commits into
opensearch-project:mainfrom
graytaylor0:JacksonEventListFix

Conversation

@graytaylor0

@graytaylor0 graytaylor0 commented Jun 11, 2025

Copy link
Copy Markdown
Member

Description

Fixes an issue where updating Jackson Event with json pointer paths to array like

/list-key/0/nested-key

failed with a ClassCastException to ObjectNode (since it is ArrayNode)

2025-06-10T14:51:24,907 [test-pipeline-processor-worker-1-thread-1] ERROR
java.lang.ClassCastException: class com.fasterxml.jackson.databind.node.ArrayNode cannot be cast to class com.fasterxml.jackson.databind.node.ObjectNode (com.fasterxml.jackson.databind.node.ArrayNode and com.fasterxml.jackson.databind.node.ObjectNode are in unnamed module of loader 'app')
    at org.opensearch.dataprepper.model.event.JacksonEvent.getOrCreateNode(JacksonEvent.java:198) ~[data-prepper-api-2.11.0-SNAPSHOT.jar:?]
    at org.opensearch.dataprepper.model.event.JacksonEvent.put(JacksonEvent.java:161) ~[data-prepper-api-2.11.0-SNAPSHOT.jar:?]
    at org.opensearch.dataprepper.model.event.JacksonEvent.put(JacksonEvent.java:177) ~[data-prepper-api-2.11.0-SNAPSHOT.jar:?]

Issues Resolved

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Taylor Gray <tylgry@amazon.com>
@kkondaka

Copy link
Copy Markdown
Collaborator

@graytaylor0 looks good. Could you also add a test in ConvertEntryProcessor tests?

Signed-off-by: Taylor Gray <tylgry@amazon.com>
int index = Integer.parseInt(key);
ArrayNode arrayNode = (ArrayNode) node;

while (arrayNode.size() <= index) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test case for this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think we should limit the number new null nodes can be added.

Comment on lines +202 to +204
while (arrayNode.size() <= index) {
arrayNode.addNull();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to fill nulls? You have null check in the below logic anyway right?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided to not allow extending the size of array by filling nulls. We will allow at most one more entry beyond the current size

Signed-off-by: Taylor Gray <tylgry@amazon.com>
…end of the array

Signed-off-by: Taylor Gray <tylgry@amazon.com>

while (arrayNode.size() <= index) {
int distanceFromArrayEnd = index - arrayNode.size();
if (distanceFromArrayEnd >= FILL_OUT_OF_BOUNDS_ELEMENTS_LIMIT + 1) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition can be outside the while loop

Signed-off-by: Taylor Gray <tylgry@amazon.com>
@graytaylor0 graytaylor0 merged commit e53aaff into opensearch-project:main Jun 12, 2025
45 of 47 checks passed
jeffreyAaron pushed a commit to jeffreyAaron/data-prepper that referenced this pull request Jun 13, 2025
…ect#5772)

Signed-off-by: Taylor Gray <tylgry@amazon.com>
Signed-off-by: Jeffrey Aaron Jeyasingh <jeffreyaaron06@gmail.com>
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.

3 participants