Skip to Content
2
Oct 02, 2019 at 11:51 PM

@sap/cds-odata-v2-adapter-proxy doesn't return aggregated measure as integer

499 Views

Hello CAP(M) Experts,

with the commit 21ad5225404a03020a5ba248b28a65bb2e1c4a75 I've added annotations for Analytics. Unfortunately the service returns the aggregated measure as a String when requested via the @sap/cds-odata-v2-adapter-proxy. For that I'm using the URL:

http://localhost:4004/v2/catalog/Books?$select=author_ID,stock&$orderby=stock&$inlinecount=allpages

I get back:

{
  "d": {
    "results": [
      {
        "author_ID": 107,
        "__metadata": {
          "uri": "http://localhost:4004/v2/catalog/Books(aggregation'{\"key\":{\"author_ID\":107},\"value\":[\"stock\"]}')",
          "type": "CatalogService.Books"
        },
        "stock": "11"
      },
      {
        "author_ID": 101,
        "__metadata": {
          "uri": "http://localhost:4004/v2/catalog/Books(aggregation'{\"key\":{\"author_ID\":101},\"value\":[\"stock\"]}')",
          "type": "CatalogService.Books"
        },
        "stock": "12"
      },
      {
        "author_ID": 170,
        "__metadata": {
          "uri": "http://localhost:4004/v2/catalog/Books(aggregation'{\"key\":{\"author_ID\":170},\"value\":[\"stock\"]}')",
          "type": "CatalogService.Books"
        },
        "stock": "22"
      },
      {
        "author_ID": 150,
        "__metadata": {
          "uri": "http://localhost:4004/v2/catalog/Books(aggregation'{\"key\":{\"author_ID\":150},\"value\":[\"stock\"]}')",
          "type": "CatalogService.Books"
        },
        "stock": "888"
      }
    ],
    "__count": 4
  }
}

As you can see the stock is returned as a string. In contrast to that when the aggregation is done with OData V4:

http://localhost:4004/catalog/Books?$apply=groupby((author_ID),aggregate(stock%20with%20sum%20as%20StockTotal))

I get:

{
  "@odata.context": "$metadata#Books(author_ID,StockTotal)",
  "@odata.metadataEtag": "W/\"q/OUzjzknmb3bMu6Fb8dAUuX53w4FSBIFhXoCuLQjeI=\"",
  "value": [
    {
      "@odata.id": null,
      "author_ID": 101,
      "StockTotal@odata.type": "#Decimal",
      "StockTotal": 12
    },
    {
      "@odata.id": null,
      "author_ID": 107,
      "StockTotal@odata.type": "#Decimal",
      "StockTotal": 11
    },
    {
      "@odata.id": null,
      "author_ID": 150,
      "StockTotal@odata.type": "#Decimal",
      "StockTotal": 888
    },
    {
      "@odata.id": null,
      "author_ID": 170,
      "StockTotal@odata.type": "#Decimal",
      "StockTotal": 22
    }
  ]
}

And the StockTotal is an Integer.

Looking forward for your help.

Best regards
Gregor