Skip to content

[BUG] Attempting to evaluate if a key is null throws an Exception if the value is a List<String> for conditional expressions #4109

Description

@graytaylor0

Describe the bug
Evaluating a statement like

when: '/my_field == null'

will throw an Exception if the value of my_field does not match the expression ANTLR language

To Reproduce
Steps to reproduce the behavior:

  1. Create a pipeline with a when condition equal to /my_field == null
  2. Send an Event where my_field is an array, such as { "my_field": ["2024-02-09 19:26:25.308", "2024-02-09 19:26:25.308"] }
  3. Observe the exception
2024-02-12T10:28:13,789 [test-pipeline-processor-worker-1-thread-1] ERROR org.opensearch.dataprepper.expression.ParseTreeEvaluator - Unable to evaluate event
org.opensearch.dataprepper.expression.ExpressionCoercionException: Unsupported type for value [2024-02-09 19:26:25.308, 2024-02-09 19:26:25.308]
	at org.opensearch.dataprepper.expression.ParseTreeCoercionService.lambda$new$0(ParseTreeCoercionService.java:33) ~[data-prepper-expression-2.7.0-SNAPSHOT.jar:?]
	at org.opensearch.dataprepper.expression.ParseTreeCoercionService.resolveJsonPointerValue(ParseTreeCoercionService.java:103) ~[data-prepper-expression-2.7.0-SNAPSHOT.jar:?]
	at org.opensearch.dataprepper.expression.ParseTreeCoercionService.coercePrimaryTerminalNode(ParseTreeCoercionService.java:69) ~[data-prepper-expression-2.7.0-SNAPSHOT.jar:?]
	at org.opensearch.dataprepper.expression.ParseTreeEvaluatorListener.visitTerminal(ParseTreeEvaluatorListener.java:69) ~[data-prepper-expression-2.7.0-SNAPSHOT.jar:?]
	at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:29) ~[antlr4-runtime-4.10.1.jar:4.10.1]

Expected behavior
For checks of /my_field != null or /my_field == null, we should convert the value of my_field to an Object and check that it is null or not null, and should not rely on the ANTLR language for conditional expressions

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: [e.g. Ubuntu 20.04 LTS]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions