Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmos: Support aggregate operators #16146

Closed
smitpatel opened this issue Jun 19, 2019 · 9 comments
Closed

Cosmos: Support aggregate operators #16146

smitpatel opened this issue Jun 19, 2019 · 9 comments
Assignees
Labels
area-cosmos area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-6.0 punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. type-enhancement
Milestone

Comments

@smitpatel
Copy link
Contributor

Average/Sum/Min/Max/Count

 typeof(Microsoft.Azure.Cosmos.QueryPlanHandler+QueryPlanHandlerException): Query contains 1 or more unsupported features. Upgrade your SDK to a version that does support the requested features:
    Query contained CompositeAggregate, which the calling client does not support. (Query contained CompositeAggregate, which the calling client does not support.)
    ---- Microsoft.Azure.Cosmos.QueryPlanHandler+QueryPlanHandlerException : Query contains 1 or more unsupported features. Upgrade your SDK to a version that does support the requested features:
    Query contained CompositeAggregate, which the calling client does not support. (Query contained CompositeAggregate, which the calling client does not support.)
    -------- System.ArgumentException : Query contained CompositeAggregate, which the calling client does not support.
@smitpatel smitpatel mentioned this issue Jun 19, 2019
82 tasks
@divega divega modified the milestones: 3.0.0, Backlog Jun 20, 2019
@divega divega changed the title Cosmos: Aggregate operators Cosmos: Support aggregate operators Jun 20, 2019
@smitpatel
Copy link
Contributor Author

@JonPSmith
Copy link

I'm trying to use Cosmos DB and I need a count of all the entries to make paging work. Can you suggest a way around this problem that doesn't require me to ingest all the data?

@AndriySvyryd
Copy link
Member

@JonPSmith The best you can do for now is something like
query.Select(_ => 1).AsEnumerable().Count()

@JonPSmith
Copy link

I'm sure you know but here is performance figures of the current way of using Count in EF Core (NoSQL database on Azure Cosmos DB Emulator, total number of entries = 50600, each count run three time to reduce first access setup time.

if using noSqlDbContext.Books.Select(_ => 1).AsEnumerable().Count() via EF Core

  1. Not timed.
  2. NoSQL count, EF Core select took 1,152.58 ms.
  3. NoSQL count, EF Core select took 1,201.86 ms.

If using SELECT VALUE Count(c) FROM c via cosmosClient

  1. Not timed.
  2. NoSQL count, via client took 121.09 ms.
  3. NoSQL count, via client took 100.90 ms.

If I'm doing something wrong then please let me know.

@JonPSmith
Copy link

BTW Just noticed an interesting article on Cosmos DB with big improvements on COUNT, SUM, AVG, MAX, and MIN if you add a index.

@JonPSmith
Copy link

I recommend this gets into the EF Core 6 list. Not having count is especially difficult (and Cosmos Count is super fast)

@ghost
Copy link

ghost commented Jan 13, 2022

I would really welcome aggregate support being added. I am wondering what is being proposed here though:

  • a single aggregate return value e.g. the result of SELECT COUNT(c) FROM c
  • multiple aggregate return values e.g. the result of SELECT MIN(c.value), MAX(c.Value) FROM c
  • full group by support e.g. the result of SELECT c.make, c.model, MIN(c.value), MAX(c.Value) FROM c GROUP BY c.make, c.model

@smitpatel
Copy link
Contributor Author

This may be fully working.

@ajcvickers ajcvickers added verify-fixed This issue is likely fixed in new query pipeline. punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. and removed propose-punt labels Jul 6, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0, Backlog Jul 7, 2022
@smitpatel smitpatel removed their assignment Sep 14, 2022
@roji
Copy link
Member

roji commented Jun 15, 2024

This is now supported, as of #33895 - though we're likely missing qiute a bit of test coverage.

For example:

await context.Set<OwnedPerson>().Select(o => o.Orders.Max(o => o.Id)).ToListAsync()

... now gets translated to:

SELECT (
    SELECT VALUE MAX(t["Id"])
    FROM t IN c["Orders"]) AS c
FROM root c
WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA")

Aggregate operators work also on the top-level entity types. GroupBy isn't yet supported, that's tracked by #17313.

@roji roji closed this as completed Jun 15, 2024
@roji roji self-assigned this Jun 15, 2024
@roji roji added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed verify-fixed This issue is likely fixed in new query pipeline. labels Jun 15, 2024
@roji roji modified the milestones: Backlog, 9.0.0 Jun 15, 2024
@ajcvickers ajcvickers modified the milestones: 9.0.0, 9.0.0-preview6 Jun 21, 2024
@roji roji modified the milestones: 9.0.0-preview6, 9.0.0 Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-cosmos area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-6.0 punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. type-enhancement
Projects
None yet
Development

No branches or pull requests

6 participants