-
Notifications
You must be signed in to change notification settings - Fork 217
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
[RFC] Data Prepper Expression Syntax #1005
Comments
Thanks for putting this together! It looks great. One change I'd like to make is to use the term "set" instead of "list." For example, the section "List Operators" should be "Set Operators." I think that we are viewing them as sets, so it would be better to be explicit in that. Along those lines, I also wonder if it would make sense to change the syntax for set initialization. Perhaps a set could be initialized with curly braces like I'm not sure if Data Prepper will ever need to evaluate against true lists or not. Perhaps There may be some value in supporting variables in the future too. I'd probably say Data Prepper would use the standard |
Great feedback! I'd like to add that variable names should be supported within string |
How would customer use these examples? I am envisioning customers only writing expressions that always include a jsonPointer |
Do we need assignment operators? How will they be used? Other high level questions - what are our requirements? What is the scope of this syntax? |
While this is a good plan, we should also consider the prioritization of which operations will be most valuable. Then we can iterate on the implementation of them. I'd propose the prioritizing them by:
Here is my initial priority: Data Prepper 1.3.0:
Data Prepper 1.4.0:
Data Prepper 2.0.0:
Needing future consideration:
|
|
Thank you everyone for the feedback. I updated the RFC proposal based on everyones feedback. |
Thanks @sbayer55 , You added set initializer to 1.3.0, but set operations to 1.4.0. Is there value in having the initializers without the operations? If not, I'd say we add set initialization in 1.4.0 as well. Also, Data Prepper may want to support a limited set of functions in the future. For example |
Issues regarding white space and potential future function support raised. |
Perhaps it is too late to comment on this RFC, but I would like a little clarity on expressions for matching against string values with
And I also see the "Escaped Example" above; however, when trying to write my own expression I am not able to get it to work for conditional routing with something like this (trying to escape my route:
- super-tenant: '/"span\.attributes\.tenant" == "super"'
- other-tenant: '/"span\.attributes\.tenant" != "super"' Do you have any recommendations for this scenario? Thanks! I also commented on #2259 |
Is your feature request related to a problem? Please describe.
As part of a larger feature (#522) to support complex condition statements in data prepper there is a need to define a syntax for conditional statements. A conditional statement is a String that is evaluated at runtime and may reference fields within a record.
Describe the solution you'd like
Terms used throught this document are defined in the Definitions section
Supported Operators
In order of evaluation priority. (top to bottom, left to right)
{}
()
not
in
,not in
<
,<=
,>
,>=
=~
,!~
==
,!=
and
,or
,
Reserved for possible future functionality
Reserved symbol set:
^
,*
,/
,%
,+
,-
,xor
,=
,+=
,-=
,*=
,/=
,%=
,++
,--
,${<text>}
Set Initialiser
Defines a set or term and/or expressions.
Examples
Priority Expression
Identifies an expression that will be evaluated at the highest priority level. Priority expression must contain an
expression or value, empty parentheses are not supported.
Examples
Set Operators
Tests if a value is in/not in a set. Note, the right-hand side operand must be a set.
Syntax
Examples
Relational Operators
Tests the relationship of two numeric values. Note, the operands must be a number or Json Pointer that will resolve to a number.
Syntax
Examples
Regex Equality Operators
Used to test if a String value matches/does not match a Regular Expression. Note, the left-hand side operand must be a string or Json Pointer that resolves to a String. The right hand side operand must be a String that contains a regular expression or a Json Pointer that resolves to a String that contains a regular expression.
Syntax
Examples
Equality Operators
Used to test if two value are/are not equivalent.
Syntax
Examples
Conditional Expression
Used to chain together multiple expressions and/or values.
Syntax
Examples
Definitions
Literal
A fundamental value that has no children.
Expression String
The String that will be parsed for evaluation. Expression String is the highest level of a Data Prepper Expression. Only supports one
Expression String resulting in a return value. Note, an Expression String is not the same as an Expression.
Statement
The highest level component of the Expression String.
Expression
A generic component that contains a Primary or an Operator. Expressions may contain expressions. An expressions imminent children can contains 0-1 Operators.
Primary
Operator
Hard coded token that identifies the operation use in an Expression.
Json Pointer
A Literal used to reference a value within the Event provided as context for the Expression String. Json Pointers are identified by a leading
/
containing alpha numeric character or underscores, delimited by/
. Json Pointers can use an extended character set if wrapped in double quotes ("
) using the escape character\
. Note, Json Pointer require~
and/
that should be used as part of the path and not a delimiter to be escaped.~0
representing~
~1
representing/
Shorthand Syntax (Regex,
\w
=[A-Za-z_]
)Shorthand Example
Escaped Syntax
Escaped Example
White Space
Operators
White space is optional surrounding Relational Operators, Regex Equality Operators, Equality Operators and commas.
White space is required surrounding Set Initializers, Priority Expressions, Set Operators, and Conditional Expressions.
Reference Table
{}
/status in {200}
/status in{200}
()
/a==(/b==200)
/a in ({200})
/status in({200})
in
,not in
/a in {200}
/a not in {400}
/a in{200, 202}
/a not in{400}
<
,<=
,>
,>=
/status < 300
/status>=300
=~
,!~
/msg =~ "^\w*$"
/msg=~"^\w*$"
==
,!=
/status == 200
/status_code==200
and
,or
,not
/a<300 and /b>200
/b<300and/b>200
,
/a in {200, 202}
/a in {200,202}
/a in {200 , 202}
/a in {200,}
The text was updated successfully, but these errors were encountered: