Backendless Support
 
Works as Designed

Getting different responses when request different properties(aggregate functions).

When I am trying to query data with different custom properties(aggregate functions) I am getting different results. For example:

  1. private final String PROPERTY_COMMENTS_COUNT = "Count(comments) as commentsCount";
  2. private final String PROPERTY_RATING = "Avg(comments.rating) as rating";
  3. queryBuilder.setProperties(COMMENTS_COUNT, PROPERTY_RATING);

I am getting only object A1, if I do

  1. queryBuilder.setProperties(COMMENTS_COUNT);

I am getting only object B1.If I am changing property to

  1. queryBuilder.setProperties(PROPERTY_RATING);

I am getting A1 again. But should get A1 and B1 for all three request.

APP ID: EF0C71DB-AC58-3DDB-FF94-C9B10FF8C200

Thanks

best,

Nick.

Best Answer
photo

To get multiple results each containing some average value, you need to use grouping. Only then you can sort grouped values. If you do not use grouping (that is the "groupBy" operator, you will be getting only one data point back. For more information, please see this doc page: https://backendless.com/docs/rest/doc.html#data_data_filtering

Leave a Comment

Comments (6)

photo
1

I need an array of counted properties for all my objects.

photo
1

Nick,

Information about objects included into the responses should be ignored when you use aggregate functions. When you get a count or average these values are calculated for a set of objects (such as the entire table or a group), as a result, individual properties for objects A1 or B1 are irrelevant and should be ignored. The documentation talk about it here: http://take.ms/blxnt

Regards,

Mark

photo
1

Mark, thanks for your answer, but is it possible to query array of objects and sort them by aggregate function ?

photo
photo
1

I am sorry, I do not understand the question. Could you please explain with an example?

photo
1

For example, I have Place table that contains 1..n Comments with rating field. I want to query Places by Avg function of rating field in Comments table of this Place. Basically I want to get all Places and sort them using Avg function.

photo
1

To get multiple results each containing some average value, you need to use grouping. Only then you can sort grouped values. If you do not use grouping (that is the "groupBy" operator, you will be getting only one data point back. For more information, please see this doc page: https://backendless.com/docs/rest/doc.html#data_data_filtering

photo