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: Allow subqueries with anonymous type projections #34004

Open
roji opened this issue Jun 16, 2024 · 0 comments
Open

Cosmos: Allow subqueries with anonymous type projections #34004

roji opened this issue Jun 16, 2024 · 0 comments

Comments

@roji
Copy link
Member

roji commented Jun 16, 2024

In various Join/SelectMany scenarios, a JOIN subquery may need to project out a JSON object:

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Column_collection_SelectMany_with_projection_to_anonymous_type(bool async)
    => AssertQuery(
        async,
        ss => ss.Set<PrimitiveCollectionsEntity>().SelectMany(c => c.Ints.Select(i => new { Original = i, Incremented = i + 1 })));

Desired NoSQL translation:

SELECT a["Original"], a["Incremented"]
FROM root c
JOIN (
    SELECT VALUE
    {
        "Original" : i,
        "Incremented" : (i + 1)
    }
    FROM i IN c["Ints"]) a
WHERE (c["Discriminator"] = "PrimitiveCollectionsEntity")

Hoewver, the a in the SELECT clause above is a reference to a projected ad-hoc JSON object (with Original/Incremented) which doesn't correspond to a type in the model; we currently have no way to represent that, since ObjectReferenceExpression requires an IEntityType. Changing that requires shaper-side changes (see comment in ObjectReferenceExpression); if we can remove that requirement, we can possibly also merge ScalarReferenceExpression and ObjectReferenceExpression to a single SourceReferenceExpression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants