Skip to content

Cosmos: Set operations over embedded collections #37918

@JoasE

Description

@JoasE

What problem are you trying to solve?

Performing a Union, Intersect, Except or Concat over owned or complex collections or projections thereof

https://learn.microsoft.com/en-us/cosmos-db/query/setunion
https://learn.microsoft.com/en-us/cosmos-db/query/setintersect
https://learn.microsoft.com/en-us/cosmos-db/query/array-concat

Describe the solution you'd like

EF could translate

ss.Set<RootEntity>().Select(e => 
     e.AssociateCollection.Where(r => r.Int == 8)
     .Concat(e.AssociateCollection.Where(r => r.String == "foo"))

To

SELECT VALUE ARRAY_CONCAT(
    ARRAY(SELECT VALUE r FROM r IN c.AssociateCollection WHERE r.Int == 8),
    ARRAY(SELECT VALUE r FROM r IN c.AssociateCollection WHERE r.String == "foo")
)
FROM c

I think this could be quite expensive RU wise since it's scanning 2 and allocating 3 arrays, but it is a possible way.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions