Webapi: Support build in Function in aggregation

Created on 15 Aug 2016  路  5Comments  路  Source: OData/WebApi

currently we can't parse:

$apply=groupby((day(DateTime),month(DateTime),year(DateTime)),aggregate(Id with countdistinct as Count))
P2 feature

Most helpful comment

Doing it in that way will violate specification. Spec says (http://docs.oasis-open.org/odata/odata-data-aggregation-ext/v4.0/cs02/odata-data-aggregation-ext-v4.0-cs02.html#_Toc435016583 ): In its simplest form the first parameter of groupby specifies the grouping properties, a comma-separated list of one or more single-valued property paths (paths ending in a single-valued primitive, complex, or navigation property) that is enclosed in parentheses.

Following syntax is correct way to answer that question (it's not implemented yet too):
$apply=compute(day(DateTime) as day, month(DateTime) as month, year(DateTime) as year)/groupby((day,month,year),aggregate(Id with countdistinct as Count)

All 5 comments

Doing it in that way will violate specification. Spec says (http://docs.oasis-open.org/odata/odata-data-aggregation-ext/v4.0/cs02/odata-data-aggregation-ext-v4.0-cs02.html#_Toc435016583 ): In its simplest form the first parameter of groupby specifies the grouping properties, a comma-separated list of one or more single-valued property paths (paths ending in a single-valued primitive, complex, or navigation property) that is enclosed in parentheses.

Following syntax is correct way to answer that question (it's not implemented yet too):
$apply=compute(day(DateTime) as day, month(DateTime) as month, year(DateTime) as year)/groupby((day,month,year),aggregate(Id with countdistinct as Count)

@kosinsky Any workaround for this in the meantime?

Unfortunately, I don't have good way, however, grouping way by unique field (so no real aggregation) and introducing in the aggregate section and then using one more groupby could help.
$apply=groupby((Id), aggregate(year(DateTime) with max as year, month(DateTime) with max as month), Id with max as Id)/groupby((year, month), ....).
I suspect performance on executing that query could be not very good depended on implementation of IQueryable

Thanks @kosinsky. I meant to reply back earlier and let you know I worked around this by creating a view in the database and added DateTimeYear, DateTimeMonth, ... columns when I need to be able to group by this metric.

Following syntax is correct way to answer that question (it's not implemented yet too):
$apply=compute(day(DateTime) as day, month(DateTime) as month, year(DateTime) as year)/groupby((day,month,year),aggregate(Id with countdistinct as Count)

Hi @kosinsky, is there any progress on it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

khodaie picture khodaie  路  4Comments

johnhzhu picture johnhzhu  路  4Comments

MDzyga picture MDzyga  路  5Comments

LianwMS picture LianwMS  路  5Comments

christiannagel picture christiannagel  路  4Comments