Uploaded image for project: 'OASIS Open Data Protocol (OData) TC'
  1. OASIS Open Data Protocol (OData) TC
  2. ODATA-1158

Transformations for limiting the number of entities in the result of a $apply transformation

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: V4.0_CSD03
    • Fix Version/s: V4.0_CSD04
    • Component/s: Data Aggregation
    • Labels:
      None
    • Environment:

      Proposed

    • Proposal:
      Hide

      Define transformations skip and top:

      • The skip transformation takes a non-negative integer n as argument that excludes the first n entities of the input set. It returns all remaining entities in the same order as they occur in the input set.
      • The top transformation takes a non-negative integer n as argument and returns the first n entities of the input set, if the input set contains more than n entities, otherwise the entire input set. The entities in the result are in the same order as they occur in the input set.

      Since both transformations operate on the order of entities in the input set, the client needs to know how to specify meaningful requests involving these two transformations.

      The transformations preceding skip/top in the sequence must first produce a certain order among the entities, and then keep this order stable for the input set of skip/top. Transformations in the first group are the topXXX and bottomXXX transformations, plus the pending orderby transformation (ODATA-1157). The second group consists of transformations identity and compute. The ordering constraint has already described for these transformations. Other transformations should not be restricted by such an ordering constraint to retain the current implementation flexibility. For example, an implementation of the filter transformation might involve efficient search structures that do not keep up the input set order.

      Show
      Define transformations skip and top: The skip transformation takes a non-negative integer n as argument that excludes the first n entities of the input set. It returns all remaining entities in the same order as they occur in the input set. The top transformation takes a non-negative integer n as argument and returns the first n entities of the input set, if the input set contains more than n entities, otherwise the entire input set. The entities in the result are in the same order as they occur in the input set. Since both transformations operate on the order of entities in the input set, the client needs to know how to specify meaningful requests involving these two transformations. The transformations preceding skip/top in the sequence must first produce a certain order among the entities, and then keep this order stable for the input set of skip/top. Transformations in the first group are the topXXX and bottomXXX transformations, plus the pending orderby transformation ( ODATA-1157 ). The second group consists of transformations identity and compute. The ordering constraint has already described for these transformations. Other transformations should not be restricted by such an ordering constraint to retain the current implementation flexibility. For example, an implementation of the filter transformation might involve efficient search structures that do not keep up the input set order.

      Description

      Transformation concat combines entity collections returned by two or more transformation sequences in a new, concatenated collection.

      For limiting the number of items returned from the overall result collection, today the only way is to use system query options $skip and $top. It is currently not possible to limit the individual result collections of the transformation sequences passed to concat.

      There are use cases requiring this ability. As an example, consider a request asking for (1) the grand total sales amount along with (2) the sales figures for the first 10 customers. Note that (1) may return a collection with more than one entry in case multiple currencies are involved, hence a global $top does not give full control to the client. In the worst case with more than ten currencies, not a single customer sales amount would be returned. If the aggregated result is put into a stable order with the orderby transformation (described in <issue>), this can be avoided with a top transformation:

      GET ~/Sales?$apply=
      concat( groupby( (Currency), Amount with sum as TotalAmount ),
      groupby( (Customer,Currency), Amount with sum as TotalAmount )
      /orderby( Customer,Currency )
      /top( 10 )
      )

      Another example also involving a skip transformation could be a request fetching sales amounts per customer and month in pages of ten data points per request, complemented with minimum and maximum amounts of the entities on this page. The request for the fourth page would look like:

      GET ~/Sales?$apply=
      groupby( (Customer,Time/Month,Currency), Amount with sum as TotalAmount ),
      /orderby( Customer,Time/Month,Currency )
      /skip( 30 )/top( 10 )
      /concat(
      identity,
      aggregate( Amount with min as MinAmount, Amount with max as MaxAmount ) )

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: