generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 181
Fix ClassCastException for value-storing aggregates on nested PPL fields
#4360
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
integ-test/src/test/resources/indexDefinitions/telemetry_test_mapping.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| { | ||
| "mappings": { | ||
| "properties": { | ||
| "resource": { | ||
| "properties": { | ||
| "attributes": { | ||
| "properties": { | ||
| "telemetry": { | ||
| "properties": { | ||
| "sdk": { | ||
| "properties": { | ||
| "language": { | ||
| "type": "keyword", | ||
| "ignore_above": 256 | ||
| }, | ||
| "name": { | ||
| "type": "keyword", | ||
| "ignore_above": 256 | ||
| }, | ||
| "version": { | ||
| "type": "integer" | ||
| }, | ||
| "enabled": { | ||
| "type": "boolean" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "severityNumber": { | ||
| "type": "integer" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| {"index":{"_id":"1"}} | ||
| {"resource": {"attributes": {"telemetry": {"sdk": {"language": "java", "name": "opentelemetry", "version": 10, "enabled": true}}}}, "severityNumber": 9} | ||
| {"index":{"_id":"2"}} | ||
| {"resource": {"attributes": {"telemetry": {"sdk": {"language": "python", "name": "opentelemetry", "version": 11, "enabled": false}}}}, "severityNumber": 12} | ||
| {"index":{"_id":"3"}} | ||
| {"resource": {"attributes": {"telemetry": {"sdk": {"language": "javascript", "name": "opentelemetry", "version": 12, "enabled": true}}}}, "severityNumber": 9} | ||
| {"index":{"_id":"4"}} | ||
| {"resource": {"attributes": {"telemetry": {"sdk": {"language": "go", "name": "opentelemetry", "version": 13, "enabled": false}}}}, "severityNumber": 16} | ||
| {"index":{"_id":"5"}} | ||
| {"resource": {"attributes": {"telemetry": {"sdk": {"language": "rust", "name": "opentelemetry", "version": 14, "enabled": true}}}}, "severityNumber": 12} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,7 +182,8 @@ public ExprValue construct(String jsonString, boolean supportArrays) { | |
| * @return ExprValue | ||
| */ | ||
| public ExprValue construct(String field, Object value, boolean supportArrays) { | ||
| return parse(new ObjectContent(value), field, type(field), supportArrays); | ||
| Object extractedValue = extractFinalPrimitiveValue(value); | ||
| return parse(new ObjectContent(extractedValue), field, type(field), supportArrays); | ||
| } | ||
|
|
||
| private ExprValue parse( | ||
|
|
@@ -526,4 +527,26 @@ private ExprValue parseInnerArrayValue( | |
| private String makeField(String path, String field) { | ||
| return path.equalsIgnoreCase(TOP_PATH) ? field : String.join(".", path, field); | ||
| } | ||
|
|
||
| /** | ||
| * Recursively extracts the final primitive value from nested Map structures. For example: | ||
| * {attributes={telemetry={sdk={language=java}}}} -> "java" | ||
| * | ||
| * @param value The value to extract from | ||
| * @return The extracted primitive value, or the original value if extraction is not possible | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| private Object extractFinalPrimitiveValue(Object value) { | ||
| if (value == null || !(value instanceof Map)) { | ||
| return value; | ||
| } | ||
|
|
||
| Map<String, Object> map = (Map<String, Object>) value; | ||
| if (map.size() == 1) { | ||
| Object singleValue = map.values().iterator().next(); | ||
| return extractFinalPrimitiveValue(singleValue); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there risk of a RecursionError here? If this is only loaded from an index, it's maybe fine (I think you can't index massively nested structures, not sure). But if there's a path where this is executed on user input, it'd be very easy to cause a crash with this. |
||
| } | ||
|
|
||
| return value; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What if the type of nested
languageis an integer, can the ppl work?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.
Yes, in ObjectContent.java, first the
extractFinalPrimitiveValuemethod will extract the value as Object and then we'll add toString() to it.Uh oh!
There was an error while loading. Please reload this page.
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.
No I mean what if the mapping contains
and query with
| stats min(`resource.attributes.telemetry.sdk.version`).Can you update the mapping and data, and test above query?
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.
Changed the approach - moved the fix from ObjectContent.java to OpenSearchExprValueFactory.construct() for better universal handling. Updated the telemetry mapping to test for types like integer and boolean