XMLWordPrintable

    Details

    • 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:
      Hide

      The case function has the following signatures:

      expression case(Edm.Boolean:expression, ..., Edm.Boolean:expression)
      {{ expression case(Edm.Boolean:expression, ..., Edm.Boolean:expression,expression)}}

      Each Edm.Boolean:expression parameter is a tuple separated by a colon, where the first component evaluates to a Boolean value, and the second component may be an expression of any type.

      The case function returns the expression value of the leftmost parameter, whose first component evaluates to true. If none of the parameters match, case returns null, unless the last parameter is an expression, whose value is returned otherwise.

      Revised proposal 2018-4-19: The client SHOULD ensure that all parameter expressions are compatible. If all parameter expressions are of the same type, the type of the case expression is of that type. If all parameter expressions 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.

      Simplified proposal 2018-08-30: all parameters are expression pairs with a colon, the "default" can be achieved by making the last pair true:expression.

      Show
      The case function has the following signatures: expression case(Edm.Boolean:expression, ..., Edm.Boolean:expression) {{ expression case(Edm.Boolean:expression, ..., Edm.Boolean:expression,expression)}} Each Edm.Boolean:expression parameter is a tuple separated by a colon, where the first component evaluates to a Boolean value, and the second component may be an expression of any type. The case function returns the expression value of the leftmost parameter, whose first component evaluates to true. If none of the parameters match, case returns null, unless the last parameter is an expression, whose value is returned otherwise. Revised proposal 2018-4-19: The client SHOULD ensure that all parameter expressions are compatible. If all parameter expressions are of the same type, the type of the case expression is of that type. If all parameter expressions 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. Simplified proposal 2018-08-30 : all parameters are expression pairs with a colon, the "default" can be achieved by making the last pair true:expression .
    • Resolution:
      Show
      https://github.com/oasis-tcs/odata-abnf/pull/2 https://www.oasis-open.org/committees/download.php/63896/odata-v4.01-wd06-part2-url-conventions-2018-08-30.docx  

      Description

      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))

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              gerald.krause1 Gerald Krause
            • Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: