Skip to content

Cosmos: translate Contains over subquery#33905

Merged
roji merged 1 commit intodotnet:mainfrom
roji:InWithSubquery
Jun 5, 2024
Merged

Cosmos: translate Contains over subquery#33905
roji merged 1 commit intodotnet:mainfrom
roji:InWithSubquery

Conversation

@roji
Copy link
Copy Markdown
Member

@roji roji commented Jun 4, 2024

NOTE: This PR is based on top of #33895, review 2nd commit only

This PR adds support for translating Contains over subquery in Cosmos:

public virtual Task Column_collection_Contains_over_subquery(bool async)
    => AssertQuery(
        async,
        ss => ss.Set<PrimitiveCollectionsEntity>().Where(c => c.Ints.Where(i => i > 1).Contains(11)));

The translation:

SELECT c
FROM root c
WHERE ((c["Discriminator"] = "PrimitiveCollectionsEntity") AND EXISTS (
    SELECT 1
    FROM i IN c["Ints"]
    WHERE ((i > 1) AND (i = 11))))

Note that the Cosmos SDK provider translates differently:

SELECT VALUE root FROM root JOIN (SELECT VALUE ARRAY(SELECT VALUE i0 FROM root JOIN i0 IN root[\"Ints\"] WHERE (i0 > 3))) AS v0 WHERE ARRAY_CONTAINS(v0, 3)

We can treat our translation as temporary (and merge it), I'll clear it with the Cosmos team later for perf etc.

@roji roji requested a review from a team June 4, 2024 20:29
@roji roji force-pushed the InWithSubquery branch from 790e463 to 062d1ea Compare June 4, 2024 20:58
@roji roji force-pushed the InWithSubquery branch from 062d1ea to 7b01336 Compare June 5, 2024 13:58
@roji roji enabled auto-merge (squash) June 5, 2024 13:59
@roji roji merged commit 27ce95b into dotnet:main Jun 5, 2024
@roji roji deleted the InWithSubquery branch June 5, 2024 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants