0

I am trying to query using groupby in cosmosdb with the following query,

var result = client.CreateDocumentQuery<Login>(documentUri)
                  .Where(i => i.logevent == "Success" && i._ts > 1517405472 && i._ts <= 1518010272)
                  .GroupBy(t => t._ts);

it throws the following error

DocumentQueryException: Query expression is invalid, expression https://documents.azure.com/dbs/colls/test.Where(i => (((i.logevent == "Success") AndAlso (i._ts > 1517405472)) AndAlso (i._ts <= 1518010272))).GroupBy(t => t._ts) is unsupported. Supported expressions are 'Queryable.Where', 'Queryable.Select' & 'Queryable.SelectMany

  • You could try to follow [documentdb-lumenize](https://github.com/lmaccherone/documentdb-lumenize) wrote by Larry Maccherone to provide Aggregations (Group-by, Pivot-table, and N-dimensional Cube) and Time Series Transformations as Stored Procedures in DocumentDB. – Bruce Chen Feb 09 '18 at 07:00

1 Answers1

3

GroupBy is not currently supported by the Cosmos DB LINQ provider. You have to materialize the results of the where clause using AsEnumerable, then perform Group By using LINQ on objects.

var result = client.CreateDocumentQuery<Login>(documentUri)
         .Where(i => i.logevent == "Success" && i._ts > 1517405472 && i._ts <= 1518010272)
         .AsEnumerable()
         .GroupBy(t => t._ts);

Note: you should push down as much of the query predicates to the server as possible. In other words, the Where clause should be in front of the AsEnumerable.

Aravind Krishna R.
  • 7,885
  • 27
  • 37