-
Notifications
You must be signed in to change notification settings - Fork 351
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
Support 'case' conditional function #2356
base: release-7.x
Are you sure you want to change the base?
Conversation
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
Can this be picked up again? 🙏 I want to start using but |
Would you please share a little bit more detail about your usage/sceneries and yourself to us so we can priority it carefully? Thanks to: [email protected] |
Right now I only have one use case which is null coalescing: case(field1 ne null:field1, true:field2) Which can be read as: coalesce(field1, field2) But I expect to find more ways to use this in the future. |
Also see this related issue OData/AspNetCoreOData#684 |
Issues
This pull request fixes #2309.
Description
Support 'case' conditional function parsing.
Here's the information for the "case" function:
5.1.1.12 Conditional Functions
5.1.1.12.1 case
The case function has the following signature:
expression case(Edm.Boolean:expression, ..., Edm.Boolean:expression)
Each parameter is a pair of expressions separated by a colon (:), where the first expression – the condition – MUST be a Boolean expression, and the second expression – the result – may evaluate to any type.
The case function evaluates the condition in each pair, starting with the leftmost pair, and stops as soon as a condition evaluates to true. It then returns the value of the result of this pair. It returns null if none of the conditions in any pair evaluates to true. Clients can specify a last pair whose condition is true to get a non-null “default/else/otherwise” result.
Clients SHOULD ensure that the results in all pairs are compatible. If all results are of the same type, the type of the case expression is of that type. If all results are of numeric type, then the type of the case expression is a numeric type capable of representing any of these expressions according to standard type promotion rules.
Services MAY support case expressions containing parameters of incompatible types, in which case the case expression is treated as Edm.Untyped and its value has the type of the parameter expression selected by the case statement.
Example 97: compute signum(X)
$compute=case(X gt 0 :1,X lt 0 :-1,true :0) as SignumX
[Discussion]
We should ask whitespace before the ':', otherwise we have the following problem:, (However, it sounds ridiculous)
That's because ':' is a valid character both for separate or char in time value.
case(Id eq 2:1)
=> should 'case(Id eq 2 :1)`case(CreatedTime eq 10:2:1)
==> We can't distinguish it from TimeOfDay valueBut, this does:
case(CreatedTime eq 10:2 :1)
case(CreatedTime eq 10:2:1:2:3)
It can be:
10:2:1 : 2:3
or10:2 : 1:2:3
Checklist (Uncheck if it is not completed)
Additional work necessary
If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.