-
Type: New Feature
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: V4.01_CS01
-
Fix Version/s: V4.01_CS02
-
Component/s: Protocol, URL Conventions
-
Labels:None
-
Environment:
Applied with simplified proposal
-
Proposal:
-
Resolution:
Support of case expressions as known from the SQL standard would add to the ad hoc capabilities and support use cases that require such an IF-THEN-ELSE logic.
Imagine case( condition_1 : value_1, ..., condition_N : value_N [, else_value] ) would be available as canonical function for common expressions; an omitted else defaults to null. Here are some examples that could be addressed with it:
1. Core OData: Ad-hoc calculations with logic on the current property values:
Example: Signum
GET ~/XValues?$compute=case(X gt 0 : 1,X lt 0 : -1, 0) as SignumX&$select=X,SignumX
2. Data Aggregation extension: Restricting aggregation to those values that occur in combination with certain groupable property values:
Example: Comparing company revenues for years 2000 and 2017
GET ~/Sales?$apply=groupby((Company), aggregate(case(Time/Year eq 2000 : Revenue) with sum as TotalRevenue2000, case(Time/Year eq 2017 : Revenue) with sum as TotalRevenue2017))
3. Data Aggregation extension: Defining dynamic groupable properties
Example: From a collection of incidents with fine-grained state model (e.g., new, assigned, resolved, verified, reopened, closed) retrieve the aggregated count of open and closed incidents:
GET ~/Incidents?$apply=compute(case(Status eq ‘Closed’ : ‘Closed’, ‘Open’) as ProcessingStatus)/groupby((ProcessingStatus), aggregate($count as IncidentCount))