Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax for Aggregating a Filtered Dataset in OData v4 Spec using $apply

Tags:

odata

odata-v4

Suppose I am querying a dataset called Sales with the following schema:

id (int) price (decimal) active (bit)

Using the $apply query option and the aggregate transformation of the OData v4 spec, what would be the syntax for finding the average price for only active Sales?

$apply supports both aggregation and filter transformations, but I can't figure out how to combine them or if you're even allowed to do so.

Thanks!

like image 397
Ken Avatar asked Sep 11 '25 07:09

Ken


1 Answers

$apply=filter(Status eq 1)/aggregate(price with average as averagePrice)

maybe you can refer the existing test:

https://github.com/OData/WebApi/blob/master/OData/test/E2ETest/WebStack.QA.Test.OData/Aggregation/AggregationTests.cs

https://github.com/OData/WebApi/blob/master/OData/test/UnitTest/System.Web.OData.Test/OData/Query/ApplyQueryOptionTest.cs

like image 146
Fan Ouyang Avatar answered Sep 13 '25 00:09

Fan Ouyang