Skip to Content
1
Jan 15, 2020 at 11:31 AM

CAP: Aggregations

938 Views Last edit Jan 15, 2020 at 12:04 PM 3 rev

Hi,

I am trying to have an aggregated OData entity using CAP.

Business case: Every time the user accesses an app, it creates an entry in database entity 'demo.Actions'. Entity 'demo.Actions' has application and userId as elements. I am trying to find distinct user counts of an application.

First I tried the Annotations approach as below.

 @Aggregation.ApplySupported.PropertyRestrictions: true
 entity Actions as select from demo.Actions {
   key application,
   userID,
   @Analytics.Measure: true
   @Aggregation.default: #COUNT_DISTINCT
   @Aggregation.referenceElement: ['userID']
   1 as usercount: Integer
 };

The aggregation did not happen. 'usercount' always gave 1 as the value.

Next, I tried the SQL way.

    entity  Actions1 as select from  demo.Actions{
        key application,
        userID,
        count (distinct userID) as usercount
    } group by application

Now I get an error saying DISTINCT in functions is not supported yetCDS(<unspecified>)

CAP documentation is of no help other than a reference here. https://cap.cloud.sap/docs/guides/generic-providers#aggregation

Is there a way to achieve the aggregation I need?