OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
686 stars 349 forks source link

CASE not working in $compute and $filter #2309

Open savicarlone1977 opened 2 years ago

savicarlone1977 commented 2 years ago

CASE is not working at all in $compute and $filter clauses

Assemblies affected

OData .Net lib 8.0.7

Reproduce steps

Call OData V4 service built using NET 6 and try a $compute with CASE clause

Expected result

Tha additional field

Actual result

Exception in parser

xuzhg commented 2 years ago

@savicarlone1977 Thanks for reporting this. Unfortunately, 'case' is not supported yet on the ODL side.

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

gathogojr commented 2 years ago

@savicarlone1977 This is a feature gap and we have added the issue to our backlog. However, we do welcome contributions so if this is a feature you might have room to work on we'd very happy to review the pull request.