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: Implement SelectMany #34013

Merged
merged 1 commit into from
Jun 20, 2024
Merged

Cosmos: Implement SelectMany #34013

merged 1 commit into from
Jun 20, 2024

Conversation

roji
Copy link
Member

@roji roji commented Jun 17, 2024

NOTE: This PR is based on top of #33998, skip first two commits

Also introduces substantial infrastructure for general joins; actual Join operator support to be introduced shortly.

Closes #17312

@roji roji force-pushed the CosmosSelectMany branch 2 times, most recently from 112de70 to 8bb7df1 Compare June 18, 2024 13:35
@roji roji marked this pull request as ready for review June 19, 2024 14:47
@roji roji requested a review from a team June 19, 2024 14:48
@@ -123,6 +123,9 @@
<data name="CanConnectNotSupported" xml:space="preserve">
<value>The Cosmos database does not support 'CanConnect' or 'CanConnectAsync'.</value>
</data>
<data name="ComplexProjectionInSubqueryNotSupported" xml:space="preserve">
<value>Complex projections in subqueries are currently unsupported.</value>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A second sentence on what they can do about this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I'm not sure what can be done :(

I think we should try to fix this for 9.0 - that's #34004, and I think it actually shouldn't be too hard. But it does involve some shaper changes...

Let's discuss this (but I'll go ahead and merge for now).

{
_sqlBuilder.Append("VALUE ");

if (projection is not [var singleProjection])
{
throw new UnreachableException(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's discuss UnreachableExceptions in a design meeting. :-)

// .SelectMany(p => Property(p, "Ints").AsQueryable(), (p, c) => new TransparentIdentifier`2(Outer = p, Inner = c))
// .Select(ti => ti.Inner)

// TODO: In Cosmos, we currently always add a predicate for the discriminator, so the source is never a bare array.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can always use HasNoDiscriminator in tests.

Meta-point: too many of our tests have:

  • Discriminators by default
  • No partition key
  • No owned types

I think this means we're largely testing un-representative models.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, with HasNoDiscriminator() there's indeed no predicate. But unfortunately there's still the problem described just above, where nav expansion rewrites the simple SelectMany() to the complete form with a result selector, and an additional Select that projects the inner out. So doing the simplification here to remove the JOIN is pretty much unfeasible until we fix that...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meta-point: too many of our tests have [...]

Yeah, you're right. For the discriminators, we've been recently discussing changing our default mapping strategy, i.e. no longer mapping different entity types to the same container by default; if go decide to do that, presumably there won't be a discriminator by default in any case (i.e. Cosmos will be more similar to relational), so at least that point maybe goes away.

// the JOIN source.
// However, the JSON object being projected out of the subquery doesn't correspond to any entity type, and there's currently
// no way for us to represent a reference to that - ObjectReferenceExpression requires an IEntityType. Changing that
// requires shaper-side changes (see comment in ObjectReferenceExpression); if we can remove that requirement, we can
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Also introduces substantial infrastructure for general joins

Closes dotnet#17312
@roji roji enabled auto-merge (squash) June 20, 2024 19:07
@roji roji merged commit 7a5508b into dotnet:main Jun 20, 2024
7 checks passed
@roji roji deleted the CosmosSelectMany branch June 20, 2024 19:44
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.

Cosmos: Translate SelectMany
2 participants