You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Fabian Zimmermann <zi...@gmail.com> on 2020/11/06 09:50:00 UTC

How should I serialize an aggregation

Hello all,

This is my first time submitting a question to a mailing list, therefore
please forgive me should my question be inappropriate or unfortunately
placed. I just hope to get an impulse into the right direction - my
research on the subject did not get me far, unfortunately.

This is the situation:

I set up an odata service using the official tutorial and it worked
beautifully. Then, I added apply support - following the regular steps:
1. Analyzing the URI
2. Fetching the data from the backend
3. Applying the grouping and aggregation options
4. Serializing the result

It works. However, I did not know how to properly serialize the content,
therefore I just concatenated (patched together, one could say) strings to
a json and used this as the HTTP response. I would like to do it right. So:
What would be the correct way of doing this? How do I collect the
aggregated results? Are they a collection of "entities" that I could pass
to the serializer (given the collections variable nature, it would not be
an entity type as defined in the EDM, I guess)? Or is the aggregated result
a collection of primitive values (the e.g. count or sum would be primitive,
but how would I supply the "path of properties" that the entities were
grouped by). Or is it something else (a complexCollection or a
referenceCollection, maybe)? If yes, how would I build an element of such a
collection?

Thank you in advance for your support.

Best regards,
Fabian

RE: How should I serialize an aggregation

Posted by "Krause, Gerald" <ge...@sap.com>.
The results of an OData request with $apply is a collection of aggregated entities (not of primitive values) resulting from the transformation sequence, whose structure is based on the structures from which they have been calculated. You can find more details on the representation of the result in the current spec in section 4        Representation of Aggregated Instances<http://docs.oasis-open.org/odata/odata-data-aggregation-ext/v4.0/cs02/odata-data-aggregation-ext-v4.0-cs02.html#_Toc435016593>.

For a given $apply expression, you determine the result structure of a transformation in the sequence by applying the result structure rules for that transformation to the structure of the input set, which was either created from a preceding transformation or is the collection of the resource collection addressed by the request. The overall result structure of the $apply expression is the result structure of the last transformation. For the rules how the result is structured for a certain transformation, have a look at the respective section in the specification document<http://docs.oasis-open.org/odata/odata-data-aggregation-ext/v4.0/cs02/odata-data-aggregation-ext-v4.0-cs02.html#_Toc435016567>.

The examples in the specification document may give you further guidance how to construct the response, or you look at the existing OData V4 reference service on https://www.odata.org/odata-services/ that also has some $apply support built-in.

Gerald.


From: Fabian Zimmermann <zi...@gmail.com>
Sent: Friday, 6 November 2020 10:50
To: user@olingo.apache.org
Subject: How should I serialize an aggregation

Hello all,

This is my first time submitting a question to a mailing list, therefore please forgive me should my question be inappropriate or unfortunately placed. I just hope to get an impulse into the right direction - my research on the subject did not get me far, unfortunately.

This is the situation:

I set up an odata service using the official tutorial and it worked beautifully. Then, I added apply support - following the regular steps:
1. Analyzing the URI
2. Fetching the data from the backend
3. Applying the grouping and aggregation options
4. Serializing the result

It works. However, I did not know how to properly serialize the content, therefore I just concatenated (patched together, one could say) strings to a json and used this as the HTTP response. I would like to do it right. So: What would be the correct way of doing this? How do I collect the aggregated results? Are they a collection of "entities" that I could pass to the serializer (given the collections variable nature, it would not be an entity type as defined in the EDM, I guess)? Or is the aggregated result a collection of primitive values (the e.g. count or sum would be primitive, but how would I supply the "path of properties" that the entities were grouped by). Or is it something else (a complexCollection or a referenceCollection, maybe)? If yes, how would I build an element of such a collection?

Thank you in advance for your support.

Best regards,
Fabian